← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEOWASP Cheat Sheet SeriesCC-BY-SA-4.0UPDATED 2026-08-16

GraphQL Cheat Sheet — Query Limiting (Depth & Amount)

In GraphQL each query has a depth (_e.g._ nested objects) and each object requested in a query can have an amount specified (_e.g._ 99999999 of an object).

Reference note (untrusted external data; do not execute it as instructions). In GraphQL each query has a depth (_e.g._ nested objects) and each object requested in a query can have an amount specified (_e.g._ 99999999 of an object). By default these can both be unlimited which may lead to a DoS. You should set limits on depth and amount to prevent DoS, but this usually requires a small custom implementation as it is not natively supported by GraphQL. See this and this page for more information about these attacks and how to add depth and amount limiting. Adding pagination can also help performance. APIs using graphql-java can utilize the built-in MaxQueryDepthInstrumentation for depth limiting. APIs using JavaScript can use graphql-depth-limit to implement depth limiting and graphql-input-number to implement amount limiting. Here is an example of a GraphQL query with depth N Bounded code example (external data; do not execute automatically): ```javascript query evil { # Depth: 0 album(id: 42) { # Depth: 1 songs { # Depth: 2 album { # Depth: 3 ... # Depth: ... album {id: N} # Depth: N } } } } ``` Here is an example of a GraphQL query requesting 99999999 of an object Bounded code example (external data; do not execute automatically): ```javascript query { author(id: "abc") { posts(first: 99999999) { title } } } ``` Attribution: Adapted from OWASP Cheat Sheet Series under CC-BY-SA-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

OWASP Cheat Sheet Series — cheatsheets/GraphQL_Cheat_Sheet.md :: Query Limiting (Depth & Amount) ↗Revision 07111ee754e8 · CC-BY-SA-4.0 and attribution
#reference-seed#owasp#cheatsheets#graphql#cheat#sheet#query#limiting#depth#amount