Request to graphql server not intercepted
See original GitHub issueDescribe the bug
Request to graphql server not intercepted
Environment
msw: 0.16.0
nodejs: 12.16.3
npm: 6.14.5
To Reproduce
// src/App.js
import ApolloClient, { gql } from 'apollo-boost';
import { ApolloProvider } from '@apollo/react-hooks';
const client = new ApolloClient({
uri: 'https://<SOME_DOMAIN>/graphql'
})
const TEST_MSW = gql`
query TestMSW {
user(id: 123) {
firstname
lastname
}
}
`;
client.query({
query: TEST_MSW
}).then(res => console.log(res)).catch(err => console.log(err));
// src/mocks.js
import { setupWorker, graphql } from 'msw';
const worker = setupWorker(
graphql.query("TestMSW", (req, res, ctx) => {
return res(
ctx.data({
user: {
firstname: 'John',
lastname: 'Doe'
}
})
)
})
)
// Calling the "start" function registers the Service Worker
worker.start();
// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
// include mocks by msw
require('./mocks.js');
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
Expected behavior
The docs mentioned that all outgoing requests will be intercepted
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
MSW do not intercept GraphQL requests at all #63 - GitHub
The call is not intercepted. I've already tried: Import jest-fetch-mock in the configuration file;; Start the server in setupFiles.js (as ...
Read more >Full Stack Error Handling with GraphQL and Apollo
If networkError is present in your response, it means your entire query was rejected, and therefore no data was returned. For example, the ......
Read more >msw: graphql operation doesn't get intercepted - Stack Overflow
It seems you just add Runtime request handler using server.use() method. But there is no graphql client call it.
Read more >Spring for GraphQL Documentation
Interception. Server transports allow intercepting requests before and after the GraphQL Java engine is called to process a request. 3.4.1.
Read more >Intercepting GraphQL Requests With Cypress
If your app uses GraphQL, every network request will match these first two arguments, since every GraphQL request will be a POST request...
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
I’ve tried the deferred started approach but that first query is still not intercepted. I used the same bootstrap code as in the documentation and use the App.js as above
In case you are performing requests on load (or on component’s mount), you can defer the start of your application until the mocking is ready (see Deferred start).
I’m considering to make this approach the recommended one when getting started with the library. Thanks for bumping that in my priorities list!