@pepeeja/cypress-graphql
Install
npm install -D @pepeeja/cypress-graphql
Configuration
Import the package in the file cypress/support/commands.js
or cypress/support/commands.ts
:
import '@pepeeja/cypress-graphql';
Commands
cy.graphqlContext
Creates isolated GraphQL mock which has private context. Context is exposed as function (gql) => {}
cy.graphqlContext((gql) => {
gql
.schemaFromString(schema)
.options({ url: 'http://localhost:4000/graphql' })
.mock('GetBooks', {
books: [
{
id: 1,
title: 'Test title',
author: 'Test author',
},
],
});
});
cy.graphqlConfig
Creates global configuration which will be applied to all cy.graphqlMock
commands.
cy.graphqlConfig({
schemaString: schema,
options: { url: 'http://localhost:4000/graphql', delay: 0, method: 'POST' },
});
cy.graphqlMock
Mocking outgoing graphql query based on operation name.
cy.graphqlMock('GetBooks', {
books: [
{
id: 1,
title: 'Test title',
author: 'Test author',
},
],
});
Examples
You can find working application here.
License
This project is licensed under the terms of the MIT License