react-relay 14.0.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -2
  4. package/ReactRelayFragmentContainer.js.flow +6 -4
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -5
  7. package/ReactRelayPaginationContainer.js.flow +21 -14
  8. package/ReactRelayQueryFetcher.js.flow +28 -16
  9. package/ReactRelayQueryRenderer.js.flow +42 -13
  10. package/ReactRelayQueryRendererContext.js.flow +2 -3
  11. package/ReactRelayRefetchContainer.js.flow +9 -9
  12. package/ReactRelayTestMocker.js.flow +3 -3
  13. package/ReactRelayTypes.js.flow +7 -8
  14. package/RelayContext.js.flow +1 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -2
  34. package/buildReactRelayContainer.js.flow +7 -7
  35. package/getRootVariablesForFragments.js.flow +1 -3
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +6 -2
  40. package/isRelayEnvironment.js.flow +1 -2
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -2
  46. package/lib/ReactRelayContainerUtils.js +2 -3
  47. package/lib/ReactRelayContext.js +3 -4
  48. package/lib/ReactRelayFragmentContainer.js +47 -73
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -4
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -31
  51. package/lib/ReactRelayPaginationContainer.js +74 -164
  52. package/lib/ReactRelayQueryFetcher.js +49 -76
  53. package/lib/ReactRelayQueryRenderer.js +63 -84
  54. package/lib/ReactRelayQueryRendererContext.js +2 -2
  55. package/lib/ReactRelayRefetchContainer.js +58 -108
  56. package/lib/ReactRelayTestMocker.js +33 -68
  57. package/lib/ReactRelayTypes.js +2 -1
  58. package/lib/RelayContext.js +4 -7
  59. package/lib/assertFragmentMap.js +3 -5
  60. package/lib/buildReactRelayContainer.js +11 -27
  61. package/lib/getRootVariablesForFragments.js +6 -10
  62. package/lib/hooks.js +5 -18
  63. package/lib/index.js +7 -24
  64. package/lib/isRelayEnvironment.js +5 -4
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -8
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
  74. package/lib/relay-hooks/FragmentResource.js +109 -203
  75. package/lib/relay-hooks/HooksImplementation.js +3 -6
  76. package/lib/relay-hooks/InternalLogger.js +2 -3
  77. package/lib/relay-hooks/LRUCache.js +2 -20
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
  79. package/lib/relay-hooks/MatchContainer.js +15 -24
  80. package/lib/relay-hooks/ProfilerContext.js +3 -3
  81. package/lib/relay-hooks/QueryResource.js +31 -101
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
  83. package/lib/relay-hooks/SuspenseResource.js +9 -33
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +42 -78
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
  99. package/lib/relay-hooks/useClientQuery.js +30 -0
  100. package/lib/relay-hooks/useEntryPointLoader.js +18 -38
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
  102. package/lib/relay-hooks/useFragment.js +8 -19
  103. package/lib/relay-hooks/useFragmentNode.js +20 -32
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -6
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
  109. package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
  111. package/lib/relay-hooks/useMemoVariables.js +15 -34
  112. package/lib/relay-hooks/useMutation.js +9 -27
  113. package/lib/relay-hooks/usePaginationFragment.js +73 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +13 -44
  115. package/lib/relay-hooks/useQueryLoader.js +24 -49
  116. package/lib/relay-hooks/useRefetchableFragment.js +19 -17
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -8
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
  121. package/lib/relay-hooks/useSubscription.js +5 -10
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
  135. package/relay-hooks/FragmentResource.js.flow +43 -19
  136. package/relay-hooks/HooksImplementation.js.flow +7 -9
  137. package/relay-hooks/InternalLogger.js.flow +1 -3
  138. package/relay-hooks/LRUCache.js.flow +1 -3
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
  140. package/relay-hooks/MatchContainer.js.flow +6 -8
  141. package/relay-hooks/ProfilerContext.js.flow +1 -3
  142. package/relay-hooks/QueryResource.js.flow +29 -11
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
  144. package/relay-hooks/SuspenseResource.js.flow +1 -3
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
  153. package/relay-hooks/__flowtests__/utils.js.flow +21 -12
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
  169. package/relay-hooks/useClientQuery.js.flow +39 -0
  170. package/relay-hooks/useEntryPointLoader.js.flow +16 -14
  171. package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
  172. package/relay-hooks/useFragment.js.flow +2 -4
  173. package/relay-hooks/useFragmentNode.js.flow +7 -8
  174. package/relay-hooks/useIsMountedRef.js.flow +2 -4
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
  179. package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
  181. package/relay-hooks/useMemoVariables.js.flow +13 -31
  182. package/relay-hooks/useMutation.js.flow +6 -8
  183. package/relay-hooks/usePaginationFragment.js.flow +75 -43
  184. package/relay-hooks/usePreloadedQuery.js.flow +49 -43
  185. package/relay-hooks/useQueryLoader.js.flow +89 -28
  186. package/relay-hooks/useRefetchableFragment.js.flow +83 -23
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
  191. package/relay-hooks/useSubscription.js.flow +1 -3
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -28
  194. package/readContext.js.flow +0 -31
@@ -6,37 +6,36 @@
6
6
  *
7
7
  *
8
8
  * @format
9
- * @emails oncall+relay
9
+ * @oncall relay
10
10
  */
11
+
11
12
  'use strict';
12
13
 
13
14
  var _require = require('./loadQuery'),
14
- loadQuery = _require.loadQuery;
15
-
15
+ loadQuery = _require.loadQuery;
16
16
  function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
17
17
  // Start loading the code for the entrypoint
18
18
  var loadingPromise = null;
19
-
20
19
  if (entryPoint.root.getModuleIfRequired() == null) {
21
20
  loadingPromise = entryPoint.root.load();
22
21
  }
23
-
24
22
  var preloadProps = entryPoint.getPreloadProps(entryPointParams);
25
23
  var queries = preloadProps.queries,
26
- entryPoints = preloadProps.entryPoints,
27
- extraProps = preloadProps.extraProps;
24
+ entryPoints = preloadProps.entryPoints,
25
+ extraProps = preloadProps.extraProps;
28
26
  var preloadedQueries = {};
29
27
  var preloadedEntryPoints = {};
30
-
31
28
  if (queries != null) {
32
29
  var queriesPropNames = Object.keys(queries);
33
30
  queriesPropNames.forEach(function (queryPropName) {
34
31
  var _queries$queryPropNam = queries[queryPropName],
35
- environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
36
- options = _queries$queryPropNam.options,
37
- parameters = _queries$queryPropNam.parameters,
38
- variables = _queries$queryPropNam.variables;
32
+ environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
33
+ options = _queries$queryPropNam.options,
34
+ parameters = _queries$queryPropNam.parameters,
35
+ variables = _queries$queryPropNam.variables;
39
36
  var environment = environmentProvider.getEnvironment(environmentProviderOptions);
37
+
38
+ // $FlowFixMe[underconstrained-implicit-instantiation]
40
39
  preloadedQueries[queryPropName] = loadQuery(environment, parameters, variables, {
41
40
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
42
41
  networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig,
@@ -44,75 +43,64 @@ function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
44
43
  }, environmentProviderOptions);
45
44
  });
46
45
  }
47
-
48
46
  if (entryPoints != null) {
49
47
  var entryPointPropNames = Object.keys(entryPoints);
50
48
  entryPointPropNames.forEach(function (entryPointPropName) {
51
49
  var entryPointDescription = entryPoints[entryPointPropName];
52
-
53
50
  if (entryPointDescription == null) {
54
51
  return;
55
52
  }
56
-
57
53
  var nestedEntryPoint = entryPointDescription.entryPoint,
58
- nestedParams = entryPointDescription.entryPointParams;
54
+ nestedParams = entryPointDescription.entryPointParams;
59
55
  preloadedEntryPoints[entryPointPropName] = loadEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
60
56
  });
61
57
  }
62
-
63
58
  var isDisposed = false;
64
59
  return {
65
60
  dispose: function dispose() {
66
61
  if (isDisposed) {
67
62
  return;
68
63
  }
69
-
70
64
  if (preloadedQueries != null) {
71
65
  Object.values(preloadedQueries).forEach(function (_ref) {
72
66
  var innerDispose = _ref.dispose;
73
67
  innerDispose();
74
68
  });
75
69
  }
76
-
77
70
  if (preloadedEntryPoints != null) {
78
71
  Object.values(preloadedEntryPoints).forEach(function (_ref2) {
79
72
  var innerDispose = _ref2.dispose;
80
73
  innerDispose();
81
74
  });
82
75
  }
83
-
84
76
  isDisposed = true;
85
77
  },
86
78
  entryPoints: preloadedEntryPoints,
87
79
  extraProps: extraProps !== null && extraProps !== void 0 ? extraProps : null,
88
80
  getComponent: function getComponent() {
89
81
  var componentModule = entryPoint.root.getModuleIfRequired();
90
-
91
82
  if (componentModule == null) {
92
83
  var _loadingPromise;
93
-
94
84
  loadingPromise = (_loadingPromise = loadingPromise) !== null && _loadingPromise !== void 0 ? _loadingPromise : entryPoint.root.load();
95
85
  throw loadingPromise;
96
- } // On certain platforms, getting an es6 module with a default export from a JSResource will return an object like
86
+ }
87
+
88
+ // On certain platforms, getting an es6 module with a default export from a JSResource will return an object like
97
89
  // {default: module}, so let's assume that if the "component" has a static property named "default"
98
90
  // that it's actually an es6 module wrapper, so unwrap it. This won't work for React classes with a static property named "default", but
99
91
  // that's probably a worthwhile trade-off.
100
-
101
-
102
- var component = // $FlowIgnore[prop-missing]
103
- componentModule["default"] != null ? componentModule["default"] : componentModule; // $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
104
-
92
+ var component =
93
+ // $FlowIgnore[prop-missing]
94
+ componentModule["default"] != null ? componentModule["default"] : componentModule;
95
+ // $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
105
96
  return component;
106
97
  },
107
-
108
98
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
109
99
  get isDisposed() {
110
100
  return isDisposed;
111
101
  },
112
-
113
102
  queries: preloadedQueries,
114
103
  rootModuleID: entryPoint.root.getModuleId()
115
104
  };
116
105
  }
117
-
118
106
  module.exports = loadEntryPoint;
@@ -6,51 +6,44 @@
6
6
  *
7
7
  *
8
8
  * @format
9
- * @emails oncall+relay
9
+ * @oncall relay
10
10
  */
11
- 'use strict';
12
11
 
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
12
+ 'use strict';
14
13
 
14
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
16
  var invariant = require('invariant');
18
-
19
17
  var React = require('react');
20
-
21
18
  var _require = require('relay-runtime'),
22
- Observable = _require.Observable,
23
- PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
24
- RelayFeatureFlags = _require.RelayFeatureFlags,
25
- ReplaySubject = _require.ReplaySubject,
26
- fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
27
- createOperationDescriptor = _require.createOperationDescriptor,
28
- getRequest = _require.getRequest,
29
- getRequestIdentifier = _require.getRequestIdentifier;
30
-
19
+ fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
20
+ Observable = _require.Observable,
21
+ PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
22
+ RelayFeatureFlags = _require.RelayFeatureFlags,
23
+ ReplaySubject = _require.ReplaySubject,
24
+ createOperationDescriptor = _require.createOperationDescriptor,
25
+ getRequest = _require.getRequest,
26
+ getRequestIdentifier = _require.getRequestIdentifier;
31
27
  var warning = require("fbjs/lib/warning");
32
-
33
28
  var RenderDispatcher = null;
34
29
  var fetchKey = 100001;
