GraphQL supports query documents that declare variables that can be accepted to fill-in values. This is a useful mechanism for reusing GraphQL documents – instead of attempting to interpolate values yourself.

To support variables, simply define them for your query document as the specification expects, and pass in a variables option to

If you're using Absinthe.Plug, variables are passed in for you automatically after being parsed from the query parameters or POST body.

query GetItem($id: ID!) {
  item(id: $id) {
|>, variables: %{"id" => "bar"})

# Result
{:ok, %{data: %{"item" => %{"name" => "Bar"}}}}
Providing the id variable to a query document.