react-relay 11.0.1 → 13.0.0-rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayContext.js.flow +2 -3
  3. package/ReactRelayFragmentContainer.js.flow +24 -24
  4. package/ReactRelayFragmentMockRenderer.js.flow +1 -1
  5. package/ReactRelayLocalQueryRenderer.js.flow +6 -7
  6. package/ReactRelayPaginationContainer.js.flow +111 -58
  7. package/ReactRelayQueryFetcher.js.flow +9 -10
  8. package/ReactRelayQueryRenderer.js.flow +115 -81
  9. package/ReactRelayRefetchContainer.js.flow +41 -38
  10. package/ReactRelayTestMocker.js.flow +16 -14
  11. package/ReactRelayTypes.js.flow +10 -10
  12. package/RelayContext.js.flow +3 -3
  13. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +1 -2
  14. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +11 -7
  15. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +10 -6
  16. package/__flowtests__/RelayModern-flowtest.js.flow +78 -46
  17. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +5 -4
  18. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +5 -4
  19. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +4 -3
  20. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +4 -3
  21. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
  22. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
  23. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
  24. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
  25. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
  26. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
  27. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
  28. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
  29. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
  30. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
  31. package/assertFragmentMap.js.flow +2 -2
  32. package/buildReactRelayContainer.js.flow +15 -12
  33. package/getRootVariablesForFragments.js.flow +2 -4
  34. package/hooks.js +1 -1
  35. package/hooks.js.flow +5 -6
  36. package/index.js +1 -1
  37. package/index.js.flow +6 -7
  38. package/jest-react/enqueueTask.js.flow +56 -0
  39. package/jest-react/index.js.flow +12 -0
  40. package/jest-react/internalAct.js.flow +139 -0
  41. package/legacy.js +1 -1
  42. package/lib/ReactRelayFragmentContainer.js +21 -15
  43. package/lib/ReactRelayFragmentMockRenderer.js +2 -2
  44. package/lib/ReactRelayLocalQueryRenderer.js +7 -8
  45. package/lib/ReactRelayPaginationContainer.js +96 -38
  46. package/lib/ReactRelayQueryFetcher.js +3 -3
  47. package/lib/ReactRelayQueryRenderer.js +86 -53
  48. package/lib/ReactRelayRefetchContainer.js +38 -25
  49. package/lib/ReactRelayTestMocker.js +8 -9
  50. package/lib/RelayContext.js +3 -2
  51. package/lib/assertFragmentMap.js +3 -2
  52. package/lib/buildReactRelayContainer.js +14 -11
  53. package/lib/getRootVariablesForFragments.js +1 -2
  54. package/lib/hooks.js +5 -5
  55. package/lib/index.js +7 -7
  56. package/lib/jest-react/enqueueTask.js +53 -0
  57. package/lib/jest-react/index.js +13 -0
  58. package/lib/jest-react/internalAct.js +116 -0
  59. package/lib/multi-actor/ActorChange.js +30 -0
  60. package/lib/multi-actor/index.js +11 -0
  61. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  62. package/lib/relay-hooks/EntryPointContainer.react.js +3 -3
  63. package/lib/relay-hooks/FragmentResource.js +347 -92
  64. package/lib/relay-hooks/LRUCache.js +1 -1
  65. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +4 -4
  66. package/lib/relay-hooks/MatchContainer.js +1 -1
  67. package/lib/relay-hooks/QueryResource.js +172 -29
  68. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -3
  69. package/lib/relay-hooks/SuspenseResource.js +130 -0
  70. package/lib/relay-hooks/loadQuery.js +42 -20
  71. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +24 -15
  72. package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -5
  73. package/lib/relay-hooks/useEntryPointLoader.js +2 -2
  74. package/lib/relay-hooks/useFetchTrackingRef.js +2 -1
  75. package/lib/relay-hooks/useFragment.js +8 -7
  76. package/lib/relay-hooks/useFragmentNode.js +4 -4
  77. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  78. package/lib/relay-hooks/useLazyLoadQuery.js +3 -3
  79. package/lib/relay-hooks/useLazyLoadQueryNode.js +10 -4
  80. package/lib/relay-hooks/useLoadMoreFunction.js +8 -12
  81. package/lib/relay-hooks/useMemoOperationDescriptor.js +2 -2
  82. package/lib/relay-hooks/useMemoVariables.js +2 -2
  83. package/lib/relay-hooks/useMutation.js +17 -6
  84. package/lib/relay-hooks/usePaginationFragment.js +2 -3
  85. package/lib/relay-hooks/usePreloadedQuery.js +8 -7
  86. package/lib/relay-hooks/useQueryLoader.js +30 -10
  87. package/lib/relay-hooks/useRefetchableFragmentNode.js +13 -17
  88. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  89. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -2
  90. package/lib/relay-hooks/useSubscribeToInvalidationState.js +2 -1
  91. package/lib/relay-hooks/useSubscription.js +10 -7
  92. package/multi-actor/ActorChange.js.flow +58 -0
  93. package/multi-actor/index.js.flow +14 -0
  94. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  95. package/package.json +3 -2
  96. package/react-relay-hooks.js +2 -2
  97. package/react-relay-hooks.min.js +2 -2
  98. package/react-relay-legacy.js +2 -2
  99. package/react-relay-legacy.min.js +2 -2
  100. package/react-relay.js +2 -2
  101. package/react-relay.min.js +2 -2
  102. package/relay-hooks/EntryPointContainer.react.js.flow +8 -15
  103. package/relay-hooks/EntryPointTypes.flow.js.flow +24 -25
  104. package/relay-hooks/FragmentResource.js.flow +368 -94
  105. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +32 -46
  106. package/relay-hooks/MatchContainer.js.flow +3 -2
  107. package/relay-hooks/QueryResource.js.flow +216 -25
  108. package/relay-hooks/RelayEnvironmentProvider.js.flow +14 -4
  109. package/relay-hooks/SuspenseResource.js.flow +115 -0
  110. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +4 -3
  111. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +1 -1
  112. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +10 -9
  113. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +8 -7
  114. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +10 -9
  115. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +10 -9
  116. package/relay-hooks/__flowtests__/utils.js.flow +8 -12
  117. package/relay-hooks/loadEntryPoint.js.flow +6 -12
  118. package/relay-hooks/loadQuery.js.flow +49 -31
  119. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +30 -21
  120. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +6 -12
  121. package/relay-hooks/useBlockingPaginationFragment.js.flow +13 -11
  122. package/relay-hooks/useEntryPointLoader.js.flow +7 -10
  123. package/relay-hooks/useFetchTrackingRef.js.flow +2 -2
  124. package/relay-hooks/useFragment.js.flow +26 -46
  125. package/relay-hooks/useFragmentNode.js.flow +5 -7
  126. package/relay-hooks/useIsOperationNodeActive.js.flow +3 -5
  127. package/relay-hooks/useIsParentQueryActive.js.flow +3 -4
  128. package/relay-hooks/useLazyLoadQuery.js.flow +9 -10
  129. package/relay-hooks/useLazyLoadQueryNode.js.flow +19 -13
  130. package/relay-hooks/useLoadMoreFunction.js.flow +20 -29
  131. package/relay-hooks/useMemoOperationDescriptor.js.flow +5 -7
  132. package/relay-hooks/useMemoVariables.js.flow +6 -6
  133. package/relay-hooks/useMutation.js.flow +26 -26
  134. package/relay-hooks/usePaginationFragment.js.flow +38 -44
  135. package/relay-hooks/usePreloadedQuery.js.flow +18 -14
  136. package/relay-hooks/useQueryLoader.js.flow +41 -22
  137. package/relay-hooks/useRefetchableFragment.js.flow +7 -8
  138. package/relay-hooks/useRefetchableFragmentNode.js.flow +24 -32
  139. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  140. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +2 -3
  141. package/relay-hooks/useSubscribeToInvalidationState.js.flow +3 -6
  142. package/relay-hooks/useSubscription.js.flow +20 -10
  143. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  144. package/lib/relay-hooks/getPaginationVariables.js +0 -67
  145. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  146. package/lib/relay-hooks/getValueAtPath.js +0 -51
  147. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  148. package/relay-hooks/getPaginationVariables.js.flow +0 -110
  149. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  150. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,36 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