35
-
36
30
  function useTrackLoadQueryInRender() {
37
31
  if (RenderDispatcher === null) {
38
32
  var _React$__SECRET_INTER, _React$__SECRET_INTER2;
39
-
40
33
  // Flow does not know of React internals (rightly so), but we need to
41
34
  // ensure here that this function isn't called inside render.
42
35
  RenderDispatcher = // $FlowFixMe[prop-missing]
43
36
  (_React$__SECRET_INTER = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER === void 0 ? void 0 : (_React$__SECRET_INTER2 = _React$__SECRET_INTER.ReactCurrentDispatcher) === null || _React$__SECRET_INTER2 === void 0 ? void 0 : _React$__SECRET_INTER2.current;
44
37
  }
45
38
  }
46
-
47
39
  function loadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
48
40
  var _React$__SECRET_INTER3, _React$__SECRET_INTER4, _options$__nameForWar, _options$fetchPolicy;
49
-
50
41
  // This code ensures that we don't call loadQuery during render.
51
42
  var CurrentDispatcher = // $FlowFixMe[prop-missing]
52
43
  (_React$__SECRET_INTER3 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER3 === void 0 ? void 0 : (_React$__SECRET_INTER4 = _React$__SECRET_INTER3.ReactCurrentDispatcher) === null || _React$__SECRET_INTER4 === void 0 ? void 0 : _React$__SECRET_INTER4.current;
53
- process.env.NODE_ENV !== "production" ? warning(RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher, 'Relay: `%s` should not be called inside a React render function.', (_options$__nameForWar = options === null || options === void 0 ? void 0 : options.__nameForWarning) !== null && _options$__nameForWar !== void 0 ? _options$__nameForWar : 'loadQuery') : void 0; // Every time you call loadQuery, we will generate a new fetchKey.
44
+ process.env.NODE_ENV !== "production" ? warning(RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher, 'Relay: `%s` should not be called inside a React render function.', (_options$__nameForWar = options === null || options === void 0 ? void 0 : options.__nameForWarning) !== null && _options$__nameForWar !== void 0 ? _options$__nameForWar : 'loadQuery') : void 0;
45
+
46
+ // Every time you call loadQuery, we will generate a new fetchKey.
54
47
  // This will ensure that every query reference that is created and
55
48
  // passed to usePreloadedQuery is independently evaluated,
56
49
  // even if they are for the same query/variables.
@@ -59,25 +52,26 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
59
52
  // cache in usePreloadedQuery reuse the cached result instead of
60
53
  // re-evaluating the new query ref and triggering a refetch if
61
54
  // necessary.
62
-
63
55
  fetchKey++;
64
56
  var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : 'store-or-network';
65
57
  var networkCacheConfig = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options === null || options === void 0 ? void 0 : options.networkCacheConfig), {}, {
66
58
  force: true
67
- }); // executeWithNetworkSource will retain and execute an operation
59
+ });
60
+
61
+ // executeWithNetworkSource will retain and execute an operation
68
62
  // against the Relay store, given an Observable that would provide
69
63
  // the network events for the operation.
70
-
71
64
  var retainReference;
72
65
  var didExecuteNetworkSource = false;
73
-
74
66
  var executeWithNetworkSource = function executeWithNetworkSource(operation, networkObservable) {
75
67
  didExecuteNetworkSource = true;
76
68
  return environment.executeWithSource({
77
69
  operation: operation,
78
70
  source: networkObservable
79
71
  });
80
- }; // N.B. For loadQuery, we unconventionally want to return an Observable
72
+ };
73
+
74
+ // N.B. For loadQuery, we unconventionally want to return an Observable
81
75
  // that isn't lazily executed, meaning that we don't want to wait
82
76
  // until the returned Observable is subscribed to to actually start
83
77
  // fetching and executing an operation; i.e. we want to execute the
@@ -86,20 +80,17 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
86
80
  // allows us to capture the events that occur during the eager execution
87
81
  // of the operation, and then replay them to the Observable we
88
82
  // ultimately return.
89
-
90
-
91
83
  var executionSubject = new ReplaySubject();
92
84
  var returnedObservable = Observable.create(function (sink) {
93
85
  return executionSubject.subscribe(sink);
94
86
  });
95
87
  var unsubscribeFromNetworkRequest;
96
- var networkError = null; // makeNetworkRequest will immediately start a raw network request if
88
+ var networkError = null;
89
+ // makeNetworkRequest will immediately start a raw network request if
97
90
  // one isn't already in flight and return an Observable that when
