react-relay 14.1.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 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +19 -5
  9. package/ReactRelayQueryRenderer.js.flow +32 -1
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +1 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  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 -0
  34. package/buildReactRelayContainer.js.flow +7 -5
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  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 -0
  46. package/lib/ReactRelayContainerUtils.js +2 -2
  47. package/lib/ReactRelayContext.js +3 -3
  48. package/lib/ReactRelayFragmentContainer.js +39 -66
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -3
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -30
  51. package/lib/ReactRelayPaginationContainer.js +66 -159
  52. package/lib/ReactRelayQueryFetcher.js +48 -74
  53. package/lib/ReactRelayQueryRenderer.js +62 -82
  54. package/lib/ReactRelayQueryRendererContext.js +2 -1
  55. package/lib/ReactRelayRefetchContainer.js +52 -99
  56. package/lib/ReactRelayTestMocker.js +32 -66
  57. package/lib/ReactRelayTypes.js +2 -0
  58. package/lib/RelayContext.js +4 -6
  59. package/lib/assertFragmentMap.js +3 -4
  60. package/lib/buildReactRelayContainer.js +10 -25
  61. package/lib/getRootVariablesForFragments.js +5 -8
  62. package/lib/hooks.js +5 -17
  63. package/lib/index.js +5 -24
  64. package/lib/isRelayEnvironment.js +5 -3
  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 -7
  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 -7
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
  74. package/lib/relay-hooks/FragmentResource.js +102 -196
  75. package/lib/relay-hooks/HooksImplementation.js +2 -5
  76. package/lib/relay-hooks/InternalLogger.js +2 -2
  77. package/lib/relay-hooks/LRUCache.js +2 -19
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
  79. package/lib/relay-hooks/MatchContainer.js +14 -22
  80. package/lib/relay-hooks/ProfilerContext.js +3 -2
  81. package/lib/relay-hooks/QueryResource.js +30 -99
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
  83. package/lib/relay-hooks/SuspenseResource.js +8 -31
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +41 -77
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
  99. package/lib/relay-hooks/useClientQuery.js +3 -6
  100. package/lib/relay-hooks/useEntryPointLoader.js +17 -36
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
  102. package/lib/relay-hooks/useFragment.js +8 -18
  103. package/lib/relay-hooks/useFragmentNode.js +20 -31
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -5
  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 +6 -9
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
  109. package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
  111. package/lib/relay-hooks/useMemoVariables.js +15 -33
  112. package/lib/relay-hooks/useMutation.js +8 -25
  113. package/lib/relay-hooks/usePaginationFragment.js +61 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +12 -29
  115. package/lib/relay-hooks/useQueryLoader.js +23 -47
  116. package/lib/relay-hooks/useRefetchableFragment.js +8 -18
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -7
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
  121. package/lib/relay-hooks/useSubscription.js +5 -9
  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 -2
  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 +1 -1
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
  135. package/relay-hooks/FragmentResource.js.flow +34 -8
  136. package/relay-hooks/HooksImplementation.js.flow +1 -1
  137. package/relay-hooks/InternalLogger.js.flow +1 -1
  138. package/relay-hooks/LRUCache.js.flow +1 -1
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
  140. package/relay-hooks/MatchContainer.js.flow +1 -1
  141. package/relay-hooks/ProfilerContext.js.flow +1 -1
  142. package/relay-hooks/QueryResource.js.flow +25 -5
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  144. package/relay-hooks/SuspenseResource.js.flow +1 -1
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  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 +35 -33
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
  153. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  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 +5 -6
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
  169. package/relay-hooks/useClientQuery.js.flow +1 -1
  170. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  171. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  172. package/relay-hooks/useFragment.js.flow +2 -2
  173. package/relay-hooks/useFragmentNode.js.flow +5 -4
  174. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  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 +2 -2
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  179. package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  181. package/relay-hooks/useMemoVariables.js.flow +13 -29
  182. package/relay-hooks/useMutation.js.flow +4 -4
  183. package/relay-hooks/usePaginationFragment.js.flow +53 -46
  184. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  185. package/relay-hooks/useQueryLoader.js.flow +85 -22
  186. package/relay-hooks/useRefetchableFragment.js.flow +64 -33
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  191. package/relay-hooks/useSubscription.js.flow +1 -1
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -27
  194. package/readContext.js.flow +0 -29
