parrot-graphql

5.0.0 • Public • Published

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.

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i parrot-graphql

    Weekly Downloads

    200

    Version

    5.0.0

    License

    Apache-2.0

    Unpacked Size

    73 kB

    Total Files

    6

    Last publish

    Collaborators

    • jayjaycross
    • amexopensource