Use semantic nullability with @throwOnFieldError and @catch#344
Closed
captbaritone wants to merge 3 commits into
Closed
Use semantic nullability with @throwOnFieldError and @catch#344captbaritone wants to merge 3 commits into
captbaritone wants to merge 3 commits into
Conversation
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.
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.
Contributor
Author
|
Recreating with correct base branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
strictSemanticNullability+nullableByDefaultto replace@killsParentOnExceptionwith@semanticNonNullfor non-spec fields@killsParentOnExceptionon the 5 spec-required fields:Node.id,PageInfo.hasNextPage/hasPreviousPage,Edge.cursor,Connection.pageInfo@throwOnFieldErrorto all client queries and fragments so Relay generates non-null types for@semanticNonNullfields@catchto all mutations (since@throwOnFieldErrordoesn't support mutation definitions) to preserve non-null typing viaResultwrapperErrorBoundaryso a field error only takes down the affected todo item, not the entire appWhy
@killsParentOnExceptionmakes 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@semanticNonNullannotation), and clients that handle errors out-of-band (via@throwOnFieldError/@catch) get non-null types with explicit error handling.Test plan
npx gratsregenerates schema with@semanticNonNulldirectives on non-spec fields, spec fields remain!yarn relaycompiles successfullynpx tsc --noEmitpasses with no type errors