Definition

GraphQL is a strongly-typed query language and runtime for APIs that allows clients to specify the exact shape of the data they require.


Core Principle

GraphQL shifts control of data fetching from the server to the client.

Instead of the server defining fixed responses (as in REST), the client defines:


Execution Model

A GraphQL request is executed against a schema on the server:

  1. Query is parsed into an AST
  2. Validated against the schema
  3. Resolved field-by-field via resolvers
  4. Response is constructed matching the query shape

Example

query {
  user {
    id
    name
  }
}

Response

{
  "data": {
    "user": {
      "id": "1",
      "name": "Zeeshan"
    }
  }
}