JohnAlbin / storybook-addon-fetch-mock

Adds fetch-mock to Storybook
Other
8 stars 5 forks source link

Can this be used to mock GraphQL api? #11

Open june-cs opened 1 year ago

june-cs commented 1 year ago

GraphQL only provides one endpoint unlike the REST type of API. Can you provide an example of how to mock several GraphQL requests for one component?

In other words, I have a React component that makes several requests to one Graphql endpoint, and the component receives a different set of data from each request.

JohnAlbin commented 11 months ago

I've done GraphQL mocking. And I've done fetch() mocking in Storybook. But I haven't done GraphQL mocking in Storybook… yet.

Here's docs on mocking in GraphQL. https://graphql.org/blog/mocking-with-graphql/

You might be able to use those mock functions with fetch-mock, but I haven't tried it.