Adds commands for executing a mocked GraphQL server using only the client
Clone or download
Latest commit 4e1bd40 Dec 9, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Rename file Dec 10, 2018
.gitignore Initial commit Dec 10, 2018 Update Dec 10, 2018
package.json v0.1.1 Dec 10, 2018
tsconfig.json Add main, types fields Dec 10, 2018
yarn.lock Initial commit Dec 10, 2018


Adds commands for executing a mocked GraphQL server using only the client


npm install cypress-graphql-mock


Adds .mockGraphql() and .mockGraphqlOps() methods to the cypress chain.

The .mockGraphql should be called in the Cypress before or beforeEach block config to setup the server. This method takes a schema, either in the form of one or more SDL files, or as the JSON result of an introspection query.

const schema = fs.readFileSync('../../app-schema.graphql', 'utf8');
// alternatively, using a dumped introspection query:
// const schema = require('../../dumped-schema.json')

beforeEach(() => {
  cy.mockGraphql({ schema });

By default, it will use the /graphql endpoint, but this can be changed depending on the expected server implementation.

beforeEach(() => {
    endpoint: '/gql'

It takes an "operations" object, representing the named operations of the GraphQL server. This is combined with the "mocks" option, to modify the output behavior per test.

The .mockGraphqlOps() allows you to configure the mock responses at a more granular level

For example, if we has a query called "UserQuery" and wanted to explicitly force a state where a viewer is null (logged out), it would look something like:

  operations: {
    UserQuery: {
      viewer: null


Githunt React