Cypress plugin that adds custom commands (cy.mockNetwork, cy.mockNetworkAdd, cy.mockNetworkReset) for mocking GraphQL API responses during Cypress end-to-end tests. Current stable version 1.0.2. Wraps GraphQL Mock Network to intercept network requests and return auto-generated or custom mocks. Requires Node >=12. Differentiates by providing a simple Cypress-native API for GraphQL mocking without external fixtures, leveraging a service worker for interception. Ships TypeScript types.
npm install cypress-graphql-mock-networkNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows setup: import plugin, read schema file, mock network in beforeEach, add custom query mock, visit page, assert content.
Copy ./mockServiceWorker.js from node_modules/cypress-graphql-mock-network/mockServiceWorker.js to server root.
Ensure cy.mockNetwork({ schema }) is called in beforeEach before cy.visit().Export your GraphQL schema as SDL (e.g., using 'graphql-code-generator' or 'apollo') and use .graphql file.
Wrap each resolver in a function: Query: () => ({ todos: () => [...] })Ensure the schema file path is correct relative to cypress.json. Use cy.readFile('./introspection.schema.graphql') or full path.Add 'import 'cypress-graphql-mock-network'' to cypress/support/index.ts (or .js).
Call cy.mockNetwork({ schema: yourSchema }) with a valid schema string.Copy mockServiceWorker.js from node_modules to the public/static folder that serves your app's root.