Query variables are used to pass dynamic values into a GraphQL query instead of hardcoding them.
Variables allow queries to be reusable and parameterized.
They are defined separately from the query body and injected at execution time.
query GetUser($id: ID!) {
user(id: $id) {
id
name
}
}
$id → variableID! → type (non-nullable)user(id: $id) → variable passed as argumentVariables are sent separately from the query.
{
"id": "1"
}
{
"query": "query GetUser($id: ID!) { user(id: $id) { id name } }",
"variables": {
"id": "1"
}
}