rumtraubenuss / mock-graphql-cypress

Cypress command to mock a GraphQL API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cypress Mock GraphQL

Installation

npm install cy-mock-graphql
yarn add cy-mock-graphql

Usage

schema.gql

type Person {
  firstname: String!
  surname: String!
}

type Query {
  people: [Person]
}

myCypressTest.spec.js

import mockGraphQL from 'cypress-mock-graphql'
import schema from 'schema.gql'

describe('My Cypress Test', () => {
  beforeEach(() => {
    mockGraphQL(schema, {
      Query: {
        people: () => ([
          {
            firstname: 'Gary',
            surname: 'Ryan'
          }
        ])
      }
    })
  })

  it('Should mock graphql', () => {
    ...
  })
})

API

mockGraphQL(schema, mock, options)

Schema

Mock

  • Optional
  • Type: Object with resolver functions, see example in usage section.

Options

  {
    endpoint: String | default '/graphql'
  }
  • endpoint: specifiy the graphql endpoint

Contributing

git clone ...

yarn
yarn ci

License

MIT

About

Cypress command to mock a GraphQL API

License:MIT License


Languages

Language:JavaScript 97.0%Language:HTML 3.0%