Keploy logo
GraphQL logo

Keploy as a GraphQL testing framework

Keploy tests GraphQL APIs by recording real operations over HTTP and every database or upstream call the resolvers made, then replaying both as assertions. There is no schema to mock, no resolver stub to maintain, and no in-process test server to construct.

Generate GraphQL tests free
keploy record -c "node dist/server.js"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a GraphQL team

Any GraphQL server, unchanged

Keploy records the HTTP transport, so Apollo Server, GraphQL Yoga, Strawberry, graphql-java, and gqlgen all record the same way. Operation name, variables, and the response shape are all captured.

  • Apollo, Yoga, Strawberry, gqlgen
  • Queries, mutations, and fragments
  • Persisted queries supported
  • Batched operations captured
The problem

Why GraphQL integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing GraphQL: by hand, with Apollo Server testing + mocked schema, or with Keploy

A mocked schema returns type-correct placeholders, so resolvers are the one layer never exercised. Keploy records real operations and every query the resolvers issued.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for GraphQL vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
orders.resolver.test.ts
hand-written
// Hand-written: the resolver is called with a stubbed context.
import { resolvers } from './orders.resolvers';
 
const context = {
dataSources: {
orders: { byId: async (id) => ({ id, amountMinor: 4200, state: 'NEW' }) },
payments: { authorize: async () => ({ status: 'AUTHORIZED' }) },
},
};
 
it('confirms an authorized order', async () => {
const result = await resolvers.Mutation.confirmOrder(
null,
{ id: 'ord_1', paymentToken: 'tok_123' },
context,
);
 
expect(result.state).toBe('CONFIRMED');
});

The resolver runs, but its data sources are stubs. Field-level resolvers, DataLoader batching, and the actual query count are all invisible.

Apollo Server testing + mocked schema1–2 hours
orders.schema.test.ts
tool-assisted
// Apollo Server + addMocksToSchema.
import { ApolloServer } from '@apollo/server';
import { addMocksToSchema } from '@graphql-tools/mock';
 
const server = new ApolloServer({
// Every field gets type-correct placeholder data.
schema: addMocksToSchema({ schema, mocks: { Int: () => 4200 } }),
});
 
it('confirms an authorized order', async () => {
const res = await server.executeOperation({
query: CONFIRM_ORDER,
variables: { id: 'ord_1', paymentToken: 'tok_123' },
});
 
// This passes whatever the resolvers do, because they never ran.
expect(res.body.singleResult.errors).toBeUndefined();
});

Instant and schema-accurate — and because the mocks replace the resolvers, this assertion holds even if every resolver is broken.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'node dist/server.js'
# Real resolvers ran. Every query they issued is here.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /graphql
body: '{"operationName":"ConfirmOrder","variables":{"id":"ord_1","paymentToken":"tok_123"}}'
resp:
status_code: 200
body:
data:
confirmOrder:
id: "ord_1"
state: "CONFIRMED"
amountMinor: 4200
noise:
- body.data.confirmOrder.confirmedAt
# Two queries for one mutation — the N+1 made visible.
mocks:
- kind: Postgres
operation: "SELECT id, amount_minor, state FROM orders WHERE id = $1"
- kind: Postgres
operation: "SELECT id, name FROM customers WHERE id = $1"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm

The mocks list is the query count for one operation, so an N+1 introduced by a new field resolver shows up as extra recorded queries.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

GraphQL testing tools, compared

The options a team on service and platform integrations actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your GraphQL app once, replay it forever

Keploy sits below your GraphQL process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a GraphQL service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for GraphQL, with zero config

6 of the 7 dependencies a typical GraphQL service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first GraphQL test suite in under five minutes

Every command below runs against your existing GraphQL service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "node dist/server.js"
  3. 3Exercise the paths you care about

    Send the operations you care about. Each one becomes a test case with every resolver query it triggered captured alongside.

    curl -X POST localhost:4000/graphql -H 'Content-Type: application/json' -d '{"operationName":"ConfirmOrder","query":"mutation ConfirmOrder($id:ID!,$paymentToken:String!){confirmOrder(id:$id,paymentToken:$paymentToken){id state amountMinor}}","variables":{"id":"ord_1","paymentToken":"tok_123"}}'
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "node dist/server.js" --delay 10

Ready to try it on your own GraphQL service?

FAQ

GraphQL testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.