In my React storybooks, I want to be able to toy around with components that use graphQL queries and mutations (implemented with Apollo).
This works fine using MockedProvider, as long as I specify in-advance the exact mutations, including their inputs.
I want to know if it is possible/how to not specify the inputs in advance, to accept any inputs.
export const MyComponent = () => (
<Mutation mutation={gql`some mutation`}>
{(doMutation, { loading, error, data }) => (
<Button onClick={()=> doMutation({input: {
someInput: Math.rand()*10 // Would be fine if this was 1.
}}) />
{data ? <>Result: {data.someResult}</> : null}
)
</Mutation>
)
storiesOf('MyComponent', module)
.add('some story', () => (
<StaticRouter context={{}}>
<MockedProvider
mocks={[
{
request: {
query: gql`some query...`,
variables: { input: { someInput: '1' } },
},
result: { data: { someResult: '1' } },
},
]}
addTypename={true}
>
<MyComponent />
</MockedProvider>
</StaticRouter>
))
In the pseudo-example above, the storybook will work fine if I send '1' as my input, but will not work for any other number - the mock must match exactly or I get "no more mocked responses for someMutation with variables {...}".
This is not a problem in tests, but in storybooks it'd be nice to be able to test with any values.