Network-level mocking for GraphQL APIs using service workers. Version 1.0.2 (stable, infrequent releases) wraps MSW to intercept GraphQL requests at the network level, avoiding monkey-patching fetch/XHR. Supports auto-mocking from a GraphQL schema and per-test manual mocks. Differentiated by realistic network tab visibility and seamless browser integration via service worker.
npm install graphql-mock-networkNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes MockNetwork with schema and custom mocks, starts network interception, and makes a mocked GraphQL request using fetch.
Copy mockServiceWorker.js to your public directory (e.g., public/mockServiceWorker.js) and serve at /mockServiceWorker.js.
Use separate mocking for subscriptions (e.g., graphql-tools with Apollo).
Provide schema as generated by introspection query (e.g., from graphql-codegen).
Ensure mocks are nested by type then field, not flat.
No direct fix – library is unmaintained. Fork and update MSW dependency manually.
Add 'globalThis' polyfill or set a global mock for 'global' in your bundler (e.g., webpack: { node: { global: true } }).Serve mockServiceWorker.js from your server's root (e.g., public/mockServiceWorker.js for Create React App).
Parse introspection JSON: `const schema = buildClientSchema(introspectionResult.data);`
Run `npm install msw` to add msw as a dependency.