question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve GraphQL mocking

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
kettanaitocommented, Sep 10, 2020

We’ve shipped support for graphql.operation request handler in msw@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.

1reaction
brapifracommented, Aug 14, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking schema capabilities - Apollo GraphQL Docs
Mocking schema capabilities. Start on client-side features before your server supports them. If your GraphQL server doesn't yet support a field that your ......
Read more >
Mocking – GraphQL Tools
Mock your GraphQL data based on a schema. ... The strongly-typed nature of a GraphQL API lends itself extremely well to mocking.
Read more >
How to Mock a GraphQL API - Bits and Pieces
Create a mock API for GraphQL with GraphQL Codegen and GraphQL Faker. ... The frontend team can start to develop together with the...
Read more >
Mocking your server is easy with GraphQL
Do you think mocking your backend is always a tedious task? ... so that you can develop and test other parts of your...
Read more >
How to Mock a GraphQL Request - tweak browser extension
This article will guide you on mocking a GraphQL request directly in the browser with our extension.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found