LOGOMock Service Worker

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): GraphQLRequestHandlers
3}

Examples

1import { setupWorker, graphql } from 'msw'
2
3const github = graphql.link('https://api.github.com/v4')
4const stripe = graphql.link('https://api.stripe.com/graphql')
5
6const worker = setupWorker(
7 github.query('GetUser', resolveGitHubUser),
8 stripe.mutation('Payment', resolveStripePayment),
9
10 // Although this operation name is `GetUser`,
11 // it will get captured only when the request is issued
12 // against the current location (no link specified).
13 graphql.query('GetUser', (req, res, ctx) => {
14 return res()
15 }),
16)
17
18worker.start()