--- title: Fields description: Guide for defining fields in Pothos --- Fields for [Object](./objects) and [Interface](./interfaces) types are defined using a shape function. This is a function that takes a [FieldBuilder](../api/field-builder) as an argument, and returns an object whose keys are field names, and whose values are fields created by the [FieldBuilder](../api/field-builder). These examples will mostly add fields to the `Query` type, but the topics covered in this guide should apply to any object or interface type. ## Scalars Scalar fields can be defined a couple of different ways: ### Field method playground-examples/foundations-field-scalars/schema.ts#field-method ### Convenience methods Convenience methods are just wrappers around the `field` method that omit the `type` option. playground-examples/foundations-field-scalars/schema.ts#convenience-methods Each Playground action opens a complete schema. In the scalar example, `queryFields` adds convenience fields to the `Query` type already defined with `queryType`. ## Other types Fields for non-scalar fields can also be created with the `field` method. Some types like [Objects](./objects) and [Interfaces](./interfaces) can be referenced by name if they have a backing model defined in the schema builder. playground-examples/foundations-field-types/schema.ts#model,object-query For types not described in the `SchemaTypes` type provided to the builder, including types that can not be added there like [Unions](./unions) and [Enums](./enums), you can use a `Ref` returned by the builder method that created them in the `type` parameter. For types created using a class \([Objects](./objects) or [Interfaces](./interfaces)\) or [Enums](./enums) created using a typescript enum, you can also use the `class` or `enum` that was used to define them. Here we add an enum field to the `Giraffe` type defined above: playground-examples/foundations-field-types/schema.ts#enum ## Lists To create a list field, you can wrap the type in an array playground-examples/foundations-field-types/schema.ts#lists ## NonNullable fields Fields in Pothos are nullable by default, but fields can be made NonNullable by setting the `nullable` option to `false`. This default can also be changed in the SchemaBuilder constructor, see [Changing Default Nullability](./changing-default-nullability) for more details. playground-examples/foundations-field-nullability/schema.ts#fields Note that by default even if a list field is nullable, the items in that list are not. The last example above shows how you can make list items nullable. ## Exposing fields from the underlying data Some GraphQL implementations have a concept of "default resolvers" that can automatically resolve fields that have a property of the same name in the underlying data. In Pothos, these relationships need to be explicitly defined, but there are helper methods that make exposing fields easier. These helpers are not available for root types \(Query, Mutation and Subscription\), but will work on any other object type or interface. playground-examples/foundations-field-types/schema.ts#model The available expose helpers are: - `exposeString` - `exposeInt` - `exposeFloat` - `exposeBoolean` - `exposeID` - `exposeStringList` - `exposeIntList` - `exposeFloatList` - `exposeBooleanList` - `exposeIDList` ## Arguments Arguments for a field can be defined in the options for a field: playground-examples/foundations-field-types/schema.ts#argument For more information see the [Arguments Guide](./args). ## Adding fields to existing type In addition to being able to define fields when defining types, you can also add additional fields independently. This is useful for breaking up types with a lot of fields into multiple files, or co-locating fields with their type \(e.g., add all query/mutation fields for a type in the same file where the type is defined\). playground-examples/foundations-field-types/schema.ts#additional-fields To see all the methods available for defining fields see the [SchemaBuilder API](../api/schema-builder) The example adds `newestGiraffe` separately from the original `giraffe` field. Query `newestGiraffe { name nameLength }` to see both the added root field and the computed object field. ## Nested Lists You can use `t.listRef` to create a list of lists playground-examples/foundations-field-nested-lists/schema.ts#fields