Some GraphQL queries don't get intercepted
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.28.2 |
browser | Chrome |
OS | MacOS 11.3 |
Request handlers
// Example of declaration. Provide your code here.
import { setupWorker, rest } from 'msw'
const handlers: RequestHandler[] = [
rest.post("*", (req) => console.log((req as any).href.url)),
graphql.query("getSandwiches", (req, res, ctx) => {
res(ctx.data({
locations: MOCK_LOCATIONS
}));
})
];
const worker = setupWorker(...handlers)
worker.start();
Actual request
Using Apollo-client to fetch GraphQL queries.
function useGetSandwichesQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<GetSandwichesQuery, GetSandwichesQueryVariables>) {
return ApolloReactHooks.useQuery<GetSandwichesQuery, GetSandwichesQueryVariables>(GetSandwichesDocument, baseOptions);
}
const { data, loading, error } = useGetSandwichesQuery({ variables: { locationId } });
Current behavior
The getSandwiches
query is not being intercepted at all. I’ve followed the advice from debugging-uncaught-requests.
onUncaughtHandledRequest
doesn’t seem to throw an error on this request, even when I remove the handler from the handlers array. It looks like it doesn’t get intercepted at all. Even the "*"
rest handler doesn’t seem to log that particular query. I have 3 GraphQL queries, 1 gets intercepted correctly and throws an error that it isn’t handled. 2 others don’t seem to get intercepted at all. The unmocked version does work perfectly fine however.
printHandlers
prints the handler correctly.
<ROOT_URL>/mockServiceWorker.js
is available, so I guess the service worker is in the correct scope.
Expected behavior
Expected all 3 GraphQL calls to be intercepted, getSandwiches
should be mocked, while the other 2 should throw an error because of the onUncaughtHandledRequest
option.
Is there anything else I can do to debug this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@kettanaito thank you for the quick reply. Removing the rest handler unfortunately has the same results. I’ve added it as a way to debug this.
I can’t share the repo I’m working on right now, but I’ll see if I can create a minimal reproduction in a couple days. Life is quite busy at the moment so bear with me on this one 😅
I’m closing this as we haven’t received any reproduction repository or evidence that there’s indeed an issue with the library. We can still discuss this and will try to help you debug the problem. Otherwise, we’re treating inactivity as a sign that the issue has been resolved.