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.
// 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;
Creates a function for your GraphQL endpoint.
path
(String): Path of your GraphQL endpoint.schema
(String): GraphQL schema string.mocks
(Object): Object describing your mocking logic that is passed to graphql-toolsmockServer
.