HomeGuides › GraphQL API testing

GraphQL API testing: queries, mutations and query cost

By the Flasqo team · Updated 24 August 2026

In short

GraphQL returns HTTP 200 for almost everything, so status-code assertions are nearly useless. This guide covers introspection-driven generation, the N+1 problem, depth limits and testing mutations properly.

  • GraphQL returns HTTP 200 for almost everything, including errors — so status-code assertions are nearly useless and tests must read the errors array.
  • Schema introspection gives you the complete type graph, which makes automated test generation more tractable than for REST.
  • The N+1 problem turns a request for 100 records into 101 database round-trips, and is invisible to response assertions.
  • Production schemas need depth and complexity limits — without them a single small query can force exponential resolution cost.

How GraphQL testing differs from REST

The differences are structural, and they invalidate most REST testing habits.

RESTGraphQL
EndpointsMany, one per resourceOne, usually /graphql
Errors4xx / 5xx status codesHTTP 200 with an errors array
Response shapeFixed by the serverDetermined by the client's query
DiscoveryOpenAPI, if it existsIntrospection, always available
Over-fetchingCommonSolved — but replaced by cost problems

The single most important consequence: a 200 response can be a complete failure. A GraphQL server that cannot resolve a field returns 200 with data: null and a populated errors array. A test asserting only on status code will pass while every field failed to resolve.

Testing with introspection

Introspection is GraphQL's most useful testing affordance. A single query returns the entire schema — every type, field, argument, nullability marker and enum value — which is more machine-readable structure than most REST APIs ever document.

From that graph you can derive test cases mechanically: a query for every field, a mutation for every input type, null probes for every non-nullable field, and invalid-type probes for every argument. This is exactly the work auto-discovery performs before generating a suite.

Note that introspection is often disabled in production, and reasonably so — it hands an attacker a complete map of your API. Test against an environment where it is enabled, then run the generated suite against production.

What to assert on

The N+1 problem

A query that fetches a list and then a related field for each item resolves the list with one query, then fires one query per item. Requesting 100 posts with their authors becomes 1 + 100 = 101 database round-trips.

query {
  posts(first: 100) {    # 1 query
    title
    author { name }      # + 100 queries, one per post
  }
}

This is invisible to response assertions — the data is correct, it just cost a hundred times more than it should. Detecting it requires observing query counts or resolver timing during the test rather than only the response. The standard fix is a batching data loader that collects the author IDs and fetches them in a single query.

Depth and complexity limits

Because clients compose their own queries, a client can nest recursive relationships arbitrarily deep:

query {
  user { posts { author { posts { author { posts { ... } } } } } }
}

Each level multiplies the resolution cost. A compact query can force an enormous amount of work — a denial-of-service vector requiring no special access. Production schemas should enforce a maximum query depth and a complexity budget that weights expensive fields more heavily, and your tests should confirm that an over-deep query is actually rejected rather than merely slow.

Testing mutations

Mutations need three assertions, and the third is the one usually skipped:

  1. The response payload is correct — the mutation returned what it promised.
  2. Invalid input is rejected in the errors array rather than partially applied.
  3. The state actually changed. Query the resource afterwards and confirm. Mutations that report success without persisting are a common and easily missed defect.

Mutations also need the same authorization probes as REST: authenticate as one user, attempt to mutate another user's resource, and confirm it is refused. See the security testing guide — object-level authorization flaws are as common in GraphQL as in REST, and the single endpoint makes them easier to overlook.

Test your API without writing the tests

Paste a URL. Flasqo discovers your endpoints, generates the suite and runs it — free, no credit card.

Start testing free

Frequently asked questions

How is testing GraphQL different from REST?

GraphQL exposes one endpoint and almost always returns HTTP 200, including for errors — failures arrive in an "errors" array inside the body. Status-code assertions are therefore nearly useless, and tests must assert on the response payload, the errors array and the resolved data shape instead.

What is the N+1 problem in GraphQL?

A nested query that resolves a list of N items and then fetches a related field for each one triggers 1 query for the list plus N queries for the children. A request for 100 records can silently become 101 database round-trips. Detecting it needs query-count observation during the test, not just response assertions.

Why limit GraphQL query depth?

Because a client can nest recursive relationships arbitrarily deep and force an exponential resolution cost from a single small request — an easy denial-of-service vector. Production schemas should enforce a maximum depth and a complexity budget, and tests should confirm the limits actually reject an over-deep query.

How do you test GraphQL mutations?

Assert three things: that the mutation returns the expected payload, that the underlying state actually changed when queried afterwards, and that invalid input is rejected in the errors array rather than partially applied. Mutations that succeed in the response but do not persist are a common defect.

Related reading

API Testing: The Complete Guide API Fuzz Testing: Break It Before Attackers Do API Integration Testing: Validate Multi-Endpoint Workflows API Auto-Discovery: Endpoint Detection & Scoring Vibe Testing: AI-Powered Test Generation From Real Artifacts Visual Flow Builder: Drag-and-Drop API Test Workflows Production Gate: Pre-Deployment Readiness Testing & Scoring 11 Best Free API Testing Tools in 2026 9 Best Postman Alternatives in 2026 Flasqo vs Postman Flasqo vs Insomnia