Q6 of 20 · GraphQL

How do schema types and nullability affect what you test?

GraphQLMidgraphqlschematest-designapi

Short answer

Short answer: The schema declares each field's type and whether it's nullable (`String`) or non-null (`String!`). Non-null fields that return null are an error condition worth testing, and omitting a non-null variable should be rejected before execution.

Detail

Every field and argument in a GraphQL schema has a type, and a trailing ! marks it non-null (required).

type User {
  id: ID!          # always present
  name: String!    # always present
  email: String    # may be null
}
query GetUser($id: ID!) { ... }   # $id is required

What this gives you to test:

  • Non-null violations: if a String! field resolves to null, GraphQL must surface an error (and, by spec, nulls can propagate up to the nearest nullable parent). That propagation behaviour is a real, testable edge case.
  • Required variables: omitting $id on a $id: ID! operation is a validation error — a cheap, high-value negative test.
  • Default values: $limit: Int = 10 should apply the default when the variable is omitted; test both the supplied and omitted paths.

Nullability is where GraphQL's "it's just JSON" black-box testers fall down — the schema is a contract with rules you can assert against.

// WHAT INTERVIEWERS LOOK FOR

Understanding non-null vs nullable, null propagation, and treating required-variable omission as a deliberate negative test.

// COMMON PITFALL

Ignoring the schema entirely and testing GraphQL as untyped JSON, missing nullability rules.