react-relay 11.0.0 → 13.0.0-rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) 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 +7 -8
  6. package/ReactRelayPaginationContainer.js.flow +111 -54
  7. package/ReactRelayQueryFetcher.js.flow +9 -10
  8. package/ReactRelayQueryRenderer.js.flow +115 -81
  9. package/ReactRelayRefetchContainer.js.flow +40 -35
  10. package/ReactRelayTestMocker.js.flow +16 -12
  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 +12 -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 -3
  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 +92 -30
  46. package/lib/ReactRelayQueryFetcher.js +3 -3
  47. package/lib/ReactRelayQueryRenderer.js +86 -53
  48. package/lib/ReactRelayRefetchContainer.js +36 -21
  49. package/lib/ReactRelayTestMocker.js +7 -6
  50. package/lib/RelayContext.js +3 -2
  51. package/lib/assertFragmentMap.js +3 -2
  52. package/lib/buildReactRelayContainer.js +14 -11
  53. package/lib/hooks.js +5 -5
  54. package/lib/index.js +7 -7
  55. package/lib/jest-react/enqueueTask.js +53 -0
  56. package/lib/jest-react/index.js +13 -0
  57. package/lib/jest-react/internalAct.js +116 -0
  58. package/lib/multi-actor/ActorChange.js +30 -0
  59. package/lib/multi-actor/index.js +11 -0
  60. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  61. package/lib/relay-hooks/EntryPointContainer.react.js +3 -3
  62. package/lib/relay-hooks/FragmentResource.js +351 -94
  63. package/lib/relay-hooks/LRUCache.js +1 -1
  64. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +4 -4
  65. package/lib/relay-hooks/MatchContainer.js +1 -1
  66. package/lib/relay-hooks/QueryResource.js +172 -29
  67. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -3
  68. package/lib/relay-hooks/SuspenseResource.js +130 -0
  69. package/lib/relay-hooks/loadQuery.js +42 -20
  70. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +24 -15
  71. package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -5
  72. package/lib/relay-hooks/useEntryPointLoader.js +2 -2
  73. package/lib/relay-hooks/useFetchTrackingRef.js +2 -1
  74. package/lib/relay-hooks/useFragment.js +8 -7
  75. package/lib/relay-hooks/useFragmentNode.js +4 -4
  76. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  77. package/lib/relay-hooks/useLazyLoadQuery.js +3 -3
  78. package/lib/relay-hooks/useLazyLoadQueryNode.js +10 -4
  79. package/lib/relay-hooks/useLoadMoreFunction.js +6 -8
  80. package/lib/relay-hooks/useMemoOperationDescriptor.js +2 -2
  81. package/lib/relay-hooks/useMemoVariables.js +2 -2
  82. package/lib/relay-hooks/useMutation.js +17 -6
  83. package/lib/relay-hooks/usePaginationFragment.js +2 -3
  84. package/lib/relay-hooks/usePreloadedQuery.js +8 -7
  85. package/lib/relay-hooks/useQueryLoader.js +30 -10
  86. package/lib/relay-hooks/useRefetchableFragmentNode.js +12 -14
  87. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  88. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -2
  89. package/lib/relay-hooks/useSubscribeToInvalidationState.js +2 -1
  90. package/lib/relay-hooks/useSubscription.js +10 -7
  91. package/multi-actor/ActorChange.js.flow +58 -0
  92. package/multi-actor/index.js.flow +14 -0
  93. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  94. package/package.json +3 -2
  95. package/react-relay-hooks.js +2 -2
  96. package/react-relay-hooks.min.js +2 -2
  97. package/react-relay-legacy.js +2 -2
  98. package/react-relay-legacy.min.js +2 -2
  99. package/react-relay.js +2 -2
  100. package/react-relay.min.js +2 -2
  101. package/relay-hooks/EntryPointContainer.react.js.flow +8 -15
  102. package/relay-hooks/EntryPointTypes.flow.js.flow +24 -25
  103. package/relay-hooks/FragmentResource.js.flow +376 -95
  104. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +32 -46
  105. package/relay-hooks/MatchContainer.js.flow +3 -2
  106. package/relay-hooks/QueryResource.js.flow +216 -25
  107. package/relay-hooks/RelayEnvironmentProvider.js.flow +14 -4
  108. package/relay-hooks/SuspenseResource.js.flow +115 -0
  109. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +4 -3
  110. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +1 -1
  111. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +10 -9
  112. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +8 -7
  113. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +10 -9
  114. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +10 -9
  115. package/relay-hooks/__flowtests__/utils.js.flow +8 -12
  116. package/relay-hooks/loadEntryPoint.js.flow +6 -12
  117. package/relay-hooks/loadQuery.js.flow +49 -31
  118. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +30 -21
  119. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +6 -12
  120. package/relay-hooks/useBlockingPaginationFragment.js.flow +13 -11
  121. package/relay-hooks/useEntryPointLoader.js.flow +7 -10
  122. package/relay-hooks/useFetchTrackingRef.js.flow +2 -2
  123. package/relay-hooks/useFragment.js.flow +26 -46
  124. package/relay-hooks/useFragmentNode.js.flow +5 -7
  125. package/relay-hooks/useIsOperationNodeActive.js.flow +3 -5
  126. package/relay-hooks/useIsParentQueryActive.js.flow +3 -4
  127. package/relay-hooks/useLazyLoadQuery.js.flow +9 -10
  128. package/relay-hooks/useLazyLoadQueryNode.js.flow +19 -13
  129. package/relay-hooks/useLoadMoreFunction.js.flow +20 -27
  130. package/relay-hooks/useMemoOperationDescriptor.js.flow +5 -7
  131. package/relay-hooks/useMemoVariables.js.flow +6 -6
  132. package/relay-hooks/useMutation.js.flow +26 -26
  133. package/relay-hooks/usePaginationFragment.js.flow +38 -44
  134. package/relay-hooks/usePreloadedQuery.js.flow +18 -14
  135. package/relay-hooks/useQueryLoader.js.flow +41 -22
  136. package/relay-hooks/useRefetchableFragment.js.flow +7 -8
  137. package/relay-hooks/useRefetchableFragmentNode.js.flow +24 -30
  138. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  139. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +2 -3
  140. package/relay-hooks/useSubscribeToInvalidationState.js.flow +3 -6
  141. package/relay-hooks/useSubscription.js.flow +20 -10
  142. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  143. package/lib/relay-hooks/getPaginationVariables.js +0 -66
  144. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  145. package/lib/relay-hooks/getValueAtPath.js +0 -51
  146. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  147. package/relay-hooks/getPaginationVariables.js.flow +0 -108
  148. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  149. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -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,108 +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
