Skip to content

Latest commit

 

History

History

parrot-graphql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Parrot-GraphQL

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 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

// 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 that is passed to graphql-tools mockServer.