A library to mock GraphQL queries when testing clients making calls to GraphQL APIs. Ideal for use with Jest and Relay Modern/Apollo, but not bound to any specific client library. Focus is on realistic testing using nock to intercept HTTP requests. Current stable version: 0.12.1. Release cadence is irregular. Key differentiators: variable matching to verify correctness, control over query resolution timing for loading states, ability to simulate HTTP error statuses, and support for sequences of responses for pagination scenarios.
npm install graphql-query-test-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates setup, teardown, and basic query mocking with Jest. Includes mocking a query and resolving all pending queries.
Add 'global.fetch = require('node-fetch');' in your Jest setup file.Ensure the URL in setup() matches the one in your client code exactly.
Use 'import { QueryMock } from 'graphql-query-test-mock'; instead of the old path.Use import { QueryMock } from 'graphql-query-test-mock';Verify that the URL passed to setup() matches exactly the GraphQL endpoint your client uses.
Add global.fetch = require('node-fetch'); in your Jest setup file.