GraphQL Integration Test Example

A test can execute a complete operation and assert both the returned data and expected errors.

Testing a GraphQL Query
const query = `
  query GetUser($id: ID!) {
    user(id: $id) {
      id
      name
    }
  }
`;

const response = await graphql({
  schema,
  source: query,
  variableValues: { id: "42" },
  contextValue: { user: testUser }
});

expect(response.errors).toBeUndefined();
expect(response.data.user.id).toBe("42");
💡 The test executes the operation through the GraphQL schema and verifies the final result rather than calling the user resolver directly.