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.

Support custom fields on a mocked GraphQL response

See original GitHub issue

Scope

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Jun 7, 2022

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.

1reaction
Poiveycommented, May 12, 2022

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 !

Read more comments on GitHub >

github_iconTop 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 >

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