--- title: Using args description: Guide for defining field args in Pothos --- Arguments let a client pass values to a field's resolver. They work on query, mutation, object, and interface fields. Define them in a field's `args` option and read them from the resolver's second parameter. ## Scalars ### Using the `t.arg` method Use `t.arg` with a scalar type name: playground-examples/foundations-arguments/schema.ts#greeting ### Using convenience methods The equivalent shorthand for the argument above is `t.arg.string({ required: true })`. Other scalar helpers include `t.arg.id`, `t.arg.int`, `t.arg.float`, and `t.arg.boolean`. Each also has a list helper, such as `t.arg.stringList`. ## Required args Arguments are optional by default. Set `required: true` to reject omitted or `null` values. See [Changing Default Nullability](./changing-default-nullability) to change this default. An optional argument can be omitted or explicitly set to `null`. A `defaultValue` applies when an argument is omitted; it does not replace an explicit `null`. The resolver below handles both: playground-examples/foundations-arguments/schema.ts#defaults ## Lists Wrap a type in an array to create a list argument, or use a list helper: playground-examples/foundations-arguments/schema.ts#lists List items are non-null by default, even when the list argument is optional. Use separate `list` and `items` settings to allow null entries in a required list: playground-examples/foundations-arguments/schema.ts#nullable-items ## Other types Arguments can also use [enums](./enums) and [input objects](./inputs). Output objects, interfaces, and unions cannot be argument types. This object field accepts an enum argument to choose the unit for its result: playground-examples/foundations-arguments/schema.ts#enum ## Nested Lists Use `t.arg.listRef` to nest lists. Its `required` option controls the items of that list; `required` on `t.arg` controls whether the outermost list can be omitted or null. playground-examples/foundations-arguments/schema.ts#nested-lists Here, `groups` has GraphQL type `[[String]!]!`: the outer list and each inner list are required, but strings inside the inner lists can be null. Without `{ required: false }`, those strings would also be non-null. ## Querying with arguments The examples above form one schema. This query exercises required arguments, defaults, lists, and the enum argument on an object field: playground-examples/foundations-arguments/Arguments.graphql ```json { "data": { "greeting": "Hello, Gina!", "repeat": "haha", "once": "ha", "knownGiraffes": ["Gina", "James"], "nonNullNames": ["Gina", "James"], "giraffe": { "meters": 5, "feet": 16.405 }, "countNames": 2 } } ```