-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for @catch on fragments/queries/mutations and aliased inl…
…ine fragments (#4838) Summary: `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. Pull Request resolved: #4838 Reviewed By: itamark Differential Revision: D65432323 Pulled By: captbaritone fbshipit-source-id: 7fd1313e6d1ae0bda2d6354ef931f10fcfa72e9e
- Loading branch information
1 parent
1306086
commit 7c9aebb
Showing
78 changed files
with
3,124 additions
and
600 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
48 changes: 48 additions & 0 deletions
48
...n/tests/catch_directive_codegen/fixtures/catch_directive_aliased_inline_fragment.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
==================================== INPUT ==================================== | ||
fragment MyFragment on Node { | ||
id | ||
... on User @catch(to: RESULT) @alias { | ||
name | ||
} | ||
} | ||
==================================== OUTPUT =================================== | ||
{ | ||
"argumentDefinitions": [], | ||
"kind": "Fragment", | ||
"metadata": null, | ||
"name": "MyFragment", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "id", | ||
"storageKey": null | ||
}, | ||
{ | ||
"kind": "CatchField", | ||
"field": { | ||
"fragment": { | ||
"kind": "InlineFragment", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "name", | ||
"storageKey": null | ||
} | ||
], | ||
"type": "User", | ||
"abstractKey": null | ||
}, | ||
"kind": "AliasedInlineFragmentSpread", | ||
"name": "User" | ||
}, | ||
"to": "RESULT", | ||
"path": "User" | ||
} | ||
], | ||
"type": "Node", | ||
"abstractKey": "__isNode" | ||
} |
6 changes: 6 additions & 0 deletions
6
...en/tests/catch_directive_codegen/fixtures/catch_directive_aliased_inline_fragment.graphql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment MyFragment on Node { | ||
id | ||
... on User @catch(to: RESULT) @alias { | ||
name | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
..._directive_codegen/fixtures/catch_directive_aliased_inline_fragment_no_condition.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
==================================== INPUT ==================================== | ||
fragment MyFragment on Node { | ||
id | ||
... @catch(to: RESULT) @alias(as: "myAlias") { | ||
name | ||
} | ||
} | ||
==================================== OUTPUT =================================== | ||
{ | ||
"argumentDefinitions": [], | ||
"kind": "Fragment", | ||
"metadata": null, | ||
"name": "MyFragment", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "id", | ||
"storageKey": null | ||
}, | ||
{ | ||
"kind": "CatchField", | ||
"field": { | ||
"fragment": { | ||
"kind": "InlineFragment", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "name", | ||
"storageKey": null | ||
} | ||
], | ||
"type": null, | ||
"abstractKey": null | ||
}, | ||
"kind": "AliasedInlineFragmentSpread", | ||
"name": "myAlias" | ||
}, | ||
"to": "RESULT", | ||
"path": "myAlias" | ||
} | ||
], | ||
"type": "Node", | ||
"abstractKey": "__isNode" | ||
} |
6 changes: 6 additions & 0 deletions
6
...h_directive_codegen/fixtures/catch_directive_aliased_inline_fragment_no_condition.graphql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment MyFragment on Node { | ||
id | ||
... @catch(to: RESULT) @alias(as: "myAlias") { | ||
name | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...es/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_fragment.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
==================================== INPUT ==================================== | ||
fragment MyFragment on Node @catch(to: RESULT) { | ||
id | ||
name | ||
} | ||
==================================== OUTPUT =================================== | ||
{ | ||
"argumentDefinitions": [], | ||
"kind": "Fragment", | ||
"metadata": { | ||
"catchTo": "RESULT" | ||
}, | ||
"name": "MyFragment", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "id", | ||
"storageKey": null | ||
}, | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "name", | ||
"storageKey": null | ||
} | ||
], | ||
"type": "Node", | ||
"abstractKey": "__isNode" | ||
} |
4 changes: 4 additions & 0 deletions
4
...tes/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_fragment.graphql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fragment MyFragment on Node @catch(to: RESULT) { | ||
id | ||
name | ||
} |
This file contains 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
Oops, something went wrong.