Support custom fields on a mocked GraphQL response
See original GitHub issueScope
Improves an existing behavior
Compatibility
- This is a breaking change
Feature description
I’m using msw for mocking grapghql api calls in react testing library tests of my application. I have a requirement to pass following object as the response context, to simulate an error response behavior
{
"networkError": {
"statusCode": "404"
},
"message": "Not Found",
"metadata": {
"errorCode": "Repository Not Accessible",
"additionalData": "http://github.com/testUser/repo-to-be-deleted"
}
}
However when setting the response context it only allows me to set data
, headers
, delay
, extensions
and some other predefined fields for the context.
I need to be able to set custom values, for an example as per the above object I need to set metadata
and message
fields
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Mocking - Apollo GraphQL Docs
Mocking enables Apollo Server to return simulated data for GraphQL operations based on your server's schema. The strongly-typed nature of a GraphQL API...
Read more >Mocking your server is easy with GraphQL
Customizing mock data# · import · import · // The GraphQL schema. Described in more detail here: · // https://medium.com/apollo-stack/the-apollo- ...
Read more >A new approach to mocking GraphQL data - freeCodeCamp
In service of that outcome, we've come up with some new patterns that allow us to mock data with an extremely small amount...
Read more >Typing and mocking a GraphQL API server with Apollo
Pass an object to the mocks option to enable custom mock resolvers. As the name suggests, they are identically shaped to the actual...
Read more >Mocking and Testing GraphQL in React - Telerik
Mocks allow you to provide fake responses to your queries, ... a large amount of mocked data, and then if you wanted to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released: v0.42.1 🎉
This has been released in v0.42.1!
Make sure to always update to the latest version (
npm i msw@latest
) to get the newest features and bug fixes.Predictable release automation by @ossjs/release.
Ok I will start working on it, I will create a pull request as soon as I have the first implementation to get your feedback !