Creates a unique GraphQL variable, that can be used multiple times.


Create a new variable, and use it as an argument:

import { Variable } from 'gqless'
const limit = new Variable(10)
const users = query.users({ limit }) // => Array[10]
// Update the variable, triggering a re-fetch
users // => Array[15]

Generated query

query($usersLimit: Int) {
users(limit: $usersLimit)


By default, options are auto-inferred based upon first-usage.

Explicitly defining can be useful to prevent mistakes:

import { schema, Variable } from 'gqless'
const limit = new Variable(5, {
node: schema.Int,
nullable: false,
name: 'example',
query.users({ limit })

Generated query

query($example: Int!) {
users(limit: $example)
Last updated on by Sam Denty