npm install cy-mock-graphql
yarn add cy-mock-graphql
type Person {
firstname: String!
surname: String!
}
type Query {
people: [Person]
}
import mockGraphQL from 'cy-mock-graphql'
import schema from 'schema.gql'
describe('My Cypress Test', () => {
beforeEach(() => {
cy.mockGraphQL(schema, {
Query: () => ({
people: () => ([
{
firstname: 'Gary',
surname: 'Ryan'
}
])
})
})
})
it('Should mock graphql', () => {
...
})
})
mockGraphQL(schema, mock, options)
- Required
- Types:
- SDL (Schema Definition Language), String
- Introspection Query Result, Object
- Optional
- Type: Object with resolver functions, see example in usage section.
{
endpoint: String | default '/graphql'
}
- endpoint: specifiy the graphql endpoint
git clone ...
yarn
yarn ci
MIT