Replies: 1 comment 3 replies
-
Hey, @bud-mo. If I understand your requirements correctly, you wish to intercept and mock a GraphQL query that happens in Knowing that, we can make the conclusion that to intercept a GraphQL operation (any request, really), we must initiate MSW in the same process where that request happens. I'd expect that following the Node.js integration guidelines and applying them to the // gatsby-node.js
const { graphql } = require('msw')
const { setupServer } = require('msw/node')
const server = setupServer(
graphql.query('MyQueryName', (req, res, ctx) => {
return res(ctx.data({ payload: { mocked: true }}))
})
)
server.listen() A couple of things to pay attention to:
If you set this up but your request is still not intercepted, we have a neat guide you can follow to debug that. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Hi all!
I am trying to use Mock Service Worker to mock some gql queries as I don't want to make requests while developing nor while running some tests.
With POST/GET API calls it works great, so into my
gatsby-node
I can mock anything I want butgraphql.query()
cannot intercept anything.I am using the
gatsby-source-contentful
plugin to get data from Contentful.Any idea?
How to reproduce: Initialize MSW as described into the getting started and perform a query into
gatsby-node
.Beta Was this translation helpful? Give feedback.
All reactions