# parrot-graphql

> A helper library to create GraphQL Parrot mocks.

Latest version **5.3.0** (published 2025-01-03) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install parrot-graphql
pnpm add parrot-graphql
yarn add parrot-graphql
bun add parrot-graphql
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.3.0 |
| Published | 2025-01-03 |
| First published | 2018-02-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 71.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Maintainers | jayjaycross, amexopensource |

## Links

- npm: https://www.npmjs.com/package/parrot-graphql
- Repository: https://github.com/americanexpress/parrot
- Homepage: https://github.com/americanexpress/parrot#readme
- Issues: https://github.com/americanexpress/parrot/issues
- npm.io page: https://npm.io/package/parrot-graphql

## Dependencies (2)

- [graphql](https://npm.io/package/graphql.md) ^15.8.0
- [@graphql-tools/mock](https://npm.io/package/@graphql-tools/mock.md) ^8.7.20

## Recent versions

- 5.3.0 (latest) — 2025-01-03
- 5.2.1 — 2024-12-04
- 5.2.0 — 2024-11-06
- 5.1.0 — 2024-10-25
- 5.0.1 — 2024-10-09
- 5.0.0 — 2023-08-22
- 5.0.0-alpha.1 — 2022-02-25
- 5.0.0-alpha.0 — 2021-01-06
- 4.1.1 — 2020-06-25
- 4.1.0 — 2020-05-07
- 4.0.1 — 2020-04-17
- 3.0.0 — 2018-02-28

## README

<h1 align="center">
	<img src="./parrot-graphql.png" alt="Parrot-GraphQL" width="50%" />
</h1>

parrot-graphql is a helper library that resolves GET and POST requests to your GraphQL endpoint using mocking logic that is defined for each schema type. Under the hood, parrot-graphql is a small wrapper around [@graphql-tools/mock](https://github.com/apollographql/graphql-tools) `mockServer`.

For in-depth examples on how to write mock resolvers, read the above documentation from graphql-tools, but below is a simple example to start you on your way.

## Example

```js
// scenarios.js
const graphql = require('parrot-graphql');
const casual = require('casual'); // A nice mocking tool

const schema = `
type Query {
  shiplog: [ShipLog]
}

type ShipLog {
  Name: String!
  Captain: String!
}
`;

const scenarios = {
  'has a ship log from GraphQL': [
    graphql('/graphql', schema, {
      Name: () => 'Jolly Roger',
      Captain: () => casual.name,
    }),
  ],
};

module.exports = scenarios;
```

## API

### `graphql(path, schema, mocks)`

Creates a function for your GraphQL endpoint.

#### Arguments

- `path` (_String_): Path of your GraphQL endpoint.
- `schema` (_String_): GraphQL schema string.
- `mocks` (_Object_): Object describing your [mocking logic](https://www.apollographql.com/docs/graphql-tools/mocking.html#Customizing-mocks) that is passed to [graphql-tools](https://github.com/apollographql/graphql-tools) `mockServer`.

---
_Source: https://npm.io/package/parrot-graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
