Q19 of 20 · GraphQL

How do you integrate GraphQL tests into a CI pipeline?

GraphQLMidgraphqlci-cdcontract-testingapi

Short answer

Short answer: Run code-based GraphQL tests (POST + body assertions) as part of the normal test stage, gate on the negative/error tests so the 200-on-error trap can't regress, and add a schema-diff check that fails the build on breaking schema changes.

Detail

A solid GraphQL CI setup has three layers:

  1. Functional + negative suite — code-based tests that POST queries/mutations and assert on data/errors. Critically, gate on the negative tests (the ones asserting error codes), because those are what catch the 200-on-error regressions; a suite of only happy-path tests gives false confidence.
  2. Schema-diff gate — commit the schema SDL and run a diff against the published/previous schema on every PR, failing on breaking changes (removed/renamed fields, type changes, new non-null inputs). This is GraphQL's contract test.
  3. Performance check (where it matters) — for hot list queries, an assertion on resolver/DB call count to catch N+1 before it ships.

Practical notes:

  • Run against a real test instance (or schema-based mock) seeded with known data.
  • Keep queries version-controlled alongside the app so CI and developers use identical operations.
  • Surface failures with the failing field's path and extensions.code so triage is fast.

The shape mirrors REST API CI, with the GraphQL-specific additions of schema-diff and error-array gating.

// WHAT INTERVIEWERS LOOK FOR

Gating on negative/error tests, a schema-diff breaking-change gate, and version-controlled queries — not just running happy-path tests.