Skip to main content

Token limits

Limit the number of lexer/parser tokens in a GraphQL document before full parse or validation.

Practices implemented

Applies to

  • GraphQL servers
  • Gateways and proxies
  • Parser/security middleware

Configuration (suggested defaults)

ParameterDefaultNotes
maxTokens15000Maximum tokens allowed for application operations.
maxIntrospectionTokens30000Higher allowance for introspection documents.
onLimitExceededrejectOne of: reject, warn.

Implementation notes

  • Count tokens from the lexer stream before expensive parse/validation phases.
  • Enforce separate token ceilings for application and introspection operations.
  • Return stable error codes/messages so users can tune limits safely.

Cautions

  • Very low limits can break legitimate operations with many fragments.
  • Token limits are not a replacement for depth/complexity controls.

Problems addressed