graphql-codegen-cypress-typescript
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Introduction

This is a plugin for the graphql-codegen platform. It allows typesafe wrappers to Cypress's cy.request function for more easily accessable type safe testing wrappers in your e2e test code.

Usage

It doesn't directly call cy.request, instead it calls cy.gql which is a function that you will need to provide. This function should have the following schema.

declare namespace Cypress {
  interface Chainable {
    gql(
      query: string, 
      variables?: {[key: string] : any}, 
      headers?: {[key: string] : any}
    ) : Cypress.Chainable<Cypress.Response>
  }
}

Here is an example implementation.

Cypress.Commands.add('gql', (query, variables, headers = {}) => {
  cy.request({
    method: 'POST',
    body: {
      variables,
      query: query.loc.source.body,
    },
    url: '/api/graphql',
    headers: {
      'Content-Type': 'application/json',
      ...headers,
    },
  });
});

Currently the plugin doesn't have any configuration options.

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-codegen-cypress-typescript

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

550 kB

Total Files

19

Last publish

Collaborators

  • robbert229