-
Notifications
You must be signed in to change notification settings - Fork 54
Use variables
Igor Dianov edited this page May 29, 2024
·
2 revisions
Using variables In order to make a query re-usable, it can be made dynamic by using variables.
Example: Fetch an author by their authors id:
query booksByAuthorId($authorId: Long!) {
Books(
where: { author: {id: {EQ: $authorId } } }
) {
select {
id
title
}
}
}
Variables:
{
"authorId": 1
}
Result:
{
"data": {
"Books": {
"select": [
{
"id": 2,
"title": "War and Peace"
},
{
"id": 3,
"title": "Anna Karenina"
}
]
}
}
}