Using args
Similar to the Fields Guide, the examples here will mostly be for the Query type, but the same patterns can be used anywhere that arguments for fields can be defined, including both Object and Interface types.
Scalars
Scalar args can be defined a couple of different ways
Using the t.arg
method
Using convenience methods
Other types
Args of non-scalar types can also be created with the t.arg
method.
Valid arg types include Scalars
, Enums
, and Input
types.
Required args
Arguments are optional by default, but can be made required by passing required: true
in the
argument options. This default can be changed in the SchemaBuilder constructor, see
Changing Default Nullability.
Note that by default even if a list arg is optional, the items in that list are not. The last argument in the example above shows how you can make list items optional.
Lists
To create a list argument, you can wrap the type in an array or use one of the helpers
Nested Lists
You can use t.arg.listRef
to create a list of lists