GraphQL has become a popular API query language, but testing GraphQL schemas and operations requires specialized tools. This guide compares three leading open-source GraphQL testing approaches: GraphQL Inspector, GraphQL Code Generator’s testing utilities, and Apollo Client’s testing framework.

What Makes GraphQL Testing Different?

Unlike REST APIs, GraphQL has a strongly-typed schema that enables unique testing capabilities: schema validation, operation verification, breaking change detection, and type-safe mock generation. Traditional HTTP testing tools fall short because they cannot validate GraphQL-specific concerns like schema compatibility, query depth limits, or resolver behavior.

The right testing tool catches schema breaking changes before they reach production, validates that client queries match the server schema, and generates type-safe test fixtures automatically.

Tool Comparison at a Glance

FeatureGraphQL InspectorGraphQL Codegen TestingApollo Client Testing
Primary FocusSchema validation & change detectionType-safe test generationClient-side testing
Schema ValidationYesYesPartial
Breaking Change DetectionYesNoNo
Mock GenerationNoYesYes
CI/CD IntegrationYesYesYes
GitHub Stars1,74611,23919,715
GitHub Repographql-hive/graphql-inspectordotansimha/graphql-code-generatorapollographql/apollo-client
LicenseMITMITMIT
Docker SupportYesYesN/A (library)

GraphQL Inspector

GraphQL Inspector focuses on schema-level validation and change detection. It compares your current schema against a previous version to identify breaking changes before deployment.

Key Features

  • Schema diffing: Detects breaking, dangerous, and non-breaking changes between schema versions
  • Operation validation: Checks if client queries are valid against the current schema
  • GitHub integration: Posts schema change reports directly on pull requests
  • CI/CD pipeline: Fails builds when breaking changes are detected
  • Schema registry: Stores schema versions for historical comparison

Docker Compose Deployment

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
version: "3.8"
services:
  graphql-inspector:
    image: ghcr.io/kamilkisiela/graphql-inspector:latest
    ports:
      - "3000:3000"
    environment:
      - GITHUB_TOKEN=${GITHUB_TOKEN}
      - INSPECTOR_SCHEMA_ENDPOINT=https://your-api.com/graphql
    volumes:
      - ./config:/app/config

Schema Diff Pipeline

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Compare local schema against production
graphql-inspector diff ./schema.graphql https://prod-api.com/graphql

# Validate all operations in a directory
graphql-inspector validate ./src/**/*.graphql ./schema.graphql

# Check for breaking changes in CI
graphql-inspector actions diff \
  --branch main \
  --schema ./schema.graphql \
  --github-token $GITHUB_TOKEN

GraphQL Code Generator

GraphQL Code Generator creates type-safe code from your GraphQL schema. Its testing utilities generate typed mocks, test fixtures, and factory functions that make unit testing significantly easier.

Key Features

  • Typed mock generation: Creates TypeScript mocks with correct types from your schema
  • Test factory functions: Generates factory functions for creating test data
  • Plugin ecosystem: Extensible with custom plugins for any testing framework
  • Framework support: Works with Jest, Vitest, Testing Library, and more
  • Automatic updates: Regenerates test fixtures when schema changes

Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# codegen.yml
overwrite: true
schema: "http://localhost:4000/graphql"
documents: "src/**/*.graphql"
generates:
  src/generated/graphql.ts:
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
  src/generated/mocks.ts:
    plugins:
      - typescript-mock-data
    config:
      typesFile: "./graphql.ts"
      enumValues: "keep"
      terminateCircularRelationships: true

Installation and Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Install codegen and mock plugin
npm install @graphql-codegen/cli @graphql-codegen/typescript-mock-data --save-dev

# Generate types and mocks
npx graphql-codegen --config codegen.yml

# Use generated mocks in tests
import { mockUser, mockPost } from './generated/mocks';

test('renders user profile', () => {
  const user = mockUser();
  render(<Profile user={user} />);
  expect(screen.getByText(user.name)).toBeInTheDocument();
});

Apollo Client Testing Framework

Apollo Client provides built-in testing utilities for React and other UI frameworks. The MockedProvider component lets you mock GraphQL responses without running a real server.

Key Features

  • MockedProvider: Wraps React components with mocked GraphQL responses
  • Query testing: Tests loading, error, and success states
  • Mutation testing: Verifies mutation calls and cache updates
  • Cache inspection: Direct access to Apollo Cache for assertions
  • No server needed: Tests run entirely client-side

