Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @catch on fragments/queries/mutations and aliased inline fragments #4838

Closed
wants to merge 1 commit into from

Conversation

captbaritone
Copy link
Contributor

@catch was originally conceived as a means for handling field errors, so we built it as a directive on fields. However, as the design evolved we opted to make it additionally catch any errors nested within it. With this newer approach, there’s no reason to limit @catch to just fields. Any GraphQL construct which gets read as a concrete value should be able to operate as a @catch boundary.

This PR adds support for marking fields/queries/mutations and aliased fragments as @catch boundaries. This means:

  1. Their value will be read out as either nullable or a Result type
  2. @semanticNonNull values nested within the fragment/operation/mutation/aliased fragment will be typed using their semantic type (non-nullable)

One particularly nice thing this enables is that it allows @catch to act as a non-destructive alternative to @throwOnFieldError.

Additional Bug Fixes

Along the way I noticed and fixed a few bugs:

  1. Semantic nullability was not respected within inline fragments nested within @catch or @throwOnFieldError
  2. Errors that bubbled up to a @catch(to: NULL) directive would not actually cause the value to become null.

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@captbaritone merged this pull request in 7c9aebb.

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.

2 participants