Registry / testing / parrot-graphql

parrot-graphql

JSON →
library5.3.0jsnpmunverified

Parrot-GraphQL is a helper library for creating GraphQL mocks used with Parrot, resolving both GET and POST requests to GraphQL endpoints. Version 5.3.0 wraps @graphql-tools/mock's mockServer to define mocking logic per schema type. It simplifies mocking GraphQL queries by allowing users to provide a schema string and custom mock resolvers, integrated seamlessly with Parrot's scenario-based testing. Released under American Express, it targets Node.js with CommonJS require syntax, though ESM may be available in newer versions. The library is ideal for integration and end-to-end testing with GraphQL APIs.

npm install parrot-graphql
INSTALL
IMPORT
SIG · PARROT-GRAPHQL
P
parrot-graphql
testingjavascriptv5.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

graphql
const { graphql } = require('parrot-graphql');
const graphql = require('parrot-graphql');
The library exports a named export 'graphql' (not default). CommonJS require with destructuring is correct.
graphql
import { graphql } from 'parrot-graphql';
import graphql from 'parrot-graphql';
ESM import must use named import syntax. Default import is not available.
graphql
const graphql = require('parrot-graphql').graphql;
const graphql = require('parrot-graphql/graphql');
Avoid subpath imports; the function is at the package root.

Creates a Parrot scenario that mocks a GraphQL endpoint with custom resolver logic using casual library.

const { graphql } = require('parrot-graphql'); const casual = require('casual'); const schema = ` type Query { user(id: ID!): User } type User { id: ID! name: String! email: String! } `; const scenarios = { 'returns a user': [ graphql('/graphql', schema, { User: () => ({ id: '1', name: casual.name, email: casual.email, }), }), ], }; module.exports = scenarios;
Debug
Known issues
breakingVersion 5.x removed default export; use named import { graphql }.
fix
Change 'const graphql = require("parrot-graphql");' to 'const { graphql } = require("parrot-graphql");'
affects: >=5.0.0
deprecatedThe peer dependency 'parrot' is required but not automatically installed.
fix
Install parrot separately: npm install parrot --save-dev
affects: >=1.0.0
gotchaGraphQL schema must be provided as a string; SDL object not supported.
fix
Ensure schema is a string, e.g., const schema = `type Query { hello: String }`;
affects: *
gotchaMocks object keys must correspond to GraphQL type names (not field names).
fix
Provide mock resolvers per type, not per field (e.g., mocks.User = () => ({...})).
affects: *
Errors
Common errors & fixes
Cannot find module 'parrot-graphql'
Package not installed or missing from node_modules.
fix
Run npm install parrot-graphql --save-dev
graphql is not a function
Using default import instead of named import.
fix
Use const { graphql } = require('parrot-graphql');
Must provide a valid GraphQL schema string
Schema argument is undefined or not a string.
fix
Ensure the schema is a string literal or template string.
Cannot read property 'mockServer' of undefined
Missing @graphql-tools/mock dependency or incompatible version.
fix
Install @graphql-tools/mock: npm install @graphql-tools/mock --save-dev
Upgrade
Version history
5.3.0latest on npm
Audit
Dependencies
@graphql-tools/mockrequiredCore mocking engine used to create mock server from schema and mocks.
parrotrequiredRun-time peer dependency for creating scenarios; the graphql() function returns handlers consumable by Parrot.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
parrot-graphql — npm install parrot-graphql · libregistry