Skip to content

Handle both REST and GraphQL requests together #654

Answered by kettanaito
f0und3r asked this question in Q&A
Discussion options

You must be logged in to vote

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)

Read more about graphql.link.

I tried, but have got 404 on /graphql requests

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@f0und3r
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #653 on March 18, 2021 10:31.