Skip to content

Use semantic nullability with @throwOnFieldError and @catch#346

Merged
captbaritone merged 1 commit into
relayjs:todo-upgrade-basefrom
captbaritone:todo-upgrade
May 22, 2026
Merged

Use semantic nullability with @throwOnFieldError and @catch#346
captbaritone merged 1 commit into
relayjs:todo-upgrade-basefrom
captbaritone:todo-upgrade

Conversation

@captbaritone

Copy link
Copy Markdown
Contributor

Summary

  • Enable Grats' strictSemanticNullability + nullableByDefault to replace @killsParentOnException with @semanticNonNull for non-spec fields
  • Keep @killsParentOnException on the 5 spec-required fields: Node.id, PageInfo.hasNextPage/hasPreviousPage, Edge.cursor, Connection.pageInfo
  • Add @throwOnFieldError to all client queries and fragments so Relay generates non-null types for @semanticNonNull fields
  • Add per-todo ErrorBoundary so a field error only takes down the affected todo item, not the entire app

Why

@killsParentOnException makes fields ! in the schema, but if a resolver throws, the error propagates up and nulls out the nearest nullable ancestor — potentially taking down large portions of the response. Semantic nullability decouples error handling from nullability: fields stay nullable in the schema (with @semanticNonNull annotation), and clients that handle errors out-of-band (via @throwOnFieldError) get non-null types with explicit error handling.

Test plan

  • npx grats regenerates schema with @semanticNonNull directives on non-spec fields, spec fields remain !
  • yarn relay compiles successfully
  • npx tsc --noEmit passes with no type errors

Replace @killsParentOnException with @semanticNonNull for non-spec
fields by enabling Grats' strictSemanticNullability. Spec-required
non-null fields (Node.id, PageInfo.hasNextPage/hasPreviousPage,
Edge.cursor, Connection.pageInfo) keep @killsParentOnException.

On the client side, add @throwOnFieldError to all queries and fragments
so Relay generates non-null types for @semanticNonNull fields, and
@catch on mutations since @throwOnFieldError doesn't support mutation
definitions.

Add per-todo ErrorBoundary so field errors only take down the affected
todo item rather than the entire app.
@meta-cla meta-cla Bot added the CLA Signed label May 22, 2026
@captbaritone captbaritone marked this pull request as ready for review May 22, 2026 18:07
@captbaritone captbaritone merged commit e4a1965 into relayjs:todo-upgrade-base May 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant