react-relay 11.0.2 → 13.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/README.md +47 -0
  2. package/ReactRelayContainerUtils.js.flow +1 -1
  3. package/ReactRelayContext.js +1 -1
  4. package/ReactRelayContext.js.flow +3 -4
  5. package/ReactRelayFragmentContainer.js.flow +25 -25
  6. package/ReactRelayFragmentMockRenderer.js.flow +2 -2
  7. package/ReactRelayLocalQueryRenderer.js.flow +7 -8
  8. package/ReactRelayPaginationContainer.js.flow +112 -59
  9. package/ReactRelayQueryFetcher.js.flow +10 -11
  10. package/ReactRelayQueryRenderer.js.flow +116 -82
  11. package/ReactRelayQueryRendererContext.js.flow +1 -1
  12. package/ReactRelayRefetchContainer.js.flow +42 -39
  13. package/ReactRelayTestMocker.js.flow +17 -15
  14. package/ReactRelayTypes.js.flow +11 -11
  15. package/RelayContext.js.flow +4 -4
  16. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
  17. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
  18. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
  19. package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
  20. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
  21. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
  22. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
  23. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
  25. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
  27. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
  29. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
  30. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
  31. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
  32. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
  33. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
  34. package/assertFragmentMap.js.flow +3 -3
  35. package/buildReactRelayContainer.js.flow +12 -11
  36. package/getRootVariablesForFragments.js.flow +3 -5
  37. package/hooks.js +1 -1
  38. package/hooks.js.flow +6 -7
  39. package/index.js +1 -1
  40. package/index.js.flow +7 -8
  41. package/isRelayEnvironment.js.flow +1 -1
  42. package/jest-react/enqueueTask.js.flow +56 -0
  43. package/jest-react/index.js.flow +12 -0
  44. package/jest-react/internalAct.js.flow +138 -0
  45. package/legacy.js +1 -1
  46. package/legacy.js.flow +1 -1
  47. package/lib/ReactRelayContainerUtils.js +1 -1
  48. package/lib/ReactRelayContext.js +1 -1
  49. package/lib/ReactRelayFragmentContainer.js +22 -16
  50. package/lib/ReactRelayFragmentMockRenderer.js +3 -3
  51. package/lib/ReactRelayLocalQueryRenderer.js +8 -9
  52. package/lib/ReactRelayPaginationContainer.js +97 -39
  53. package/lib/ReactRelayQueryFetcher.js +3 -3
  54. package/lib/ReactRelayQueryRenderer.js +87 -54
  55. package/lib/ReactRelayQueryRendererContext.js +1 -1
  56. package/lib/ReactRelayRefetchContainer.js +39 -26
  57. package/lib/ReactRelayTestMocker.js +8 -9
  58. package/lib/ReactRelayTypes.js +1 -1
  59. package/lib/RelayContext.js +4 -3
  60. package/lib/assertFragmentMap.js +3 -2
  61. package/lib/buildReactRelayContainer.js +8 -8
  62. package/lib/getRootVariablesForFragments.js +2 -3
  63. package/lib/hooks.js +6 -6
  64. package/lib/index.js +8 -8
  65. package/lib/isRelayEnvironment.js +1 -1
  66. package/lib/jest-react/enqueueTask.js +53 -0
  67. package/lib/jest-react/index.js +13 -0
  68. package/lib/jest-react/internalAct.js +115 -0
  69. package/lib/legacy.js +1 -1
  70. package/lib/multi-actor/ActorChange.js +30 -0
  71. package/lib/multi-actor/index.js +11 -0
  72. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  73. package/lib/readContext.js +1 -1
  74. package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
  75. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
  76. package/lib/relay-hooks/FragmentResource.js +342 -89
  77. package/lib/relay-hooks/InternalLogger.js +1 -1
  78. package/lib/relay-hooks/LRUCache.js +1 -1
  79. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
  80. package/lib/relay-hooks/MatchContainer.js +2 -2
  81. package/lib/relay-hooks/ProfilerContext.js +1 -1
  82. package/lib/relay-hooks/QueryResource.js +172 -29
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
  84. package/lib/relay-hooks/SuspenseResource.js +130 -0
  85. package/lib/relay-hooks/loadEntryPoint.js +1 -1
  86. package/lib/relay-hooks/loadQuery.js +42 -20
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
  89. package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
  90. package/lib/relay-hooks/useEntryPointLoader.js +3 -3
  91. package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
  92. package/lib/relay-hooks/useFragment.js +7 -7
  93. package/lib/relay-hooks/useFragmentNode.js +5 -5
  94. package/lib/relay-hooks/useIsMountedRef.js +1 -1
  95. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  96. package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
  97. package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
  98. package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
  99. package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
  100. package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
  101. package/lib/relay-hooks/useMemoVariables.js +3 -3
  102. package/lib/relay-hooks/useMutation.js +18 -7
  103. package/lib/relay-hooks/usePaginationFragment.js +3 -4
  104. package/lib/relay-hooks/usePreloadedQuery.js +6 -6
  105. package/lib/relay-hooks/useQueryLoader.js +31 -11
  106. package/lib/relay-hooks/useRefetchableFragment.js +1 -1
  107. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
  108. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  109. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
  110. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
  111. package/lib/relay-hooks/useSubscription.js +11 -8
  112. package/multi-actor/ActorChange.js.flow +58 -0
  113. package/multi-actor/index.js.flow +14 -0
  114. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  115. package/package.json +3 -3
  116. package/react-relay-hooks.js +2 -2
  117. package/react-relay-hooks.min.js +2 -2
  118. package/react-relay-legacy.js +2 -2
  119. package/react-relay-legacy.min.js +2 -2
  120. package/react-relay.js +2 -2
  121. package/react-relay.min.js +2 -2
  122. package/readContext.js.flow +1 -1
  123. package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
  125. package/relay-hooks/FragmentResource.js.flow +359 -93
  126. package/relay-hooks/InternalLogger.js.flow +1 -1
  127. package/relay-hooks/LRUCache.js.flow +1 -1
  128. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
  129. package/relay-hooks/MatchContainer.js.flow +4 -3
  130. package/relay-hooks/ProfilerContext.js.flow +1 -1
  131. package/relay-hooks/QueryResource.js.flow +217 -26
  132. package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
  133. package/relay-hooks/SuspenseResource.js.flow +115 -0
  134. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
  135. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  136. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
  138. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
  139. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
  140. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
  141. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
  142. package/relay-hooks/__flowtests__/utils.js.flow +21 -32
  143. package/relay-hooks/loadEntryPoint.js.flow +7 -13
  144. package/relay-hooks/loadQuery.js.flow +50 -32
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
  147. package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
  148. package/relay-hooks/useEntryPointLoader.js.flow +8 -11
  149. package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
  150. package/relay-hooks/useFragment.js.flow +31 -62
  151. package/relay-hooks/useFragmentNode.js.flow +6 -8
  152. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  153. package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
  154. package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
  155. package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
  156. package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
  157. package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
  158. package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
  159. package/relay-hooks/useMemoVariables.js.flow +7 -7
  160. package/relay-hooks/useMutation.js.flow +27 -27
  161. package/relay-hooks/usePaginationFragment.js.flow +39 -45
  162. package/relay-hooks/usePreloadedQuery.js.flow +14 -20
  163. package/relay-hooks/useQueryLoader.js.flow +42 -23
  164. package/relay-hooks/useRefetchableFragment.js.flow +8 -9
  165. package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
  166. package/relay-hooks/useRelayEnvironment.js.flow +3 -5
  167. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
  168. package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
  169. package/relay-hooks/useSubscription.js.flow +21 -11
  170. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  171. package/lib/relay-hooks/getPaginationVariables.js +0 -67
  172. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  173. package/lib/relay-hooks/getValueAtPath.js +0 -51
  174. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  175. package/relay-hooks/getPaginationVariables.js.flow +0 -110
  176. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  177. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -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;