Skip to content

GraphQL

Scope: designing, securing and running GraphQL APIs, whatever the server language. The general rules in API design also apply, in particular backward compatibility (API-2) and designing the contract first (API-4), as do Security (SEC-1 on authorization) and Authentication. For TypeScript servers, see also TypeScript and Node.js.

Entries are sorted by score from 1 to 10 (criteria): 9–10 start here or strongly recommended, 6–8 recommended, 1–5 further reading or conditional.

Adopted references

  • 10 Learn GraphQL (GraphQL Foundation): the baseline: the core concepts, then the Best Practices lessons on thinking in graphs, serving over HTTP, authorization, pagination, schema design, error handling, performance, security, federation and schema governance.
  • 9 GraphQL Specification (September 2025 edition): the language, type system, validation and execution rules that every GraphQL server implements.
  • 8 GraphQL Cheat Sheet (OWASP): the baseline for security: input validation, denial of service, access control, batching attacks and insecure default configurations.
  • 7 GraphQL over HTTP (GraphQL Foundation, working draft): how to serve and call GraphQL over HTTP: URLs, GET and POST, media types, status codes, and security notes.
  • 7 GraphQL Cursor Connections Specification (Relay): the standard shape for cursor-paginated lists: connections, edges, pageInfo and the first, after, last and before arguments.

Key rules

Schema design

  • 8 GQL-1 Evolve the schema without versions: add fields and types, mark what you plan to remove with @deprecated(reason: …) naming the replacement, and remove it only after usage tracking shows that clients have migrated, or the announced deadline has passed. Removing or renaming fields, changing their types, making arguments required, or making a non-null field nullable breaks clients (API-2). (GraphQL, Schema change management, Schema design: Versioning, GraphQL spec, @deprecated)
  • 8 GQL-2 Change data only in mutations: keep query fields free of side effects, and don't execute a mutation sent with GET. The specification requires every field except top-level mutation fields to be free of side effects, and GraphQL over HTTP forbids mutations over GET. (GraphQL spec, Normal and serial execution, GraphQL over HTTP, GET)
  • 7 GQL-3 Design the schema around the business domain and the way clients use the data, not around the database tables behind it. Agree on review criteria, such as naming, nullability and compatibility, and review every schema change against them, as API-4 asks for any API contract. (GraphQL, Thinking in graphs, Review and validate schema changes)
  • 7 GQL-4 Paginate every list field that can grow, with cursor-based connections that follow the Relay connection specification, and cap the page size. Opaque cursors let you change how the backend paginates later, and unbounded lists let one request fetch huge amounts of data. (GraphQL, Pagination, Relay, Cursor Connections Specification, OWASP, Query limiting)
  • 6 GQL-5 Choose nullability field by field: keep a field nullable if it can fail or be denied on its own, make it non-null only where clients need the guarantee, and return lists as [Item!]!. When a non-null field fails, the null spreads to its nearest nullable parent, and making a non-null field nullable later is a breaking change. (GraphQL, Schema design: Nullability, Naming conventions: nullability patterns, Schema change management: breaking changes)
  • 6 GQL-6 Return expected business errors, such as failed validation or a broken business rule, as typed results in the mutation's payload type, and keep the top-level errors array for unexpected failures. Errors in the schema are typed and discoverable, and a payload type can gain fields without breaking clients. (GraphQL, Error handling, Naming conventions: payload types)

Security

Performance and architecture

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 6 GraphQL Inspector diff: compares the schema in a pull request with the current one, sorts the changes into breaking, dangerous and safe, and fails when any change is breaking. Removing a deprecated field counts as breaking unless you turn on suppressRemovalOfDeprecatedField, and considerUsage checks breaking changes against real usage. Checks GQL-1.
  • 6 GraphQL ESLint: lints schema and operation files in CI and the editor. relay-connection-types, relay-arguments and relay-page-info check that connections follow the Relay specification. require-deprecation-reason (in schema-recommended) and require-deprecation-date check deprecations, and no-deprecated (in operations-recommended) flags client operations that still use deprecated fields. Partly checks GQL-1 and GQL-4.

Tutorials and further reading

  • 6 Tutorial: Designing a GraphQL API (Shopify): designs a schema step by step from a real domain, covering IDs, pagination, business logic and mutations.
  • 5 Production Ready GraphQL (Marc-André Giroux, 2020): a book on schema design, performance, security, tooling and architecture for GraphQL APIs at scale.