98
91
  // subscribed to will replay the network events that have occured so far,
99
92
  // as well as subsequent events.
100
-
101
93
  var didMakeNetworkRequest = false;
102
-
103
94
  var makeNetworkRequest = function makeNetworkRequest(params) {
104
95
  // N.B. this function is called synchronously or not at all
105
96
  // didMakeNetworkRequest is safe to rely on in the returned value
@@ -110,7 +101,6 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
110
101
  didMakeNetworkRequest = true;
111
102
  var observable;
112
103
  var subject = new ReplaySubject();
113
-
114
104
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
115
105
  // Here, we are calling fetchQueryDeduped at the network layer level,
116
106
  // which ensures that only a single network request is active for a given
@@ -136,21 +126,19 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
136
126
  var network = environment.getNetwork();
137
127
  observable = network.execute(params, variables, networkCacheConfig);
138
128
  }
139
-
140
129
  var _observable$subscribe = observable.subscribe({
141
- error: function error(err) {
142
- networkError = err;
143
- subject.error(err);
144
- },
145
- next: function next(data) {
146
- subject.next(data);
147
- },
148
- complete: function complete() {
149
- subject.complete();
150
- }
151
- }),
152
- unsubscribe = _observable$subscribe.unsubscribe;
153
-
130
+ error: function error(err) {
131
+ networkError = err;
132
+ subject.error(err);
133
+ },
134
+ next: function next(data) {
135
+ subject.next(data);
136
+ },
137
+ complete: function complete() {
138
+ subject.complete();
139
+ }
140
+ }),
141
+ unsubscribe = _observable$subscribe.unsubscribe;
154
142
  unsubscribeFromNetworkRequest = unsubscribe;
155
143
  return Observable.create(function (sink) {
156
144
  var subjectSubscription = subject.subscribe(sink);
@@ -160,9 +148,7 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
160
148
  };
161
149
  });
162
150
  };
163
-
164
151
  var unsubscribeFromExecution;
165
-
166
152
  var executeDeduped = function executeDeduped(operation, fetchFn) {
167
153
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
168
154
  // N.B. at this point, if we're calling execute with a query ast (OperationDescriptor),
@@ -174,7 +160,9 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
174
160
  // so we set this to true before deduping, to guarantee that the `source`
175
161
  // observable is returned.
176
162
  didMakeNetworkRequest = true;
177
- } // Here, we are calling fetchQueryDeduped, which ensures that only
163
+ }
164
+
165
+ // Here, we are calling fetchQueryDeduped, which ensures that only
178
166
  // a single operation is active for a given (environment, identifier) pair,
179
167
  // and also tracks the active state of the operation, which is necessary
180
168
  // for our Suspense infra to later be able to suspend (or not) on
@@ -188,8 +176,6 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
188
176
  // - If no duplicate active operation is found, it will call the fetchFn
189
177
  // to execute the operation, and return an Observable that will provide
190
178
  // the events for executing the operation.
191
-
192
-
193
179
  var _fetchQueryDeduped$su = fetchQueryDeduped(environment, operation.request.identifier, fetchFn).subscribe({
194
180
  error: function error(err) {
195
181
  executionSubject.error(err);
@@ -201,23 +187,19 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
201
187
  executionSubject.complete();
202
188
  }
203
189
  });
204
-
205
190
  unsubscribeFromExecution = _fetchQueryDeduped$su.unsubscribe;
206
191
  };
207
-
208
192
  var checkAvailabilityAndExecute = function checkAvailabilityAndExecute(concreteRequest) {
209
193
  var operation = createOperationDescriptor(concreteRequest, variables, networkCacheConfig);
210
194
  retainReference = environment.retain(operation);
211
-
212
195
  if (fetchPolicy === 'store-only') {
213
196
  return;
214
- } // N.B. If the fetch policy allows fulfillment from the store but the
197
+ }
198
+
199
+ // N.B. If the fetch policy allows fulfillment from the store but the
215
200
  // environment already has the data for that operation cached in the store,
216
201
  // then we do nothing.
217
-
218
-
219
202
  var shouldFetch = fetchPolicy !== 'store-or-network' || environment.check(operation).status !== 'available';
220
-
221
203
  if (shouldFetch) {
222
204
  executeDeduped(operation, function () {
223
205
  // N.B. Since we have the operation synchronously available here,
@@ -228,20 +210,16 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
228
210
  });
229
211
  }
230
212
  };
231
-
232
213
  var params;
233
214
  var cancelOnLoadCallback;
234
215
  var queryId;
235
-
236
216
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
237
217
  var preloadableConcreteRequest = preloadableRequest;
238
218
  params = preloadableConcreteRequest.params;
239
219
  var _params = params;
240
220
  queryId = _params.id;
241
221
  !(queryId !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: `loadQuery` requires that preloadable query `%s` has a persisted query id', params.name) : invariant(false) : void 0;
242
-
243
222
  var _module = PreloadableQueryRegistry.get(queryId);
244
-
245
223
  if (_module != null) {
246
224
  checkAvailabilityAndExecute(_module);
247
225
  } else {
@@ -252,20 +230,18 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
252
230
  // ast, and we know that if we don't have the query ast
253
231
  // available, then this query could've never been written to the
254
232
  // store in the first place, so it couldn't have been cached.
255
- var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
256
-
233
+ var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params);
234
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
257
235
  var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad(queryId, function (preloadedModule) {
258
236
  cancelOnLoadCallback();
259
237
  var operation = createOperationDescriptor(preloadedModule, variables, networkCacheConfig);
260
238
  retainReference = environment.retain(operation);
261
-
262
239
  if (networkObservable != null) {
263
240
  executeDeduped(operation, function () {
264
241
  return executeWithNetworkSource(operation, networkObservable);
265
242
  });
266
243
  }
267
244
  });
268
-
269
245
  cancelOnLoadCallback = _PreloadableQueryRegi.dispose;
270
246
  }
271
247
  } else {
@@ -275,35 +251,28 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
275
251
  queryId = params.cacheID != null ? params.cacheID : params.id;
276
252
  checkAvailabilityAndExecute(request);
277
253
  }
278
-
279
254
  var isDisposed = false;
280
255
  var isReleased = false;
281
256
  var isNetworkRequestCancelled = false;
282
-
283
257
  var releaseQuery = function releaseQuery() {
284
258
  if (isReleased) {
285
259
  return;
286
260
  }
287
-
288
261
  retainReference && retainReference.dispose();
289
262
  isReleased = true;
290
263
  };
291
-
292
264
  var cancelNetworkRequest = function cancelNetworkRequest() {
293
265
  if (isNetworkRequestCancelled) {
294
266
  return;
295
267
  }
296
-
297
268
  if (didExecuteNetworkSource) {
298
269
  unsubscribeFromExecution && unsubscribeFromExecution();
299
270
  } else {
300
271
  unsubscribeFromNetworkRequest && unsubscribeFromNetworkRequest();
301
272
  }
302
-
303
273
  cancelOnLoadCallback && cancelOnLoadCallback();
304
274
  isNetworkRequestCancelled = true;
305
275
  };
306
-
307
276
  return {
308
277
  kind: 'PreloadedQuery',
309
278
  environment: environment,
@@ -312,7 +281,6 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
312
281
  if (isDisposed) {
313
282
  return;
314
283
  }
315
-
316
284
  releaseQuery();
317
285
  cancelNetworkRequest();
318
286
  isDisposed = true;
@@ -321,17 +289,14 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
321
289
  cancelNetworkRequest: cancelNetworkRequest,
322
290
  fetchKey: fetchKey,
323
291
  id: queryId,
324
-
325
292
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
326
293
  get isDisposed() {
327
294
  return isDisposed || isReleased;
328
295
  },
329
-
330
296
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
331
297
  get networkError() {
332
298
  return networkError;
333
299
  },
334
-
335
300
  name: params.name,
336
301
  networkCacheConfig: networkCacheConfig,
337
302
  fetchPolicy: fetchPolicy,
@@ -339,7 +304,6 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
339
304
  variables: variables
340
305
  };