- // flowlint ambiguous-object-type:error
12
- 'use strict';
13
-
14
- var invariant = require("fbjs/lib/invariant");
15
-
16
- function getRefetchMetadata(fragmentNode, componentDisplayName) {
17
- var _fragmentNode$metadat, _fragmentNode$metadat2;
18
-
19
- !(((_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) !== true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` not to be plural when using ' + '`%s`. Remove `@relay(plural: true)` from fragment `%s` ' + 'in order to use it with `%s`.', fragmentNode.name, componentDisplayName, fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
20
- var refetchMetadata = (_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.refetch;
21
- !(refetchMetadata != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` to be refetchable when using `%s`. ' + 'Did you forget to add a @refetchable directive to the fragment?', componentDisplayName, fragmentNode.name) : invariant(false) : void 0; // handle both commonjs and es modules
22
-
23
- var refetchableRequest = refetchMetadata.operation["default"] ? refetchMetadata.operation["default"] : refetchMetadata.operation;
24
- var fragmentRefPathInResponse = refetchMetadata.fragmentPathInResult;
25
- !(typeof refetchableRequest !== 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected refetch query to be an ' + "operation and not a string when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', componentDisplayName) : invariant(false) : void 0;
26
- var identifierField = refetchMetadata.identifierField;
27
- !(identifierField == null || typeof identifierField === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.') : invariant(false) : void 0;
28
- return {
29
- fragmentRefPathInResponse: fragmentRefPathInResponse,
30
- identifierField: identifierField,
31
- refetchableRequest: refetchableRequest,
32
- refetchMetadata: refetchMetadata
33
- };
34
- }
35
-
36
- module.exports = getRefetchMetadata;
@@ -1,51 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
- // flowlint ambiguous-object-type:error
12
- 'use strict';
13
-
14
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
15
-
16
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
17
-
18
- var invariant = require("fbjs/lib/invariant");
19
-
20
- function getValueAtPath(data, path) {
21
- var result = data;
22
-
23
- var _iterator = (0, _createForOfIteratorHelper2["default"])(path),
24
- _step;
25
-
26
- try {
27
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
- var key = _step.value;
29
-
30
- if (result == null) {
31
- return null;
32
- }
33
-
34
- if (typeof key === 'number') {
35
- !Array.isArray(result) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an array when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
36
- result = result[key];
37
- } else {
38
- !(typeof result === 'object' && !Array.isArray(result)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an object when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
39
- result = result[key];
40
- }
41
- }
42
- } catch (err) {
43
- _iterator.e(err);
44
- } finally {
45
- _iterator.f();
46
- }
47
-
48
- return result;
49
- }
50
-
51
- module.exports = getValueAtPath;
@@ -1,74 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- * @flow strict-local
9
- * @format
10
- */
11
-
12
- // flowlint ambiguous-object-type:error
13
-
14
- 'use strict';
15
-
16
- const getRefetchMetadata = require('./getRefetchMetadata');
17
- const invariant = require('invariant');
18
-
19
- import type {
20
- ConcreteRequest,
21
- ReaderFragment,
22
- ReaderPaginationMetadata,
23
- } from 'relay-runtime';
24
-
25
- function getPaginationMetadata(
26
- fragmentNode: ReaderFragment,
27
- componentDisplayName: string,
28
- ): {|
29
- connectionPathInFragmentData: $ReadOnlyArray<string | number>,
30
- identifierField: ?string,
31
- paginationRequest: ConcreteRequest,
32
- paginationMetadata: ReaderPaginationMetadata,
33
- stream: boolean,
34
- |} {
35
- const {
36
- refetchableRequest: paginationRequest,
37
- refetchMetadata,
38
- } = getRefetchMetadata(fragmentNode, componentDisplayName);
39
-
40
- const paginationMetadata = refetchMetadata.connection;
41
- invariant(
42
- paginationMetadata != null,
43
- 'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' +
44
- 'connection when using `%s`. Did you forget to add a @connection ' +
45
- 'directive to the connection field in the fragment?',
46
- componentDisplayName,
47
- fragmentNode.name,
48
- );
49
- const connectionPathInFragmentData = paginationMetadata.path;
50
-
51
- const connectionMetadata = (fragmentNode.metadata?.connection ?? [])[0];
52
- invariant(
53
- connectionMetadata != null,
54
- 'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' +
55
- 'connection when using `%s`. Did you forget to add a @connection ' +
56
- 'directive to the connection field in the fragment?',
57
- componentDisplayName,
58
- fragmentNode.name,
59
- );
60
- const identifierField = refetchMetadata.identifierField;
61
- invariant(
62
- identifierField == null || typeof identifierField === 'string',
63
- 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.',
64
- );
65
- return {
66
- connectionPathInFragmentData,
67
- identifierField,
68
- paginationRequest,
69
- paginationMetadata,
70
- stream: connectionMetadata.stream === true,
71
- };
72
- }
73
-
74
- module.exports = getPaginationMetadata;
@@ -1,110 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- * @flow strict-local
9
- * @format
10
- */
11
-
12
- // flowlint ambiguous-object-type:error
13
-
14
- 'use strict';
15
-
16
- const invariant = require('invariant');
17
- const warning = require('warning');
18
-
19
- import type {Direction} from './useLoadMoreFunction';
20
- import type {ReaderPaginationMetadata, Variables} from 'relay-runtime';
21
-
22
- function getPaginationVariables(
23
- direction: Direction,
24
- count: number,
25
- cursor: ?string,
26
- baseVariables: Variables,
27
- extraVariables: Variables,
28
- paginationMetadata: ReaderPaginationMetadata,
29
- ): {[string]: mixed, ...} {
30
- const {
31
- backward: backwardMetadata,
32
- forward: forwardMetadata,
33
- } = paginationMetadata;
34
-
35
- if (direction === 'backward') {
36
- invariant(
37
- backwardMetadata != null &&
38
- backwardMetadata.count != null &&
39
- backwardMetadata.cursor != null,
40
- 'Relay: Expected backward pagination metadata to be available. ' +
41
- "If you're seeing this, this is likely a bug in Relay.",
42
- );
43
- warning(
44
- !extraVariables.hasOwnProperty(backwardMetadata.cursor),
45
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
46
- 'contain cursor variable `%s`. This variable is automatically ' +
47
- 'determined by Relay.',
48
- backwardMetadata.cursor,
49
- );
50
- warning(
51
- !extraVariables.hasOwnProperty(backwardMetadata.count),
52
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
53
- 'contain count variable `%s`. This variable is automatically ' +
54
- 'determined by Relay.',
55
- backwardMetadata.count,
56
- );
57
- // $FlowFixMe[cannot-spread-interface]
58
- const paginationVariables = {
59
- ...baseVariables,
60
- ...extraVariables,
61
- [backwardMetadata.cursor]: cursor,
62
- [backwardMetadata.count]: count,
63
- };
64
- if (forwardMetadata && forwardMetadata.cursor) {
65
- paginationVariables[forwardMetadata.cursor] = null;
66
- }
67
- if (forwardMetadata && forwardMetadata.count) {
68
- paginationVariables[forwardMetadata.count] = null;
69
- }
70
- return paginationVariables;
71
- }
72
-
73
- invariant(
74
- forwardMetadata != null &&
75
- forwardMetadata.count != null &&
76
- forwardMetadata.cursor != null,
77
- 'Relay: Expected forward pagination metadata to be available. ' +
78
- "If you're seeing this, this is likely a bug in Relay.",
79
- );
80
- warning(
81
- !extraVariables.hasOwnProperty(forwardMetadata.cursor),
82
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
83
- 'contain cursor variable `%s`. This variable is automatically ' +
84
- 'determined by Relay.',
85
- forwardMetadata.cursor,
86
- );
87
- warning(
88
- !extraVariables.hasOwnProperty(forwardMetadata.count),
89
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
90
- 'contain count variable `%s`. This variable is automatically ' +
91
- 'determined by Relay.',
92
- forwardMetadata.count,
93
- );
94
- // $FlowFixMe[cannot-spread-interface]
95
- const paginationVariables = {
96
- ...baseVariables,
97
- ...extraVariables,
98
- [forwardMetadata.cursor]: cursor,
99
- [forwardMetadata.count]: count,
100
- };
101
- if (backwardMetadata && backwardMetadata.cursor) {
102
- paginationVariables[backwardMetadata.cursor] = null;
103
- }
104
- if (backwardMetadata && backwardMetadata.count) {
105
- paginationVariables[backwardMetadata.count] = null;
106
- }
107
- return paginationVariables;
108
- }
109
-
110
- module.exports = getPaginationVariables;
@@ -1,80 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- * @flow strict-local
9
- * @format
10
- */
11
-
12
- // flowlint ambiguous-object-type:error
13
-
14
- 'use strict';
15
-
16
- const invariant = require('invariant');
17
-
18
- import type {
19
- ConcreteRequest,
20
- ReaderFragment,
21
- ReaderRefetchMetadata,
22
- } from 'relay-runtime';
23
-
24
- function getRefetchMetadata(
25
- fragmentNode: ReaderFragment,
26
- componentDisplayName: string,
27
- ): {|
28
- fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
29
- identifierField: ?string,
30
- refetchableRequest: ConcreteRequest,
31
- refetchMetadata: ReaderRefetchMetadata,
32
- |} {
33
- invariant(
34
- fragmentNode.metadata?.plural !== true,
35
- 'Relay: getRefetchMetadata(): Expected fragment `%s` not to be plural when using ' +
36
- '`%s`. Remove `@relay(plural: true)` from fragment `%s` ' +
37
- 'in order to use it with `%s`.',
38
- fragmentNode.name,
39
- componentDisplayName,
40
- fragmentNode.name,
41
- componentDisplayName,
42
- );
43
-
44
- const refetchMetadata = fragmentNode.metadata?.refetch;
45
- invariant(
46
- refetchMetadata != null,
47
- 'Relay: getRefetchMetadata(): Expected fragment `%s` to be refetchable when using `%s`. ' +
48
- 'Did you forget to add a @refetchable directive to the fragment?',
49
- componentDisplayName,
50
- fragmentNode.name,
51
- );
52
-
53
- // handle both commonjs and es modules
54
- const refetchableRequest:
55
- | ConcreteRequest
56
- | string = (refetchMetadata: $FlowFixMe).operation.default
57
- ? (refetchMetadata: $FlowFixMe).operation.default
58
- : refetchMetadata.operation;
59
- const fragmentRefPathInResponse = refetchMetadata.fragmentPathInResult;
60
- invariant(
61
- typeof refetchableRequest !== 'string',
62
- 'Relay: getRefetchMetadata(): Expected refetch query to be an ' +
63
- "operation and not a string when using `%s`. If you're seeing this, " +
64
- 'this is likely a bug in Relay.',
65
- componentDisplayName,
66
- );
67
- const identifierField = refetchMetadata.identifierField;
68
- invariant(
69
- identifierField == null || typeof identifierField === 'string',
70
- 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.',
71
- );
72
- return {
73
- fragmentRefPathInResponse,
74
- identifierField,
75
- refetchableRequest,
76
- refetchMetadata,
77
- };
78
- }
79
-
80
- module.exports = getRefetchMetadata;
@@ -1,46 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- * @flow strict-local
9
- * @format
10
- */
11
-
12
- // flowlint ambiguous-object-type:error
13
-
14
- 'use strict';
15
-
16
- const invariant = require('invariant');
17
-
18
- function getValueAtPath(
19
- data: mixed,
20
- path: $ReadOnlyArray<string | number>,
21
- ): mixed {
22
- let result = data;
23
- for (const key of path) {
24
- if (result == null) {
25
- return null;
26
- }
27
- if (typeof key === 'number') {
28
- invariant(
29
- Array.isArray(result),
30
- 'Relay: Expected an array when extracting value at path. ' +
31
- "If you're seeing this, this is likely a bug in Relay.",
32
- );
33
- result = result[key];
34
- } else {
35
- invariant(
36
- typeof result === 'object' && !Array.isArray(result),
37
- 'Relay: Expected an object when extracting value at path. ' +
38
- "If you're seeing this, this is likely a bug in Relay.",
39
- );
40
- result = result[key];
41
- }
42
- }
43
- return result;
44
- }
45
-
46
- module.exports = getValueAtPath;