@@ -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
+
11
12
  'use strict';
12
13
 
13
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
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,65 +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
+
11
12
  'use strict';
12
13
 
13
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
16
  var _require = require('relay-runtime'),
18
- Observable = _require.Observable,
19
- PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
20
- RelayFeatureFlags = _require.RelayFeatureFlags,
21
- ReplaySubject = _require.ReplaySubject,
22
- createOperationDescriptor = _require.createOperationDescriptor,
23
- getRequest = _require.getRequest,
24
- getRequestIdentifier = _require.getRequestIdentifier; // Expire results by this delay after they resolve.
25
-
26
-
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.
27
25
  var DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
28
26
 
29
27
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
30
28
  var STORE_OR_NETWORK_DEFAULT = 'store-or-network';
31
29
  var pendingQueriesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
32
-
33
30
  function preloadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
34
31
  var _pendingQueries = pendingQueriesByEnvironment.get(environment);
35
-
36
32
  if (_pendingQueries == null) {
37
33
  _pendingQueries = new Map();
38
34
  pendingQueriesByEnvironment.set(environment, _pendingQueries);
39
35
  }
40
-
41
36
  var pendingQueries = _pendingQueries; // store in a const for flow
42
-
43
37
  var queryEntry = preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options);
44
38
  var source = queryEntry.kind === 'network' ? Observable.create(function (sink) {
45
39
  var subscription;
46
-
47
40
  if (pendingQueries.get(queryEntry.cacheKey) == null) {
48
41
  var newQueryEntry = preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options);
49
-
50
42
  if (newQueryEntry.kind === 'network') {
51
43
  subscription = newQueryEntry.subject.subscribe(sink);
52
44
  }
53
45
  } else {
54
46
  subscription = queryEntry.subject.subscribe(sink);
55
47
  }
56
-
57
48
  return function () {
58
49
  var _subscription;
59
-
60
50
  (_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.unsubscribe();
61
-
62
51
  if (environment.isServer()) {
63
52
  return;
64
53
  }
65
-
66
54
  setTimeout(function () {
67
55
  // Clear the cache entry after the default timeout
68
56
  // null-check for Flow
@@ -86,13 +74,10 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
86
74
  status: queryEntry.status
87
75
  };
88
76
  }
89
-
90
77
  function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, variables, options) {
91
78
  var _options$fetchPolicy;
92
-
93
79
  var params;
94
80
  var query;
95
-
96
81
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
97
82
  var preloadableConcreteRequest = preloadableRequest;
98
83
  params = preloadableConcreteRequest.params;
@@ -101,7 +86,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
101
86
  query = getRequest(preloadableRequest);
102
87
  params = query.params;
103
88
  }
104
-
105
89
  var network = environment.getNetwork();
106
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;
107
91
  var fetchKey = options === null || options === void 0 ? void 0 : options.fetchKey;
@@ -114,10 +98,8 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
114
98
  status: 'missing'
115
99
  };
116
100
  var nextQueryEntry;
117
-
118
101
  if (availability.status === 'available' && query != null) {
119
102
  var _availability$fetchTi;
120
-
121
103
  nextQueryEntry = prevQueryEntry && prevQueryEntry.kind === 'cache' ? prevQueryEntry : {
122
104
  cacheKey: cacheKey,
123
105
  fetchKey: fetchKey,
@@ -131,7 +113,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
131
113
  fetchTime: (_availability$fetchTi = availability === null || availability === void 0 ? void 0 : availability.fetchTime) !== null && _availability$fetchTi !== void 0 ? _availability$fetchTi : null
132
114
  }
133
115
  };
134
-
135
116
  if (!environment.isServer() && prevQueryEntry == null) {
136
117
  setTimeout(function () {
137
118
  // Clear the cache entry after the default timeout
@@ -162,7 +143,6 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
162
143
  if (environment.isServer()) {
163
144
  return;
164
145
  }
165
-
166
146
  setTimeout(function () {
167
147
  // Clear the cache entry after the default timeout
168
148
  // null-check for Flow
@@ -185,25 +165,20 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
185
165
  } else {
186
166
  nextQueryEntry = prevQueryEntry;
187
167
  }
188
-
189
168
  pendingQueries.set(cacheKey, nextQueryEntry);
190
169
  return nextQueryEntry;
191
170
  }
192
-
193
171
  function cleanup(pendingQueries, entry) {
194
172
  // Reload the entry by its cache key and only invalidate if its the identical
195
173
  // entry instance. This ensures that if the same query/variables are fetched
196
174
  // successively that a timeout/expiration from an earlier fetch doesn't clear
197
175
  // a subsequent fetch.
198
176
  var currentEntry = pendingQueries.get(entry.cacheKey);
199
-
200
177
  if (currentEntry != null && currentEntry === entry) {
201
178
  if (currentEntry.kind === 'network') {
202
179
  currentEntry.subscription.unsubscribe();
203
180
  }
204
-
205
181
  pendingQueries["delete"](currentEntry.cacheKey);
206
182
  }
207
183
  }
208
-
209
184
  module.exports = preloadQuery;
@@ -4,53 +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
+
11
12
  'use strict';
12
13
 
13
14
  var preloadQuery = require('./preloadQuery_DEPRECATED');
14
-
15
15
  function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
16
16
  // Start loading the code for the entrypoint
17
17
  if (entryPoint.root.getModuleIfRequired() == null) {
18
+ // $FlowFixMe[unused-promise]
18
19
  entryPoint.root.load();
19
20
  }
20
-
21
21
  var preloadProps = entryPoint.getPreloadProps(entryPointParams);
22
22
  var queries = preloadProps.queries,
23
- entryPoints = preloadProps.entryPoints;
23
+ entryPoints = preloadProps.entryPoints;
24
24
  var preloadedQueries = {};
25
25
  var preloadedEntryPoints = {};
26
-
27
26
  if (queries != null) {
28
27
  var queriesPropNames = Object.keys(queries);
29
28
  queriesPropNames.forEach(function (queryPropName) {
30
29
  var _queries$queryPropNam = queries[queryPropName],
31
- environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
32
- options = _queries$queryPropNam.options,
33
- parameters = _queries$queryPropNam.parameters,
34
- variables = _queries$queryPropNam.variables;
30
+ environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
31
+ options = _queries$queryPropNam.options,
32
+ parameters = _queries$queryPropNam.parameters,
33
+ variables = _queries$queryPropNam.variables;
35
34
  var environment = environmentProvider.getEnvironment(environmentProviderOptions);
36
35
  preloadedQueries[queryPropName] = preloadQuery(environment, parameters, variables, options, environmentProviderOptions);
37
36
  });
38
37
  }
39
-
40
38
  if (entryPoints != null) {
41
39
  var entryPointPropNames = Object.keys(entryPoints);
42
40
  entryPointPropNames.forEach(function (entryPointPropName) {
43
41
  var entryPointDescription = entryPoints[entryPointPropName];
44
-
45
42
  if (entryPointDescription == null) {
46
43
  return;
47
44
  }
48
-
49
45
  var nestedEntryPoint = entryPointDescription.entryPoint,
50
- nestedParams = entryPointDescription.entryPointParams;
46
+ nestedParams = entryPointDescription.entryPointParams;
51
47
  preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
52
48
  });
53
49
  }
54
50
  }
55
-
56
51
  module.exports = prepareEntryPoint;