benawad / apollo-mocked-provider

Automatically mock GraphQL data with a mocked ApolloProvider
MIT License
92 stars 25 forks source link

Custom resolver with no data #36

Closed draxx318 closed 3 years ago

draxx318 commented 3 years ago

Is possible to pass a custom resolver with no data to the ApolloMockedProvider to simulate a scenario where the query returns an empty array?

sarfata commented 3 years ago

Yes. Just return an empty array.

For example, I have this in my project:

stories.add("Boat selector with no boat", () => (
  <ApolloMockedProvider
    customResolvers={{
      Query: () => ({
        me: () => ({
          boats: [],
        }),
      }),
    }}
  >
    <ControlledBoatSelectorInput />
  </ApolloMockedProvider>
))

If this does not work for you, please send more details.

draxx318 commented 3 years ago

Thanks, works like a charm. I was trying to do it the same way but probably had something wrong with the implementation.