Replies: 1 comment 11 replies
-
Hey, @BernardA. The beauty of MSW is that it's agnostic of your request-issuing setup. All you have to do is to declare a query name that you wish to intercept and describe how to mock its response. import { graphql } from 'msw'
const handlers = [
graphql.query('getBrandsModels', (req, res, ctx) => {
return res(
ctx.data({
brands: [
{
id: 1,
brand: 'Lego',
models: [
{
id: 2,
model: 'Porsche',
},
],
},
],
})
)
}),
] If you wish, you can scope the queries intercepted to a specific endpoint by using graphql.link: import { graphql } from 'msw'
const myService = graphql.link(process.env.NEXT_PUBLIC_API_GRAPHQL_URL)
const handlers = [
myService.query('getBrandsModels', (req, res, ctx) => {
// The mocked response as described above.
}),
] You then use the handlers above for both browser and Node.js integrations. Let me know if you have any more questions or find this setup not working for you. |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is more of a question that an issue per se.
I have a Next js app that uses graphql to communicate with the API - both my own API and Wordpress'.
In both cases no graphql client like Apollo is used.
Instead I use
axios
to make the query or mutations, like in the instance below:At
/pages/brands
:Where
apiQl
is like:This serves my purposes quite well.
I have all the app state managed with
redux
and certainly see no reason to add a tool likeApollo client
.I have not been able to make
msw
work with my API setup and was wondering if it is possible at all without installing the grapqhql clients you prescribe which, as said, I have no reason to use otherwise.If it is possible with my API setup, please indicated how.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions