Improve GraphQL mocking
See original GitHub issueIs your feature request related to a problem? Please describe. Right now you need to mock the whole GraphQL response like this https://github.com/mswjs/msw/blob/e31a344332f5951177bb17655a82c7cefe59445e/test/graphql-api/query.mocks.ts
Describe the solution you’d like The idea is to only mock the types and fields that you need in your test
Describe alternatives you’ve considered
I’ve been using relay-testing-utils
to mock only parts of my GraphQL response https://relay.dev/docs/en/testing-relay-components
We can also use graphql-tools mocking approach (https://www.apollographql.com/docs/graphql-tools/mocking/)
Additional context This is based on a twitter discussion (https://twitter.com/sseraphini/status/1264877251587432448) about graphql-mock-api
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:25 (15 by maintainers)
Top GitHub Comments
We’ve shipped support for
graphql.operation
request handler inmsw@0.21.0
. Updating to that version should allow you to use that request handler to resolve any GraphQL operation any way you wish (i.e. using an external server).I’ll close this issue, concluding its scope being
graphql.operation
support. That is to prevent it from being forever open without a clear milestone. We still have a way to go with enhancing GraphQL support with adding subscriptions and providing other improvements to the experience. Please don’t hesitate to reach out and share your feedback on the GraphQL usage of MSW. You’re awesome.Agreed. I think the
graphql.operation
could pretty much cover all cases mentioned here. I see that @garhbod is planning to contribute with a PR, great! I’m happy to help if needed!