Variables

Variables

GraphQL offers a way to reuse your queries dynamically through variables. These will come into play especially if you're accessing the API programmatically (such as our Node or Python examples).

Before:

Query (no variables)
Response
Query (no variables)
{
course(id: "00000000-5945-95c7-65fd-a9747b200317") {
id
title
flows {
title
}
}
}
Response
{
"data": {
"course": {
"id": "00000000-5945-95c7-65fd-a9747b200317",
"title": "History of Dunder-Mifflin",
"flows": [
{
"title": "Founding a Company"
},
{
"title": "Corporate Citizenship"
}
]
}
}
}

With variables:

Query (with variables)
Response
Query (with variables)
query($courseId: UUID!) {
course(id: $courseId) {
id
title
flows {
title
}
}
}
Response
{
"data": {
"course": {
"id": "00000000-5945-95c7-65fd-a9747b200317",
"title": "History of Dunder-Mifflin",
"flows": [
{
"title": "Founding A Company"
},
{
"title": "Corporate Citizenship"
}
]
}
}
}

Here's an example of what this would look like in the API Explorer:

GraphiQL allows variables to be passed on the bottom-left pane.

See also