Handle both REST and GraphQL requests together #654
-
Hello! Can MSW handling rest and graphql requests together? I tried, but have got 404 on /graphql requests, if i comment rest handlers - all ok. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, @f0und3r. MSW supports simultaneous handling of both REST and GraphQL API. You'd most likely want to scope the GraphQL handlers to a specific endpoint to prevent resource address collisions with REST API: import { graphql } from 'msw'
// Create a scoped handler.
const myGraphQLApi = graphql.link('http://your.server/graphql')
// Handle request in setupWorker/setupServer.
myGraphQLApi.query('QueryName', resolver)
I suggest trying that again and following uncaught requests debugging guidelines if you get 404. If that page doesn't help, please attach your setup here so other contributors could help. |
Beta Was this translation helpful? Give feedback.
Hi, @f0und3r.
MSW supports simultaneous handling of both REST and GraphQL API. You'd most likely want to scope the GraphQL handlers to a specific endpoint to prevent resource address collisions with REST API:
Read more about
graphql.link
.I suggest trying that again and following uncaught requests debugging guidelines if you get 404. If that page doesn't help, please attach your setup here so other contributors could help.