Test Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { MockedProvider } from '@apollo/client/testing';
import { render, screen, waitFor } from '@testing-library/react';
import { UserProfile } from './UserProfile';
import { GET_USER } from './queries';

const mocks = [
  {
    request: {
      query: GET_USER,
      variables: { id: '1' },
    },
    result: {
      data: {
        user: {
          id: '1',
          name: 'Test User',
          email: 'test@example.com',
          __typename: 'User',
        },
      },
    },
  },
];

test('displays user name', async () => {
  render(
    <MockedProvider mocks={mocks} addTypename={true}>
      <UserProfile userId="1" />
    </MockedProvider>
  );

  expect(screen.getByText(/loading/i)).toBeInTheDocument();

  await waitFor(() => {
    expect(screen.getByText('Test User')).toBeInTheDocument();
  });
});

Docker-based Test Server

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: "3.8"
services:
  test-graphql:
    image: node:20-alpine
    working_dir: /app
    volumes:
      - .:/app
      - /app/node_modules
    command: sh -c "npm install && npm test"
    environment:
      - NODE_ENV=test
      - GRAPHQL_URL=http://mock-server:4000/graphql

When to Use Each Tool

ScenarioBest Tool
Detecting breaking schema changes in CIGraphQL Inspector
Generating type-safe test fixturesGraphQL Code Generator
Testing React components with GraphQLApollo Client Testing
Validating client queries against schemaGraphQL Inspector
Creating mock data for unit testsGraphQL Code Generator
End-to-end client integration testsApollo Client Testing

Why Self-Host GraphQL Testing?

Running GraphQL testing tools on your own infrastructure ensures your schema never leaves your network. For teams working with sensitive data or proprietary APIs, self-hosted testing prevents accidental schema exposure to third-party services.

Self-hosted schema validation runs as part of your CI pipeline without external dependencies, making builds faster and more reliable. When your CI runner loses connectivity to a cloud testing service, your entire deployment pipeline stalls. Local tools eliminate this single point of failure.

For large organizations with multiple GraphQL services, a self-hosted schema registry enables cross-team schema validation. Teams can verify their changes against dependent services without coordination overhead. This is especially valuable for federated GraphQL architectures where schema changes in one service can break clients of another.

For teams using GraphQL gateway patterns, see our GraphQL gateway comparison and GraphQL federation guide. For visual schema exploration, our GraphQL IDE comparison covers the best browser-based tools.

FAQ

What is the best tool for detecting breaking changes in GraphQL schemas?

GraphQL Inspector is the most purpose-built tool for this task. It compares schema versions and categorizes changes as breaking, dangerous, or non-breaking. It integrates directly with GitHub pull requests and CI pipelines to block deployments that introduce breaking changes.

Can GraphQL Code Generator replace Apollo Client’s MockedProvider?

No, they serve different purposes. GraphQL Code Generator creates type-safe mock data and test fixtures, while Apollo Client’s MockedProvider simulates server responses for component testing. They work best together: use Codegen to generate typed mocks, then pass those mocks to MockedProvider.

Do I need a GraphQL testing tool if I have unit tests?

Unit tests verify your resolver logic, but they cannot detect schema-level issues like breaking changes to field types or removed queries. GraphQL Inspector catches these problems before they reach clients. For comprehensive coverage, combine unit tests with schema validation and client-side integration tests.

How do I test GraphQL subscriptions?

Apollo Client testing supports subscription mocks through the MockedProvider by adding subscription responses to the mocks array. For end-to-end subscription testing, run a real GraphQL server in your test environment and use WebSocket connections to verify real-time updates.

Can these tools work with federated GraphQL schemas?

Yes. GraphQL Inspector supports federated schemas through its schema composition validation. GraphQL Code Generator works with any valid GraphQL schema, including composed federated schemas. Apollo Client testing handles federated queries by mocking the composed schema response.

How do I integrate GraphQL Inspector into a GitHub Actions pipeline?

Add the GraphQL Inspector GitHub Action to your workflow. It automatically detects schema changes in pull requests and posts inline comments with breaking change warnings. Configure the action with your schema endpoint and GitHub token for automatic PR reviews.

What is the difference between schema validation and operation validation?

Schema validation checks if your GraphQL schema definition is syntactically correct and follows GraphQL specification rules. Operation validation checks if client queries and mutations are valid against a specific schema. GraphQL Inspector does both; Apollo Client testing focuses on operation validation.