Skip to content

Instantly share code, notes, and snippets.

@JakeDawkins
Created May 1, 2018 01:56
Show Gist options
  • Save JakeDawkins/84d810d96cc1b36ed270bc09ba148816 to your computer and use it in GitHub Desktop.
Save JakeDawkins/84d810d96cc1b36ed270bc09ba148816 to your computer and use it in GitHub Desktop.
Example of integration testing a GraphQL schema
import { schema } from '../my-schema';
// Docs for `graphql` function
// http://graphql.org/graphql-js/graphql/#graphql
import { graphql } from 'graphql';
it('executes a query that looks up some data', async () => {
// optionally create some fake context (i.e. data connectors)
const myFakeContext = { restConnectionOne: { findOne: jest.fn() } };
const expectedResult = {...};
const result = await graphql(schema, query, {}, myFakeContext);
expect(result.data).toEqual(expectedResult);
expect(myFakeContext.restConnectionOne.findOne).toBeCalledWith({ id: 1 });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment