# Non-Null - Hot Chocolate

> How Hot Chocolate maps C# nullable reference types to the GraphQL non-null modifier, with explicit overrides like [GraphQLNonNullType] and non-null list items.

Canonical source: https://chillicream.com/docs/hotchocolate/defining-a-schema/non-null

By default, every GraphQL field can return either its declared type or `null`. The non-null modifier (`!`) tells clients that a field will never be `null`. If a resolver returns `null` for a non-null field, the execution engine raises an error rather than sending unexpected null values to clients.

GraphQL

```
type User {
  name: String!
  bio: String
}
```

In this schema, `name` always has a value. The `bio` field may be `null`.

## Implicit Nullability from C# Types

Hot Chocolate infers nullability from your C# types. When [nullable reference types](https://docs.microsoft.com/dotnet/csharp/nullable-references) (NRT) are enabled in your project, the mapping is straightforward.

### Value Types

Value types are non-null by default. Use `?` to make them nullable.

| C# type | GraphQL type |
| ------- | ------------ |
| int     | Int!         |
| int?    | Int          |
| bool    | Boolean!     |
| bool?   | Boolean      |

### Reference Types (NRT Enabled)

With NRT enabled (recommended), non-nullable references map to non-null GraphQL types.

| C# type | GraphQL type |
| ------- | ------------ |
| string  | String!      |
| string? | String       |
| User    | User!        |
| User?   | User         |

### Reference Types (NRT Disabled)

Without NRT, all reference types are nullable by default. Hot Chocolate cannot distinguish `string` from `string?` because the compiler treats them identically.

| C# type | GraphQL type |
| ------- | ------------ |
| string  | String       |
| User    | User         |

We strongly recommend enabling NRT. It provides accurate schema nullability without extra attributes and catches null-related bugs at compile time.

## Enabling Nullable Reference Types

Add the following to your `.csproj` file to enable NRT across the project:

XML

```
<PropertyGroup>
    <Nullable>enable</Nullable>
</PropertyGroup>
```

You can also enable it per file with `#nullable enable` at the top of the file.

## Explicit Nullability

When you need to override the inferred nullability, use attributes or the descriptor API.

C#

```
public class Book
{
    [GraphQLNonNullType]
    public string Title { get; set; }

    public string? Author { get; set; }
}
```

`[GraphQLNonNullType]` forces the field to be non-null in the schema regardless of the C# nullability.

## Non-Null List Items

Lists have two layers of nullability: the list itself and its items. With NRT enabled:

| C# type        | GraphQL type |
| -------------- | ------------ |
| List<string>   | \[String!\]! |
| List<string>?  | \[String!\]  |
| List<string?>  | \[String\]!  |
| List<string?>? | \[String\]   |

To override nullability on list items explicitly:

C#

```
public class Book
{
    [GraphQLType(typeof(ListType<NonNullType<StringType>>))]
    public List<string> Genres { get; set; }
}
```

Both produce `genres: [String!]` in the schema.

## Next Steps

- **Need to define lists?** See [Lists](https://chillicream.com/docs/hotchocolate/defining-a-schema/lists).
- **Need to understand arguments?** See [Arguments](https://chillicream.com/docs/hotchocolate/defining-a-schema/arguments).
- **Need input types?** See [Input Object Types](https://chillicream.com/docs/hotchocolate/defining-a-schema/input-object-types).
- **Need to learn about scalars?** See [Scalars](https://chillicream.com/docs/hotchocolate/defining-a-schema/scalars).
[Edit this page on GitHub](https://github.com/ChilliCream/graphql-platform/edit/main/website/content/docs/hotchocolate/defining-a-schema/non-null.md)

Maintained by ChilliCream. Last updated on **June 30, 2026** by **Tobias Tengler**
