Explain the difference between nullable and non-nullable fields in GraphQL

Beginner

Answer

In GraphQL, fields are nullable by default. The exclamation mark (!) makes a field non-nullable.

type User {
  id: ID!           # Required field
  name: String!     # Required field
  email: String     # Optional field (can be null)
  age: Int          # Optional field
  posts: [Post!]!   # Required array of required Posts
  tags: [String]    # Optional array of optional strings
}