341
306
  }
342
-
343
307
  module.exports = {
344
308
  loadQuery: loadQuery,
345
309
  useTrackLoadQueryInRender: useTrackLoadQueryInRender
@@ -4,66 +4,53 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  *
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
- // flowlint ambiguous-object-type:error
12
- 'use strict';
13
11
 
14
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
12
+ 'use strict';
15
13
 
14
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
16
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
-
18
16
  var _require = require('relay-runtime'),
19
- Observable = _require.Observable,
20
- PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
21
- RelayFeatureFlags = _require.RelayFeatureFlags,
22
- ReplaySubject = _require.ReplaySubject,
23
- createOperationDescriptor = _require.createOperationDescriptor,
24
- getRequest = _require.getRequest,
25
- getRequestIdentifier = _require.getRequestIdentifier; // Expire results by this delay after they resolve.
26
-
27
-
17
+ Observable = _require.Observable,
18
+ PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
19
+ ReplaySubject = _require.ReplaySubject,
20
+ createOperationDescriptor = _require.createOperationDescriptor,
21
+ getRequest = _require.getRequest,
22
+ getRequestIdentifier = _require.getRequestIdentifier;
23
+
24
+ // Expire results by this delay after they resolve.
28
25
  var DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
29
26
 
30
27
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
31
28
  var STORE_OR_NETWORK_DEFAULT = 'store-or-network';
32
29
  var pendingQueriesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
33
-
34
30
  function preloadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
35
31
  var _pendingQueries = pendingQueriesByEnvironment.get(environment);
36
-
37
32
  if (_pendingQueries == null) {
38
33
  _pendingQueries = new Map();
39
34
  pendingQueriesByEnvironment.set(environment, _pendingQueries);
40
35
  }
41
-
42
36
  var pendingQueries = _pendingQueries; // store in a const for flow
43
-
44
37
  var queryEntry = preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options);
