Skip to content

Warn when nullable input field maps to non-nullable output field in GraphQL schema #1740

@velo

Description

@velo

Summary

Issue a compiler warning when a nullable field in the input type is mapped to a non-nullable field in the output/API type. This helps catch potential NullValueInNonNullableField errors at compile time.

Background

In DataSQRL/cloud-backend#224, we encountered a GraphQL error where a field (scheduleDurationMin) was declared as Int! (non-nullable) in the output type, but the corresponding input type allowed it to be optional (Int). This caused runtime errors when null values were stored and later queried.

{
  "message": "The field at path '/deploymentsLookup/runtime/scheduleDurationMin' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value.",
  "extensions": { "classification": "NullValueInNonNullableField" }
}

See detailed explanation: https://github.com/DataSQRL/cloud-backend/pull/224#issuecomment-3609420925

Proposed Behavior

When compiling, if the compiler detects that:

  • An output/API field is declared as non-nullable (e.g., Int!)
  • The corresponding source field (from input table or computed column) is nullable

Then issue a warning (not an error) to alert the developer of a potential null value issue.

Why Warning and Not Error

As noted by @henneberger: SQL nullability determination can be off in certain cases, and enforcing this strictly would be frustrating when the determination isn't accurate. A warning gives developers visibility while allowing them to proceed when they know better.

Example

# Input type - nullable field
input BackendDeploymentRuntimeConfigInput {
  scheduleDurationMin: Int  # nullable
}

# Output type - non-nullable field  
type DeploymentRuntime {
  scheduleDurationMin: Int!  # non-nullable - WARN: source field is nullable
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions