Nock-based GraphQL testing library (v2.1.0) that mocks GraphQL queries and mutations by intercepting actual HTTP calls via nock. Unlike Apollo's MockedProvider, it tests with real fetch requests, providing more realistic integration tests. Ships TypeScript types. Requires nock, cross-fetch, and graphql as peer dependencies. Suitable for Apollo Client and other GraphQL clients that use HTTP.
npm install nock-graphqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to instantiate NockGraphQL, mock a GraphQL query, execute it with Apollo Client, and verify the mock was called.
Upgrade Node.js to 18+ and npm to 9+.
Add global.fetch = require('cross-fetch') in test setup file.Use afterEach to call cleanup().
Set addTypename: false in InMemoryCache or include __typename fields.
global.fetch = require('cross-fetch')Ensure variables match exactly (including order and types) and document string is identical.