link()
A high-order request handler that scopes a GraphQL API under the given endpoint.
graphql.link()
is primarily designed for applications that communicate with multiple GraphQL endpoints to prevent operation name collision during API mocking.
Call signature
1interface graphql {2 link(uri: string): GraphQLRequestHandlers3}
Examples
1import { setupWorker, graphql } from 'msw'23const github = graphql.link('https://api.github.com/v4')4const stripe = graphql.link('https://api.stripe.com/graphql')56const worker = setupWorker(7 github.query('GetUser', resolveGitHubUser),8 stripe.mutation('Payment', resolveStripePayment),910 // Although this operation name is `GetUser`,11 // it will get captured only when the request is issued12 // against the current location (no link specified).13 graphql.query('GetUser', (req, res, ctx) => {14 return res()15 }),16)1718worker.start()