How to Set a GraphQL Resource Budget While Preserving Essential Workflows
A GraphQL resource budget should be built around specific product tasks: opening a list, moving to the next page, and viewing details. Identify the queries these workflows require and the resource costs the server is prepared to accept. OWASP recommends limiting query depth and the number of requested objects, as well as using cost analysis. Here is how to turn those recommendations into testable rules, without suggesting that one set of numbers can ensure API stability.
Start with workflows and the trust boundary
Start by listing the actions that must continue to work after limits are introduced. For each action, record the required fields, nested relationships, and page size. This forms the basis for testing: a successful response alone does not mean the user received everything needed to complete the task.
For this work, draw the trust boundary between the client's query and the server's decision about acceptable resource costs. The client describes the data it wants, but the budget must be defined and enforced on the server. Do not consider a query acceptable simply because your product's interface generated it. Test both normal operations and prepared cases that exceed the budget.
Define several limits instead of a single number
OWASP recommends limiting the depth of incoming GraphQL queries and the number of requested objects. Pagination allows you to limit the amount of data in a single response. Record these parameters separately: permitted nesting depth, object count limit, and maximum page size. Choose values for your own workflows; these recommendations do not specify universal numerical thresholds.
Supplement these rules with cost analysis: assign a cost to resolving fields or types and set a threshold above which the server rejects a query. Document how the budget is calculated and which operations must fit within it. Do not describe an assigned cost as a precise measurement of execution time or memory consumption: the facts presented here do not establish that relationship.
Work through a fictional budget example
Consider a wholly fictional order dashboard. Its test dataset contains only synthetic customers, products, and orders. The team chooses a page of 20 orders for the list, and order details with line items for the detail view. The number 20 is a condition of this example, not an OWASP recommendation.
The team prepares two sets of operations. The first reproduces the agreed interface actions. The second contains small, controlled deviations: a page size one above the chosen limit, an additional nesting level, or a cost just above the threshold. Expected results are recorded in advance: a normal workflow receives the required data, while an operation exceeding the relevant limit is rejected. This makes budget discussions concrete by showing which rule affects a particular task.
Give timeouts a supporting role
GraphQL does not natively support query timeouts; implementing them requires custom code. There is no single suitable value because requirements depend on the API and its data retrieval mechanism. Choose a timeout for your application instead of adopting a value from someone else's example without testing it.
A timeout may take effect only after excessive resources have already been consumed. On its own, it does not ensure that resource costs are limited in time. During testing, establish separately whether depth, object count, and cost limits are enforced; do not treat a timeout as proof that these rules work.
Do not substitute an HTTP request counter for a budget
Counting HTTP requests does not account for expensive GraphQL queries or multiple operations within a single request. Do not use that counter as the sole evidence that resource costs are acceptable. In your test plan, specify which forms of multiple-operation requests your application supports and how the chosen budget applies to them.
Server-side batching and caching can reduce resource consumption by preventing repeated retrieval of the same data within a short period. Treat them as additional optimizations. Their presence alone does not confirm that queries exceeding the agreed budget are rejected; that requires separate testing.
Test boundaries and address specific causes
Run tests in a test environment you own, using synthetic data and a small number of operations capped in advance. For each rule, prepare values below the threshold, at the boundary, and just above it. Change one parameter at a time so that the result can be linked to a specific limit. Then repeat the full set of required user actions.
If an essential workflow stops working, first establish which data it actually needs. Possible fixes include requesting fewer fields, retrieving lists in pages, or revisiting the cost assigned to a particular field. Treat raising the overall threshold as a separate decision that requires retesting. Keep the expected and actual results for every case, including whether the interface receives all the data it needs.
Set priorities and state the limits of testing
First, agree on essential workflows and server-side limits for depth, object count, and cost. Then test boundary cases and timeout settings; after that, assess the benefits of batching and caching. This sequence lets you test query acceptance rules first, before working on additional resource savings.
Successful testing confirms behavior only for the selected operations, data, and settings. It does not guarantee the security or stability of the entire API. Revisit the test suite when workflows change. If you need help reviewing limits and preserving essential user actions, you can start with a free audit of your website or the web component of your product.