Variables

Repeated queries can also be parameterised using variables. As an example below is a request which retrieves Tasks by a given priority.

query GetTasksByPriority($priority: TaskPriority!) {
  tasks(filter: {priority: $priority}) {
    edges {
      node {
        id
        name
        priority
      }
    }
  }
}

Notice that the $priority is passed as an argument to the query and is typed to a TaskPriority type which is an enum value one of HIGH, LOW, or NORMAL.

Variables are passed to the GraphQL endpoint along side query in the request as an extra body parameter.

> POST /v1/graphql HTTP/1.1
> Host: client-api.bipsync.com
> Content-Type: application/json
> Accept: */*
> Content-Length: 342

| {
|   "query": "query GetTasksByPriority($priority: TaskPriority!) {\n    tasks(filter: { priority: $priority }) {\n        edges {\n            node {\n                id\n                name\n                priority\n            }\n        }\n    }\n}",
|   "operationName": "GetTasksByPriority",
|   "variables": {
|     "priority": "HIGH"
|   }
| }