Schema validation and resource limits
Validate shape and meaning
A schema describes the permitted shape of data: fields, required values, types and bounds. An order-list request might accept an integer limit between 1 and 20 and an optional cursor. Reject unexpected fields if the contract requires a closed object. Schema validity is only the first step: the server must also verify business rules, such as whether a cursor belongs to the current authorized query.
Bound the work
Rate limits restrict request frequency over a defined period; concurrency limits restrict simultaneous work. A separate body-size limit, execution deadline, page-size maximum and downstream spending quota may be needed. One accepted request can still be costly. GraphQL may need limits on depth, breadth, batch size or estimated complexity. Pick bounds from measured legitimate needs and capacity, not arbitrary universal numbers.
Example: a bounded list contract
In this offline model, limit=1 and limit=20 are valid; limit=0, limit=21 and limit="10" are invalid (the contract requires a JSON integer). The first 30 requests per minute may proceed to other checks; later requests receive a rate-limit response such as HTTP 429. This is a fictional single-client fixed-window policy. Real distributed enforcement, retry guidance and resource accounting require separate tests.
Common mistakes
Client-side validation is useful feedback, not enforcement. A page cap does not cap total work across all pages. A per-client quota alone may not protect an expensive shared dependency. Do not silently coerce invalid values unless documented, or expose unbounded default lists. Apply quotas to sensitive business actions as well as generic request traffic; coordinate legitimate retries and avoid duplicate side effects.
Practice: boundaries
For a report API accepting page size 1–50, propose tests for the lower and upper bounds, missing input, incorrect type and the first request above a quota. Distinguish invalid data from a valid request rejected due to capacity. No load generation is necessary.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Schema validation and resource limits — knowledge check
Apply API security principles to fictional scenarios.
The list contract requires an integer from 1 to 20. Which value passes?
What does a concurrency limit bound?
Why can one accepted GraphQL request still be expensive?
The fictional 30-request quota is exhausted. What response is appropriate?
What remains to check after schema validation succeeds?