45
38
  var source = queryEntry.kind === 'network' ? Observable.create(function (sink) {
46
39
  var subscription;
47
-
48
40
  if (pendingQueries.get(queryEntry.cacheKey) == null) {
49
41
  var newQueryEntry = preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options);
50
-
51
42
  if (newQueryEntry.kind === 'network') {
52
43
  subscription = newQueryEntry.subject.subscribe(sink);
53
44
  }
54
45
  } else {
55
46
  subscription = queryEntry.subject.subscribe(sink);
56
47
  }
57
-
58
48
  return function () {
59
49
  var _subscription;
60
-
61
50
  (_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.unsubscribe();
62
-
63
51
  if (environment.isServer()) {
64
52
  return;
65
53
  }
66
-
67
54
  setTimeout(function () {
68
55
  // Clear the cache entry after the default timeout
69
56
  // null-check for Flow
@@ -87,13 +74,10 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
87
74
  status: queryEntry.status
88
75
  };
89
76
  }
90
-
91
77
  function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options) {
92
78
  var _options$fetchPolicy;
93
-
94
79
  var params;
95
80
  var query;
96
-
97
81
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
98
82
  var preloadableConcreteRequest = preloadableRequest;
99
83
  params = preloadableConcreteRequest.params;
@@ -102,7 +86,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
102
86
  query = getRequest(preloadableRequest);
103
87
  params = query.params;
104
88
  }
105
-
106
89
  var network = environment.getNetwork();
107
90
  var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : STORE_OR_NETWORK_DEFAULT;
108
91
  var fetchKey = options === null || options === void 0 ? void 0 : options.fetchKey;
@@ -115,10 +98,8 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
115
98
  status: 'missing'
116
99
  };
117
100
  var nextQueryEntry;
118
-
119
101
  if (availability.status === 'available' && query != null) {
120
102
  var _availability$fetchTi;
121
-
122
103
  nextQueryEntry = prevQueryEntry && prevQueryEntry.kind === 'cache' ? prevQueryEntry : {
123
104
  cacheKey: cacheKey,
124
105
  fetchKey: fetchKey,
@@ -132,7 +113,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
132
113
  fetchTime: (_availability$fetchTi = availability === null || availability === void 0 ? void 0 : availability.fetchTime) !== null && _availability$fetchTi !== void 0 ? _availability$fetchTi : null
133
114
  }
134
115
  };
135
-
136
116
  if (!environment.isServer() && prevQueryEntry == null) {
137
117
  setTimeout(function () {
138
118
  // Clear the cache entry after the default timeout
@@ -163,7 +143,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
163
143
  if (environment.isServer()) {
164
144
  return;
165
145
  }
166
-
167
146
  setTimeout(function () {
168
147
  // Clear the cache entry after the default timeout
169
148
  // null-check for Flow
@@ -186,25 +165,20 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
186
165
  } else {
187
166
  nextQueryEntry = prevQueryEntry;
188
167
  }
189
-
190
168
  pendingQueries.set(cacheKey, nextQueryEntry);
191
169
  return nextQueryEntry;
192
170
  }
193
-
194
171
  function cleanup(pendingQueries, entry) {
195
172
  // Reload the entry by its cache key and only invalidate if its the identical
196
173
  // entry instance. This ensures that if the same query/variables are fetched
197
174
  // successively that a timeout/expiration from an earlier fetch doesn't clear
198
175
  // a subsequent fetch.
199
176
  var currentEntry = pendingQueries.get(entry.cacheKey);
200
-
201
177
  if (currentEntry != null && currentEntry === entry) {
202
178
  if (currentEntry.kind === 'network') {
203
179
  currentEntry.subscription.unsubscribe();
204
180
  }
205
-
206
181
  pendingQueries["delete"](currentEntry.cacheKey);
207
182
  }
208
183
  }
209
-
210
184
  module.exports = preloadQuery;
@@ -4,54 +4,48 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  *
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
- // flowlint ambiguous-object-type:error
11
+
12
12
  'use strict';
13
13
 
14
14
  var preloadQuery = require('./preloadQuery_DEPRECATED');
15
-
16
15
  function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
17
16
  // Start loading the code for the entrypoint
18
17
  if (entryPoint.root.getModuleIfRequired() == null) {
18
+ // $FlowFixMe[unused-promise]
19
19
  entryPoint.root.load();
20
20
  }
21
-
22
21
  var preloadProps = entryPoint.getPreloadProps(entryPointParams);
23
22
  var queries = preloadProps.queries,
24
- entryPoints = preloadProps.entryPoints;
23
+ entryPoints = preloadProps.entryPoints;
25
24
  var preloadedQueries = {};
26
25
  var preloadedEntryPoints = {};
27
-
28
26
  if (queries != null) {
29
27
  var queriesPropNames = Object.keys(queries);
30
28
  queriesPropNames.forEach(function (queryPropName) {
31
29
  var _queries$queryPropNam = queries[queryPropName],
32
- environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
33
- options = _queries$queryPropNam.options,
34
- parameters = _queries$queryPropNam.parameters,
35
- variables = _queries$queryPropNam.variables;
30
+ environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
31
+ options = _queries$queryPropNam.options,
32
+ parameters = _queries$queryPropNam.parameters,
33
+ variables = _queries$queryPropNam.variables;
36
34
  var environment = environmentProvider.getEnvironment(environmentProviderOptions);
37
35
  preloadedQueries[queryPropName] = preloadQuery(environment, parameters, variables, options, environmentProviderOptions);
38
36
  });
39
37
  }
40
-
41
38
  if (entryPoints != null) {
42
39
  var entryPointPropNames = Object.keys(entryPoints);
43
40
  entryPointPropNames.forEach(function (entryPointPropName) {
44
41
  var entryPointDescription = entryPoints[entryPointPropName];
45
-
46
42
  if (entryPointDescription == null) {
47
43
  return;
48
44
  }
49
-
50
45
  var nestedEntryPoint = entryPointDescription.entryPoint,
51
- nestedParams = entryPointDescription.entryPointParams;
46
+ nestedParams = entryPointDescription.entryPointParams;
52
47
  preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
53
48
  });
54
49
  }
55
50
  }
56
-
57
51
  module.exports = prepareEntryPoint;