Skip to content

Use semantic nullability with @throwOnFieldError and @catch#344

Closed
captbaritone wants to merge 3 commits into
relayjs:mainfrom
captbaritone:todo-upgrade
Closed

Use semantic nullability with @throwOnFieldError and @catch#344
captbaritone wants to merge 3 commits into
relayjs:mainfrom
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 @catch to all mutations (since @throwOnFieldError doesn't support mutation definitions) to preserve non-null typing via Result wrapper
  • 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 / @catch) 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

Modernize the newsfeed example app:
- Webpack + Babel → Vite
- Raw http server + hand-written graphql-js → GraphQL Yoga + Grats
- graphql v17-alpha → v16 stable
- React 18 → React 19
- TypeScript 4.9 → 5.7
- ESLint legacy config → flat config (v9)
- Remove DefinitelyTyped Relay shims (v21 ships its own types)
- Remove GraphiQL custom playground (Yoga has built-in)
- Remove future/ directory (broken tutorial stubs)
- Remove committed dist/ artifacts
- Add CI steps for newsfeed
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
Without a lockfile, yarn resolves ^0.0.0-main-4dcb3ffa to the stable
v21 release which doesn't ship TypeScript types. Pin the exact version.
@captbaritone

Copy link
Copy Markdown
Contributor Author

Recreating with correct base branch

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