graphql
API reference for the `graphql` namespace.
Intercept and mock GraphQL operations.
Mock Service Worker comes with first-class support for mocking GraphQL APIs. You can develop, test, showcase, and debug your GraphQL applications using the graphql namespace exported by msw/graphql.
import { graphql } from 'msw/graphql'graphql
API reference for the `graphql` namespace.
MSW supports intercepting any GraphQL operations that comply with the GraphQL Specification. This includes queries, mutations, and subscriptions regardless of the GraphQL client that performed them. The library has you covered if you're exploring GraphQL via graphql-request or plain fetch() as well as if you're using a production-ready client like Apollo, Relay, or URQL.
Here are some of the benefits when using MSW for mocking GraphQL:
<MockProvider>s! Embrace a cleaner test setup to focus on what matters most: testing your app.graphql package to parse operations).The following sections will guide you through everything you need to know about intercepting and mocking GraphQL APIs: