Learn

GraphQL limits

Protect a GraphQL API against resource-exhaustion attacks: deeply nested queries, alias flooding, batch abuse and introspection.

GraphQL limits

Setting it up

Route editor → GraphQL → Protect a GraphQL endpoint:

  1. Enter the endpoint paths (default /graphql; one per line).
  2. Set the limits (or leave the defaults):
Limit Default What it prevents
Max depth 10 Deeply nested selections
Max aliases 30 Alias flooding (100 logins in one request)
Max fields 500 Overly broad queries
Max batch 5 Too many operations per HTTP request
Max fragments 100 Fragment abuse
Max directives per field 5 Directive abuse
Max tokens 10,000 Very large documents (refused before parsing)
  1. Configure introspection: blocked by default. Allow it for developer networks only.
  2. It starts in Log only — the request log (view GraphQL limits) shows "Would be refused" with the reason.
  3. Watch for real clients that trigger the limits and adjust. Switch to Enforce when the log is quiet.

Advanced options

  • Cost limit (Max cost): every field costs 1; fields under a pagination argument (first, last, limit) multiply. Give expensive fields a higher cost under Field costs (e.g. Query.search = 10).
  • Schema allowlist: upload the API's SDL schema. Queries for unknown types, fields or arguments are refused.
  • Persisted queries: only allow queries whose SHA-256 hash is on a list. Supports Apollo's automatic persisted query protocol.
  • Hide field suggestions: removes "Did you mean 'password'?" from error responses (which would otherwise reveal the schema even with introspection off).

Attack detection inside GraphQL

Attack detection inspects each GraphQL argument and variable on its own (login.password, $input.email), so normal GraphQL syntax (braces, $, ...) does not trigger false positives.

Rate limiting GraphQL operations

A rate limit can count GraphQL operations instead of requests. Tick Count GraphQL operations and optionally Only this operation (e.g. login). Then 100 login mutations in one batched request count as 100.

Example: protecting a login mutation from batching

  1. Add a rate limit: 10 per minute, per address, count GraphQL operations, only operation = login.
  2. A client sending { login(…) login(…) login(…) } three times per request uses 3 of the 10. After 10 logins in a minute, the client gets 429.