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 for GraphQL requests with partial results

See original GitHub issue

Thanks for this great library! It’s a pleasure to use. While integrating it I ran into an issue which might be caused by lack of understanding on my side.

Is your feature request related to a problem? Please describe.

When using GraphQL requests which for instance load different parts of data such as

query MyQuery {
   myOrders {
      total
   }
   myProfile {
      name
   }
}

then this query can partially fail. In the example above the myOrders could be resolved while the myProfile can fail and be null. The resulting response could be something like

{
   data: {
     myOrders: {
        total: 42
     },
     myProfile: null
   },
   errors: [{
      path: 'MyQuery.myProfile',
      extensions: { code: 'foo' }
   }]
}

I don’t see a way to support this case via msw and the graphql mocking system. The errors context to how I read it’s code terminates the request. While the data context seems to be a shorthand for json.data(). As a result I can’t use both as in ctx.data and ctx.errors. While ctx.json is not exposed when using graphql. Mocking the request via rest feels cumbersome as matching the query is hard.

Describe the solution you’d like

Either the errors on ctx does not terminate the request and allows for combination with data or json is exposed on the context when using graphql.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Oct 28, 2020

This has been implemented in https://github.com/mswjs/msw/pull/403. Will be released in the next minor version of msw.

Thank you, @tdeekens, for a superb work on this! 🎉

2reactions
emmenkocommented, Sep 26, 2020

I’m not sure exposing the json method is what we want here.

I like the fact that graphql/rest handlers expose only a set of methods that make sense to their respective APIs. GraphQL has a very well-defined and strict spec for the response format (data and error) and allowing people to just pass any arbitrary JSON feels out of place.

As a user, as I suggested before, I would imagine to have a dedicated method for covering the use case of partial results. This has some advantages:

  • like for data() and errors(), it’s very clear what the intent is
  • it’s easier to type, as using such dedicated method requires you to define both data and errors objects
  • it fits with the GraphQL format, as partial results is something specified in the spec

Just my 2 cents…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also...
Read more >
Handle partial responses when the server returns an error #51
The GraphQL spec is pretty explicit about supporting partial responses and the errors field containing detailed information. As the most popular GraphQL ......
Read more >
GraphQL Best Practices
By defaulting every field to nullable, any of these reasons may result in just that field returned "null" rather than having a complete...
Read more >
GraphQL mutations: Partial updates implementation - Medium
In GraphQL, you have to create mutations to modify server-side data, and different implementations are possible to support partial updates.
Read more >
Execution - GraphQL Java
To execute a query against a schema, build a new GraphQL object with the appropriate arguments and then call execute() . The result...
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