GraphQL – Graph Query Language
GraphQL – Graph Query Language
GraphQL is a modern query language for APIs and a runtime for executing those queries. Created to let clients request exactly the data they need, GraphQL makes APIs more efficient, predictable, and easy to evolve.
What is a GraphQL API?
A GraphQL API exposes a single endpoint that accepts queries describing what data the client needs. Instead of multiple REST endpoints returning fixed payloads, a GraphQL API returns precisely shaped responses based on the client’s query.
- Query: A read operation where the client selects fields it needs.
- Mutation: An operation that changes server-side data (create, update, delete).
- Single endpoint: All requests go to one endpoint (e.g.,
/graphql
). - Strong typing: The API is defined by a schema that describes available types and fields.
GraphQL Schema
The schema is the contract between client and server. It declares types, fields, and the operations clients may perform. Types are strongly typed and documented, which enables tooling like auto-completion and validation.
Core schema concepts:
- Object types: Named collections of fields (e.g.,
User
,Post
). - Scalar types: Primitive values such as
String
,Int
,Boolean
. - Query type: The root type for read operations.
- Mutation type: The root type for write operations (optional).
- Resolvers: Functions on the server that produce the data for each field.