# Nullability in GraphQL and Apollo Kotlin

DevFeed: [Nullability in GraphQL and Apollo Kotlin](<https://devfeed.tech/articles/nullability-in-graphql-and-apollo-kotlin-23471.md>)

Original publisher: [Read original article](<https://www.apollographql.com/blog/nullability-in-graphql-and-apollo-kotlin>)

Author: Benoit Lubek

Published: 2023-02-27T08:10:00Z

Content type: article

Language: en

Sources: [Apollo Blog](<https://devfeed.tech/sources/apollo-blog.md>)

Topics: [Null-Safety](<https://devfeed.tech/topics/null-safety.md>), [GraphQL](<https://devfeed.tech/topics/graphql.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [apollo](<https://devfeed.tech/tags/apollo.md>), [client](<https://devfeed.tech/tags/client.md>), [client-library](<https://devfeed.tech/tags/client-library.md>), [codegen](<https://devfeed.tech/tags/codegen.md>), [compile](<https://devfeed.tech/tags/compile.md>), [directives](<https://devfeed.tech/tags/directives.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [errors](<https://devfeed.tech/tags/errors.md>), [field](<https://devfeed.tech/tags/field.md>), [fields](<https://devfeed.tech/tags/fields.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [graphql](<https://devfeed.tech/tags/graphql.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mobile](<https://devfeed.tech/tags/mobile.md>), [models](<https://devfeed.tech/tags/models.md>), [null](<https://devfeed.tech/tags/null.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [nulls](<https://devfeed.tech/tags/nulls.md>), [type-system](<https://devfeed.tech/tags/type-system.md>)

## AI overview

Apollo Kotlin generates Kotlin models from GraphQL operations and schema types: schema-nullable fields become nullable in the model. Fields controlled by `@include` or `@skip` are nullable even when their schema type is non-null, because they may be omitted from a response. Fragment fields can also be nullable when polymorphism means they may not be returned; the generator can infer a fragment is always applicable in some cases and generate its fields as non-null. The excerpt explains that GraphQL errors can produce partial responses: an unresolved nullable field becomes null, while an unresolved non-null field can make its parent null if possible. It also notes that GraphQL defaults fields to nullable, unlike Kotlin, where types are non-null by default.

## Source excerpt

The concept of is sometimes called a "billion dollar mistake". Mistake or not, is here to stay and there are ways to coexist peacefully! In fact, nullability is one of the key features of GraphQL, allowing API authors to clearly specify which fields of a type are nullable. As for Kotlin, the language supports nullability in its type system, significantly reducing the risk for errors - for example assigning a potentially value to a non-nullable field won't even compile!