{"id":47364,"library":"cypress-graphql-mock-network","title":"Cypress GraphQL Mock Network","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/warrenday/cypress-graphql-mock-network","tags":["javascript","typescript"],"install":[{"cmd":"npm install cypress-graphql-mock-network","lang":"bash","label":"npm"},{"cmd":"yarn add cypress-graphql-mock-network","lang":"bash","label":"yarn"},{"cmd":"pnpm add cypress-graphql-mock-network","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core mocking library that handles schema-based mock generation and network interception","package":"graphql-mock-network","optional":false}],"imports":[{"note":"This is a side-effect module that registers Cypress commands. Import in support file, no named exports.","wrong":"import { cypress-graphql-mock-network } from 'cypress-graphql-mock-network'","symbol":"none (side-effect import)","correct":"import 'cypress-graphql-mock-network'"},{"note":"Accepts an object with schema property. Schema can be a string or an SDL object. Should be called in beforeEach.","wrong":"cy.mockNetwork(schema)","symbol":"cy.mockNetwork","correct":"cy.mockNetwork({ schema })"},{"note":"Argument should be a resolver map object, not nested resolvers. Use functions returning data.","wrong":"cy.mockNetworkAdd({ Query: { ... } })","symbol":"cy.mockNetworkAdd","correct":"cy.mockNetworkAdd({ Query: () => ({ ... }) })"}],"quickstart":{"code":"// cypress/support/index.ts\nimport 'cypress-graphql-mock-network';\n\n// cypress/integration/example.spec.ts\nbeforeEach(() => {\n  cy.readFile('./introspection.schema.graphql').then(schema => {\n    cy.mockNetwork({ schema });\n  });\n});\n\nit('displays custom mocked data', () => {\n  cy.mockNetworkAdd({\n    Query: () => ({\n      todos: () => ({\n        data: [{ id: '1', title: 'Go shopping', completed: true }]\n      })\n    })\n  });\n  cy.visit('http://localhost:3000');\n  cy.contains('Go shopping').should('exist');\n});","lang":"typescript","description":"Shows setup: import plugin, read schema file, mock network in beforeEach, add custom query mock, visit page, assert content."},"warnings":[{"fix":"Copy ./mockServiceWorker.js from node_modules/cypress-graphql-mock-network/mockServiceWorker.js to server root.","message":"Service worker (mockServiceWorker.js) must be served from root of website (e.g., /mockServiceWorker.js). If served from subdirectory, mocking will not work.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure cy.mockNetwork({ schema }) is called in beforeEach before cy.visit().","message":"cy.mockNetwork() must be called before cy.visit() in each test. If visited first, network requests will not be intercepted.","severity":"gotcha","affected_versions":"*"},{"fix":"Export your GraphQL schema as SDL (e.g., using 'graphql-code-generator' or 'apollo') and use .graphql file.","message":"Using an outdated introspection schema format may cause mocking failures. Schema should be in .graphql or .gql format with SDL.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Wrap each resolver in a function: Query: () => ({ todos: () => [...] })","message":"mockNetworkAdd resolvers must be functions returning objects, not plain objects. Using { Query: { todos: [...] } } will not work.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'1.0.2':29 '12':48 'add':8 'api':17,57 'auto':41 'auto-gener':40 'command':10 'current':26 'custom':9,44 'cy.mocknetwork':11 'cy.mocknetworkadd':12 'cy.mocknetworkreset':13 'cypress':1,5,20,55 'cypress-n':54 'differenti':49 'end':22,24 'end-to-end':21 'extern':62 'fixtur':63 'generat':42 'graphql':2,16,31,59 'intercept':35,69 'javascript':73 'leverag':64 'mock':3,15,32,45,60 'nativ':56 'network':4,33,36 'node':47 'plugin':6 'provid':51 'request':37 'requir':46 'respons':18 'return':39 'servic':66 'ship':70 'simpl':53 'stabl':27 'test':25 'type':72 'typescript':71,74 'version':28 'without':61 'worker':67 'wrap':30","created_at":"2026-06-07T16:51:09.343560+00:00","updated_at":"2026-06-07T16:51:09.343560+00:00","problems":[{"fix":"Ensure the schema file path is correct relative to cypress.json. Use cy.readFile('./introspection.schema.graphql') or full path.","cause":"cy.readFile() did not resolve properly or schema was null.","error":"TypeError: Cannot read properties of undefined (reading 'schema')"},{"fix":"Add 'import 'cypress-graphql-mock-network'' to cypress/support/index.ts (or .js).","cause":"Plugin not imported or imported incorrectly.","error":"cy.mockNetwork is not a function"},{"fix":"Call cy.mockNetwork({ schema: yourSchema }) with a valid schema string.","cause":"cy.mockNetwork() called without schema argument or schema undefined.","error":"MockNetwork: No schema provided"},{"fix":"Copy mockServiceWorker.js from node_modules to the public/static folder that serves your app's root.","cause":"mockServiceWorker.js not served at root.","error":"Service worker not found: /mockServiceWorker.js"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/warrenday/cypress-graphql-mock-network","github":"https://github.com/warrenday/cypress-graphql-mock-network","docs":null,"changelog":null,"pypi":null,"npm":"cypress-graphql-mock-network","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}