Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pepeeja/cypress-graphql
Cypress command to mock GraphQL requests
https://github.com/pepeeja/cypress-graphql
cypress graphql javascript mock typescript
Last synced: 7 days ago
JSON representation
Cypress command to mock GraphQL requests
- Host: GitHub
- URL: https://github.com/pepeeja/cypress-graphql
- Owner: pepeeja
- License: mit
- Created: 2021-03-03T16:53:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-17T16:26:35.000Z (almost 4 years ago)
- Last Synced: 2024-12-27T12:02:52.344Z (25 days ago)
- Topics: cypress, graphql, javascript, mock, typescript
- Language: TypeScript
- Homepage:
- Size: 677 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @pepeeja/cypress-graphql
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/pepeeja/cypress-graphql/blob/main/LICENSE) [![npm latest package](https://img.shields.io/npm/v/@pepeeja/cypress-graphql/latest.svg)](https://www.npmjs.com/package/@pepeeja/cypress-graphql) [![npm type definitions](https://img.shields.io/npm/types/@pepeeja/cypress-graphql)](https://github.com/pepeeja/cypress-graphql/search?l=typescript)
## Install
```shell
npm install -D @pepeeja/cypress-graphql
```## Configuration
Import the package in the file `cypress/support/commands.js` or `cypress/support/commands.ts`:
```ts
import '@pepeeja/cypress-graphql';
```## Commands
### `cy.graphqlContext`
Creates isolated GraphQL mock which has private context. Context is exposed as function `(gql) => {}`
```ts
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.
```ts
cy.graphqlConfig({
schemaString: schema,
options: { url: 'http://localhost:4000/graphql', delay: 0, method: 'POST' },
});
```### `cy.graphqlMock`
Mocking outgoing graphql query based on operation name.
```ts
cy.graphqlMock('GetBooks', {
books: [
{
id: 1,
title: 'Test title',
author: 'Test author',
},
],
});
```## Examples
You can find working application [here](/example).
## License
This project is licensed under the terms of the [MIT License](LICENSE)