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: 4 months 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 (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-17T16:26:35.000Z (about 4 years ago)
- Last Synced: 2025-02-14T10:06:01.401Z (5 months 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
[](https://github.com/pepeeja/cypress-graphql/blob/main/LICENSE) [](https://www.npmjs.com/package/@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)