Skip to content

Commit f933d6c

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Improve missing fragment data error message to point to @alias docs.
Reviewed By: lynnshaoyu Differential Revision: D77629049 fbshipit-source-id: acf724710ceb0a1d9d3e0dfd028ca6dc26ede79d
1 parent 6314d78 commit f933d6c

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

packages/react-relay/relay-hooks/__tests__/FragmentResource-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ describe('FragmentResource', () => {
712712
componentDisplayName,
713713
),
714714
).toThrow(
715-
"Relay: Expected to receive an object where `...FragmentResourceTest1Fragment` was spread, but the fragment reference was not found`. This is most likely the result of:\n- Forgetting to spread `FragmentResourceTest1Fragment` in `TestComponent`'s parent's fragment.\n- Conditionally fetching `FragmentResourceTest1Fragment` but unconditionally passing a fragment reference prop to `TestComponent`. If the parent fragment only fetches the fragment conditionally - with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` spread - then the fragment reference will not exist. In this case, pass `null` if the conditions for evaluating the fragment are not met (e.g. if the `@include(if)` value is false.)",
715+
`Relay: Expected to receive an object where \`...FragmentResourceTest1Fragment\` was spread, but the fragment reference was not found\`.`,
716716
);
717717
});
718718
});

packages/react-relay/relay-hooks/legacy/FragmentResource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,15 @@ class FragmentResourceImpl {
340340
'to `%s`. If the parent fragment only fetches the fragment conditionally ' +
341341
'- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' +
342342
'spread - then the fragment reference will not exist. ' +
343-
'In this case, pass `null` if the conditions for evaluating the ' +
344-
'fragment are not met (e.g. if the `@include(if)` value is false.)',
343+
'This issue can generally be fixed by adding `@alias` after `...%s`.\n' +
344+
'See https://relay.dev/docs/next/guides/alias-directive/',
345345
fragmentNode.name,
346346
fragmentNode.name,
347347
componentDisplayName,
348348
fragmentNode.name,
349349
fragmentKey == null ? 'a fragment reference' : `the \`${fragmentKey}\``,
350350
componentDisplayName,
351+
fragmentNode.name,
351352
);
352353

353354
let fragmentResult = null;

packages/react-relay/relay-hooks/readFragmentInternal.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ function readFragmentInternal(
198198
'to `%s`. If the parent fragment only fetches the fragment conditionally ' +
199199
'- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' +
200200
'spread - then the fragment reference will not exist. ' +
201-
'In this case, pass `null` if the conditions for evaluating the ' +
202-
'fragment are not met (e.g. if the `@include(if)` value is false.)',
201+
'This issue can generally be fixed by adding `@alias` after `...%s`.\n' +
202+
'See https://relay.dev/docs/next/guides/alias-directive/',
203203
fragmentNode.name,
204204
fragmentNode.name,
205205
hookDisplayName,
206206
fragmentNode.name,
207207
fragmentKey == null ? 'a fragment reference' : `the \`${fragmentKey}\``,
208208
hookDisplayName,
209+
fragmentNode.name,
209210
);
210211

211212
const state = getFragmentState(environment, fragmentSelector);

packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,14 @@ hook useFragmentInternal(
400400
'to `%s`. If the parent fragment only fetches the fragment conditionally ' +
401401
'- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' +
402402
'spread - then the fragment reference will not exist. ' +
403-
'In this case, pass `null` if the conditions for evaluating the ' +
404-
'fragment are not met (e.g. if the `@include(if)` value is false.)',
403+
'This issue can generally be fixed by adding `@alias` after `...%s`.\n' +
404+
'See https://relay.dev/docs/next/guides/alias-directive/',
405405
fragmentNode.name,
406406
fragmentNode.name,
407407
hookDisplayName,
408408
fragmentNode.name,
409409
hookDisplayName,
410+
fragmentNode.name,
410411
);
411412

412413
const environment = useRelayEnvironment();

packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ hook useFragmentInternal_EXPERIMENTAL(
436436
'- Conditionally fetching `%s` but unconditionally passing %s prop ' +
437437
'to `%s`. If the parent fragment only fetches the fragment conditionally ' +
438438
'- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' +
439-
'spread - then the fragment reference will not exist. ' +
440-
'In this case, pass `null` if the conditions for evaluating the ' +
441-
'fragment are not met (e.g. if the `@include(if)` value is false.)',
439+
'spread - then the fragment reference will not exist. ' +
440+
'This issue can generally be fixed by adding `@alias` after `...%s`.\n' +
441+
'See https://relay.dev/docs/next/guides/alias-directive/',
442442
fragmentNode.name,
443443
fragmentNode.name,
444444
hookDisplayName,

0 commit comments

Comments
 (0)