- const paginationVariables = {
58
- ...baseVariables,
59
- ...extraVariables,
60
- [backwardMetadata.cursor]: cursor,
61
- [backwardMetadata.count]: count,
62
- };
63
- if (forwardMetadata && forwardMetadata.cursor) {
64
- paginationVariables[forwardMetadata.cursor] = null;
65
- }
66
- if (forwardMetadata && forwardMetadata.count) {
67
- paginationVariables[forwardMetadata.count] = null;
68
- }
69
- return paginationVariables;
70
- }
71
-
72
- invariant(
73
- forwardMetadata != null &&
74
- forwardMetadata.count != null &&
75
- forwardMetadata.cursor != null,
76
- 'Relay: Expected forward pagination metadata to be available. ' +
77
- "If you're seeing this, this is likely a bug in Relay.",
78
- );
79
- warning(
80
- !extraVariables.hasOwnProperty(forwardMetadata.cursor),
81
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
82
- 'contain cursor variable `%s`. This variable is automatically ' +
83
- 'determined by Relay.',
84
- forwardMetadata.cursor,
85
- );
86
- warning(
87
- !extraVariables.hasOwnProperty(forwardMetadata.count),
88
- 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
89
- 'contain count variable `%s`. This variable is automatically ' +
90
- 'determined by Relay.',
91
- forwardMetadata.count,
92
- );
93
- const paginationVariables = {
94
- ...baseVariables,
95
- ...extraVariables,
96
- [forwardMetadata.cursor]: cursor,
97
- [forwardMetadata.count]: count,
98
- };
99
- if (backwardMetadata && backwardMetadata.cursor) {
100
- paginationVariables[backwardMetadata.cursor] = null;
101
- }
102
- if (backwardMetadata && backwardMetadata.count) {
103
- paginationVariables[backwardMetadata.count] = null;
104
- }
105
- return paginationVariables;
106
- }
107
-
108
- 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;