GraphQL

GraphQL replaces many resource URLs with one endpoint and a typed schema. The client sends a query describing the shape of the data it needs — this user, their last three orders, each order's total — and receives exactly that shape back. Writes are mutations, sent the same way.

How it works

The server validates each query against its schema before running it, then resolves each field, possibly from different data sources. Requests are usually POSTs with the query in a JSON body. Errors are reported in an errors array alongside whatever data could be resolved, typically with a 200 status for the HTTP request as a whole.

The misconception

That GraphQL replaces HTTP status codes. Because a partially failed query still returns 200, a client that checks only the status will miss field-level errors entirely; the errors array has to be inspected on every response. The same flexibility also means a single query can be very expensive, which is why production servers limit depth and complexity.

Try it here

POST https://funapi.dev/graphql runs queries and mutations over the Friends characters, with a GraphiQL explorer at the same URL; the Friends API docs page also runs it as POST /graphql in the Try it out panel.

Sources

Other terms

All glossary terms · Testing techniques · All 39 mock REST APIs

Last updated