s3rvac
s3rvac

Reputation: 10319

What is the meaning of exclamation marks with respect to lists in GraphQL?

What is the difference between the following type definitions in GraphQL?

  1. [Item]
  2. [Item!]
  3. [Item]!
  4. [Item!]!

In which cases can the list be empty?

Upvotes: 2

Views: 203

Answers (1)

s3rvac
s3rvac

Reputation: 10319

  1. [Item] means that both the list itself as well as its items can be null.
  2. [Item!] means that the list cannot contain null items, but the list itself can be null.
  3. [Item]! means that the list can contain null items, but the list itself cannot be null.
  4. [Item!]! means that both the list itself as well as its items cannot be null.

In all four cases, the list can be empty.

Upvotes: 6

Related Questions