Definition

Query variables are used to pass dynamic values into a GraphQL query instead of hardcoding them.


Core Concept

Variables allow queries to be reusable and parameterized.

They are defined separately from the query body and injected at execution time.


Syntax

query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
  }
}

Providing Variable Values

Variables are sent separately from the query.

{
  "id": "1"
}

Full Request Structure

{
  "query": "query GetUser($id: ID!) { user(id: $id) { id name } }",
  "variables": {
    "id": "1"
  }
}