`graphql.operation` cannot intercept the unnamed graphql
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.35.0 |
browser | Chrome v93.0.4577.82 |
OS | MacOS v11.5.2 |
Request handlers
import { setupWorker, rest } from 'msw'
const worker = setupWorker(
graphql.operation((res, req, ctx) => {
// ...
})
)
worker.start()
Actual request
import { request, gql } from "graphql-request";
const query = gql`
{
hero {
name
friends {
name
}
}
}
`;
request("/", query)
Current behavior
The handler didn’t work, and there is a warning in the console:
[MSW] Failed to intercept a GraphQL request at "POST /": unnamed GraphQL operations are not supported.
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation
Note that using rest.post
is workable:
rest.post(/\//, (res, req, ctx) => {
// ...
})
Expected behavior
The handlers should works.
Screenshots
Here is a reproducible codesandbox.
Finally, thanks for the fantastic library 🙌. MSW helps my daily work a lot! Please let me know if there is anything I can help with this issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Full Stack Error Handling with GraphQL and Apollo
This effectively intercepts the old // failed request, and retries it with a new token return forward(operation); // handle other errors ...
Read more >msw: graphql operation doesn't get intercepted - Stack Overflow
Using MWS, I'm trying to mock the graphql operation testRequest as follows: Funny thing is, the console.log in the ...
Read more >Introspection - GraphQL
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >GraphQL Step Last Updated December 15, 2022 - TechDocs
schema-based error checking. If you select the content type as application/graphql, you cannot use the GraphQL variables and the operation Name. GraphQL ......
Read more >Multiple GraphQL Operations in a Request - Dgraph
GraphQL requests can contain one or more operations. Operations include query, mutation, or subscription.
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
Hey, @andykao1213. Thank you for reporting this!
We are aware of this issue and collaborating with @neilime who has already implemented a fix! Please await the next release.
For others who find this, i had this issue aswell. It did a mutation like this:
but it should have been:
Regards