react-relay 16.0.0 → 16.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayTypes.js.flow +1 -0
  3. package/hooks.js +1 -1
  4. package/hooks.js.flow +1 -1
  5. package/index.js +1 -1
  6. package/index.js.flow +1 -1
  7. package/legacy.js +1 -1
  8. package/lib/relay-hooks/HooksImplementation.js +1 -1
  9. package/lib/relay-hooks/SuspenseResource.js +7 -4
  10. package/lib/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js → experimental/readFragmentInternal_EXPERIMENTAL.js} +4 -4
  11. package/lib/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js → experimental/useFragmentInternal_EXPERIMENTAL.js} +63 -29
  12. package/lib/relay-hooks/{react-cache/useFragment_REACT_CACHE.js → experimental/useFragment_EXPERIMENTAL.js} +1 -1
  13. package/lib/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js → experimental/usePaginationFragment_EXPERIMENTAL.js} +1 -1
  14. package/lib/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js} +2 -2
  15. package/lib/relay-hooks/{react-cache/useRefetchableFragment_REACT_CACHE.js → experimental/useRefetchableFragment_EXPERIMENTAL.js} +1 -1
  16. package/lib/relay-hooks/{FragmentResource.js → legacy/FragmentResource.js} +7 -6
  17. package/lib/relay-hooks/{useBlockingPaginationFragment.js → legacy/useBlockingPaginationFragment.js} +2 -2
  18. package/lib/relay-hooks/{useFragmentNode.js → legacy/useFragmentNode.js} +2 -2
  19. package/lib/relay-hooks/{useRefetchableFragmentNode.js → legacy/useRefetchableFragmentNode.js} +8 -8
  20. package/lib/relay-hooks/useFragment.js +1 -1
  21. package/lib/relay-hooks/useLazyLoadQueryNode.js +13 -3
  22. package/lib/relay-hooks/usePaginationFragment.js +1 -1
  23. package/lib/relay-hooks/useRefetchableFragment.js +1 -1
  24. package/package.json +2 -2
  25. package/react-relay-hooks.js +2 -2
  26. package/react-relay-hooks.min.js +2 -2
  27. package/react-relay-legacy.js +2 -2
  28. package/react-relay-legacy.min.js +2 -2
  29. package/react-relay.js +2 -2
  30. package/react-relay.min.js +2 -2
  31. package/relay-hooks/EntryPointTypes.flow.js.flow +25 -33
  32. package/relay-hooks/HooksImplementation.js.flow +3 -1
  33. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +5 -11
  34. package/relay-hooks/SuspenseResource.js.flow +11 -8
  35. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +1 -1
  36. package/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js.flow → experimental/readFragmentInternal_EXPERIMENTAL.js.flow} +4 -2
  37. package/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js.flow → experimental/useFragmentInternal_EXPERIMENTAL.js.flow} +61 -18
  38. package/relay-hooks/{react-cache/useFragment_REACT_CACHE.js.flow → experimental/useFragment_EXPERIMENTAL.js.flow} +10 -4
  39. package/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js.flow → experimental/usePaginationFragment_EXPERIMENTAL.js.flow} +2 -2
  40. package/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow} +11 -11
  41. package/relay-hooks/{react-cache/useRefetchableFragment_REACT_CACHE.js.flow → experimental/useRefetchableFragment_EXPERIMENTAL.js.flow} +1 -1
  42. package/relay-hooks/{FragmentResource.js.flow → legacy/FragmentResource.js.flow} +8 -5
  43. package/relay-hooks/{useBlockingPaginationFragment.js.flow → legacy/useBlockingPaginationFragment.js.flow} +13 -18
  44. package/relay-hooks/{useFragmentNode.js.flow → legacy/useFragmentNode.js.flow} +2 -2
  45. package/relay-hooks/{useRefetchableFragmentNode.js.flow → legacy/useRefetchableFragmentNode.js.flow} +12 -14
  46. package/relay-hooks/loadQuery.js.flow +1 -1
  47. package/relay-hooks/useFragment.js.flow +10 -4
  48. package/relay-hooks/useLazyLoadQueryNode.js.flow +18 -2
  49. package/relay-hooks/usePaginationFragment.js.flow +7 -9
  50. package/relay-hooks/useRefetchableFragment.js.flow +15 -18
  51. package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -20
  52. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +0 -255
  53. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -33
  54. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -81
  55. package/relay-hooks/react-cache/RelayReactCache.js.flow +0 -40
  56. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +0 -430
  57. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +0 -70
  58. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +0 -150
@@ -11,9 +11,9 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ import type {Options} from './legacy/useRefetchableFragmentNode';
14
15
  import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
15
16
  import type {RefetchFn} from './useRefetchableFragment';
16
- import type {Options} from './useRefetchableFragmentNode';
17
17
  import type {
18
18
  FragmentType,
19
19
  GraphQLResponse,
@@ -23,8 +23,8 @@ import type {
23
23
  } from 'relay-runtime';
24
24
 
25
25
  const HooksImplementation = require('./HooksImplementation');
26
+ const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
26
27
  const useLoadMoreFunction = require('./useLoadMoreFunction');
27
- const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
28
28
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
29
29
  const {useCallback, useDebugValue, useState} = require('react');
30
30
  const {
@@ -157,15 +157,12 @@ function useLoadMore<TVariables: Variables>(
157
157
  }
158
158
 
159
159
  export type ReturnType<TVariables, TData, TKey> = {
160
- // NOTE: This $Call ensures that the type of the returned data is either:
160
+ // NOTE: This type ensures that the type of the returned data is either:
161
161
  // - nullable if the provided ref type is nullable
162
162
  // - non-nullable if the provided ref type is non-nullable
163
- // prettier-ignore
164
- data: $Call<
165
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
166
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
167
- TKey,
168
- >,
163
+ data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
164
+ ? TData
165
+ : ?TData,
169
166
  loadNext: LoadMoreFn<TVariables>,
170
167
  loadPrevious: LoadMoreFn<TVariables>,
171
168
  hasNext: boolean,
@@ -186,6 +183,7 @@ function usePaginationFragment<
186
183
  ): ReturnType<TVariables, TData, TKey> {
187
184
  const impl = HooksImplementation.get();
188
185
  if (impl) {
186
+ // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
189
187
  return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
190
188
  fragmentInput,
191
189
  parentFragmentRef,
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {Options} from './useRefetchableFragmentNode';
14
+ import type {Options} from './legacy/useRefetchableFragmentNode';
15
15
  import type {
16
16
  Disposable,
17
17
  FragmentType,
@@ -20,21 +20,18 @@ import type {
20
20
  } from 'relay-runtime';
21
21
 
22
22
  const HooksImplementation = require('./HooksImplementation');
23
- const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
23
+ const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
24
24
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
25
25
  const {useDebugValue} = require('react');
26
26
  const {getFragment} = require('relay-runtime');
27
27
 
28
- type RefetchVariables<TVariables, TKey> =
29
- // NOTE: This $Call ensures that the type of the returned variables is either:
28
+ type RefetchVariables<TVariables, TKey: ?{+$fragmentSpreads: mixed, ...}> =
29
+ // NOTE: This type ensures that the type of the returned variables is either:
30
30
  // - nullable if the provided ref type is nullable
31
31
  // - non-nullable if the provided ref type is non-nullable
32
- // prettier-ignore
33
- $Call<
34
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
35
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
36
- TKey,
37
- >;
32
+ [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
33
+ ? Partial<TVariables>
34
+ : TVariables;
38
35
 
39
36
  type RefetchFnBase<TVars, TOptions> = (
40
37
  vars: TVars,
@@ -46,16 +43,15 @@ export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
46
43
  TOptions,
47
44
  >;
48
45
 
49
- export type ReturnType<TVariables, TData, TKey> = [
50
- // NOTE: This $Call ensures that the type of the returned data is either:
46
+ export type ReturnType<
47
+ TVariables,
48
+ TData,
49
+ TKey: ?{+$fragmentSpreads: mixed, ...},
50
+ > = [
51
+ // NOTE: This type ensures that the type of the returned data is either:
51
52
  // - nullable if the provided ref type is nullable
52
53
  // - non-nullable if the provided ref type is non-nullable
53
- // prettier-ignore
54
- $Call<
55
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
56
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
57
- TKey,
58
- >,
54
+ [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}] ? TData : ?TData,
59
55
  RefetchFn<TVariables, TKey>,
60
56
  ];
61
57
 
@@ -115,6 +111,7 @@ function useRefetchableFragment<
115
111
  ): ReturnType<TVariables, TData, TKey> {
116
112
  const impl = HooksImplementation.get();
117
113
  if (impl) {
114
+ // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
118
115
  return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
119
116
  fragmentInput,
120
117
  parentFragmentRef,
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- var invariant = require('invariant');
4
- var _require = require('react'),
5
- unstable_getCacheForType = _require.unstable_getCacheForType,
6
- unstable_getCacheSignal = _require.unstable_getCacheSignal;
7
- var _require2 = require('relay-runtime'),
8
- RelayFeatureFlags = _require2.RelayFeatureFlags;
9
- function getCacheForType(factory) {
10
- !(typeof unstable_getCacheForType === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
11
- return unstable_getCacheForType(factory);
12
- }
13
- function getCacheSignal() {
14
- !(typeof unstable_getCacheSignal === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
15
- return unstable_getCacheSignal();
16
- }
17
- module.exports = {
18
- getCacheForType: getCacheForType,
19
- getCacheSignal: getCacheSignal
20
- };
@@ -1,255 +0,0 @@
1
- 'use strict';
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
6
- var SuspenseResource = require('../SuspenseResource');
7
- var _require = require('./RelayReactCache'),
8
- getCacheForType = _require.getCacheForType,
9
- getCacheSignal = _require.getCacheSignal;
10
- var invariant = require('invariant');
11
- var _require2 = require('relay-runtime'),
12
- fetchQueryInternal = _require2.__internal.fetchQuery,
13
- RelayFeatureFlags = _require2.RelayFeatureFlags;
14
- var warning = require("fbjs/lib/warning");
15
- var DEFAULT_FETCH_POLICY = 'store-or-network';
16
- var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
17
- var QueryCache = /*#__PURE__*/function () {
18
- function QueryCache() {
19
- this._map = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
20
- }
21
- var _proto = QueryCache.prototype;
22
- _proto.get = function get(environment, key) {
23
- var forEnv = this._map.get(environment);
24
- if (!forEnv) {
25
- forEnv = new Map();
26
- this._map.set(environment, forEnv);
27
- }
28
- return forEnv.get(key);
29
- };
30
- _proto.set = function set(environment, key, value) {
31
- var forEnv = this._map.get(environment);
32
- if (!forEnv) {
33
- forEnv = new Map();
34
- this._map.set(environment, forEnv);
35
- }
36
- forEnv.set(key, value);
37
- };
38
- _proto["delete"] = function _delete(environment, key) {
39
- var forEnv = this._map.get(environment);
40
- if (!forEnv) {
41
- return;
42
- }
43
- forEnv["delete"](key);
44
- if (forEnv.size === 0) {
45
- this._map["delete"](environment);
46
- }
47
- };
48
- return QueryCache;
49
- }();
50
- function createQueryCache() {
51
- return new QueryCache();
52
- }
53
- var noopOnCommit = function noopOnCommit() {
54
- return function () {
55
- return undefined;
56
- };
57
- };
58
- var noopPromise = new Promise(function () {});
59
- function getQueryCacheKey(operation, fetchPolicy, renderPolicy, fetchKey) {
60
- return "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
61
- }
62
- function constructQueryResult(operation) {
63
- var rootFragmentRef = {
64
- __id: operation.fragment.dataID,
65
- __fragments: (0, _defineProperty2["default"])({}, operation.fragment.node.name, operation.request.variables),
66
- __fragmentOwner: operation.request
67
- };
68
- return {
69
- fragmentNode: operation.request.node.fragment,
70
- fragmentRef: rootFragmentRef
71
- };
72
- }
73
- function makeInitialCacheEntry() {
74
- return {
75
- status: 'pending',
76
- promise: noopPromise,
77
- onCommit: noopOnCommit,
78
- suspenseResource: null
79
- };
80
- }
81
- function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescriptor, options) {
82
- var _options$fetchPolicy, _options$renderPolicy;
83
- var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : DEFAULT_FETCH_POLICY;
84
- var renderPolicy = (_options$renderPolicy = options === null || options === void 0 ? void 0 : options.renderPolicy) !== null && _options$renderPolicy !== void 0 ? _options$renderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
85
- var cache = getCacheForType(createQueryCache);
86
- var cacheKey = getQueryCacheKey(queryOperationDescriptor, fetchPolicy, renderPolicy, options === null || options === void 0 ? void 0 : options.fetchKey);
87
- var initialEntry = cache.get(environment, cacheKey);
88
- function updateCache(updater) {
89
- var currentEntry = cache.get(environment, cacheKey);
90
- if (!currentEntry) {
91
- currentEntry = makeInitialCacheEntry();
92
- cache.set(environment, cacheKey, currentEntry);
93
- }
94
- var newStatus = updater(currentEntry);
95
- cache.set(environment, cacheKey, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentEntry), newStatus));
96
- }
97
- if (RelayFeatureFlags.USE_REACT_CACHE_LEGACY_TIMEOUTS) {
98
- var _entry;
99
- if (initialEntry === undefined) {
100
- onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
101
- var createdEntry = cache.get(environment, cacheKey);
102
- !(createdEntry !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'An entry should have been created by onCacheMiss. This is a bug in Relay.') : invariant(false) : void 0;
103
- _entry = createdEntry;
104
- } else {
105
- _entry = initialEntry;
106
- }
107
- if (!_entry.suspenseResource) {
108
- _entry.suspenseResource = new SuspenseResource(function () {
109
- var retention = environment.retain(queryOperationDescriptor);
110
- return {
111
- dispose: function dispose() {
112
- retention.dispose();
113
- cache["delete"](environment, cacheKey);
114
- }
115
- };
116
- });
117
- }
118
- if (_entry.onCommit === noopOnCommit) {
119
- _entry.onCommit = function () {
120
- !_entry.suspenseResource ? process.env.NODE_ENV !== "production" ? invariant(false, 'SuspenseResource should have been initialized. This is a bug in Relay.') : invariant(false) : void 0;
121
- var retention = _entry.suspenseResource.permanentRetain(environment);
122
- return function () {
123
- retention.dispose();
124
- };
125
- };
126
- }
127
- _entry.suspenseResource.temporaryRetain(environment);
128
- } else {
129
- if (initialEntry === undefined) {
130
- onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
131
- var retention = environment.retain(queryOperationDescriptor);
132
- var dispose = function dispose() {
133
- retention.dispose();
134
- cache["delete"](environment, cacheKey);
135
- };
136
- var abortSignal = getCacheSignal();
137
- abortSignal.addEventListener('abort', dispose, {
138
- once: true
139
- });
140
- }
141
- }
142
- var entry = cache.get(environment, cacheKey);
143
- !(entry !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'An entry should have been created by onCacheMiss. This is a bug in Relay.') : invariant(false) : void 0;
144
- switch (entry.status) {
145
- case 'pending':
146
- throw entry.promise;
147
- case 'rejected':
148
- throw entry.error;
149
- case 'resolved':
150
- return [entry.result, entry.onCommit];
151
- }
152
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'switch statement should be exhaustive') : invariant(false) : void 0;
153
- }
154
- function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCache, customFetchObservable) {
155
- var queryAvailability = environment.check(operation);
156
- var queryStatus = queryAvailability.status;
157
- var hasFullQuery = queryStatus === 'available';
158
- var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
159
- var shouldFetch;
160
- var shouldRenderNow;
161
- switch (fetchPolicy) {
162
- case 'store-only':
163
- {
164
- shouldFetch = false;
165
- shouldRenderNow = true;
166
- break;
167
- }
168
- case 'store-or-network':
169
- {
170
- shouldFetch = !hasFullQuery;
171
- shouldRenderNow = canPartialRender;
172
- break;
173
- }
174
- case 'store-and-network':
175
- {
176
- shouldFetch = true;
177
- shouldRenderNow = canPartialRender;
178
- break;
179
- }
180
- case 'network-only':
181
- default:
182
- {
183
- shouldFetch = true;
184
- shouldRenderNow = false;
185
- break;
186
- }
187
- }
188
- if (shouldFetch) {
189
- executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable);
190
- updateCache(function (existing) {
191
- switch (existing.status) {
192
- case 'resolved':
193
- return existing;
194
- case 'rejected':
195
- return existing;
196
- case 'pending':
197
- return shouldRenderNow ? {
198
- status: 'resolved',
199
- result: constructQueryResult(operation)
200
- } : existing;
201
- }
202
- });
203
- } else {
204
- !shouldRenderNow ? process.env.NODE_ENV !== "production" ? invariant(false, 'Should either fetch or be willing to render. This is a bug in Relay.') : invariant(false) : void 0;
205
- updateCache(function (_existing) {
206
- return {
207
- status: 'resolved',
208
- result: constructQueryResult(operation)
209
- };
210
- });
211
- }
212
- }
213
- function executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable) {
214
- var resolvePromise;
215
- var promise = new Promise(function (r) {
216
- resolvePromise = r;
217
- });
218
- promise.displayName = 'Relay(' + operation.request.node.operation.name + ')';
219
- var isFirstPayload = true;
220
- var fetchObservable = customFetchObservable !== null && customFetchObservable !== void 0 ? customFetchObservable : fetchQueryInternal(environment, operation);
221
- fetchObservable.subscribe({
222
- start: function start(subscription) {},
223
- error: function error(_error) {
224
- if (isFirstPayload) {
225
- updateCache(function (_existing) {
226
- return {
227
- status: 'rejected',
228
- error: _error
229
- };
230
- });
231
- } else {
232
- process.env.NODE_ENV !== "production" ? warning(false, 'getQueryResultOrFetchQuery: An incremental payload for query `%` returned an error: `%`:`%`.', operation.request.node.operation.name, _error.message, _error.stack) : void 0;
233
- }
234
- resolvePromise();
235
- isFirstPayload = false;
236
- },
237
- next: function next(response) {
238
- updateCache(function (_existing) {
239
- return {
240
- status: 'resolved',
241
- result: constructQueryResult(operation)
242
- };
243
- });
244
- resolvePromise();
245
- isFirstPayload = false;
246
- }
247
- });
248
- updateCache(function (existing) {
249
- return existing.status === 'pending' ? {
250
- status: 'pending',
251
- promise: promise
252
- } : existing;
253
- });
254
- }
255
- module.exports = getQueryResultOrFetchQuery_REACT_CACHE;
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- var _require = require('../loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
- var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
6
- var useRelayEnvironment = require('../useRelayEnvironment');
7
- var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
8
- var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
9
- var _require2 = require('react'),
10
- useEffect = _require2.useEffect;
11
- function useLazyLoadQuery_REACT_CACHE(gqlQuery, variables, options) {
12
- var _options$networkCache;
13
- useTrackLoadQueryInRender();
14
- var environment = useRelayEnvironment();
15
- var queryOperationDescriptor = useMemoOperationDescriptor(gqlQuery, variables, (_options$networkCache = options === null || options === void 0 ? void 0 : options.networkCacheConfig) !== null && _options$networkCache !== void 0 ? _options$networkCache : {
16
- force: true
17
- });
18
- var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, queryOperationDescriptor, {
19
- fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
20
- renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
21
- fetchKey: options === null || options === void 0 ? void 0 : options.fetchKey
22
- }),
23
- queryResult = _getQueryResultOrFetc[0],
24
- effect = _getQueryResultOrFetc[1];
25
- useEffect(effect);
26
- var fragmentNode = queryResult.fragmentNode,
27
- fragmentRef = queryResult.fragmentRef;
28
- return useFragmentInternal(fragmentNode, fragmentRef, 'useLazyLoadQuery()', {
29
- fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
30
- networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig
31
- });
32
- }
33
- module.exports = useLazyLoadQuery_REACT_CACHE;
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- var _require = require('../loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
- var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
6
- var useRelayEnvironment = require('../useRelayEnvironment');
7
- var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
8
- var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
9
- var invariant = require('invariant');
10
- var _require2 = require('react'),
11
- useDebugValue = _require2.useDebugValue,
12
- useEffect = _require2.useEffect;
13
- var _require3 = require('relay-runtime'),
14
- _require3$__internal = _require3.__internal,
15
- fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
16
- fetchQuery = _require3$__internal.fetchQuery;
17
- var warning = require("fbjs/lib/warning");
18
- function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
19
- var environment = useRelayEnvironment();
20
- useTrackLoadQueryInRender();
21
- var fetchKey = preloadedQuery.fetchKey,
22
- fetchPolicy = preloadedQuery.fetchPolicy,
23
- source = preloadedQuery.source,
24
- variables = preloadedQuery.variables,
25
- networkCacheConfig = preloadedQuery.networkCacheConfig;
26
- var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
27
- var fetchObservable;
28
- if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
29
- !(operation.request.node.params.name === preloadedQuery.name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' + 'got prefetch results for query `%s`.', operation.request.node.params.name, preloadedQuery.name) : invariant(false) : void 0;
30
- fetchObservable = fetchQueryDeduped(environment, operation.request.identifier, function () {
31
- if (environment === preloadedQuery.environment && source != null) {
32
- return environment.executeWithSource({
33
- operation: operation,
34
- source: source
35
- });
36
- } else {
37
- return environment.execute({
38
- operation: operation
39
- });
40
- }
41
- });
42
- } else {
43
- process.env.NODE_ENV !== "production" ? warning(preloadedQuery.isDisposed === false, 'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' + 'This is because disposing the query marks it for future garbage ' + 'collection, and as such query results may no longer be present in the Relay ' + 'store. In the future, this will become a hard error.') : void 0;
44
- var fallbackFetchObservable = fetchQuery(environment, operation);
45
- if (source != null && environment === preloadedQuery.environment) {
46
- fetchObservable = source.ifEmpty(fallbackFetchObservable);
47
- } else if (environment !== preloadedQuery.environment) {
48
- process.env.NODE_ENV !== "production" ? warning(false, 'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' + 'that was created with a different environment than the one that is currently ' + 'in context. In the future, this will become a hard error.') : void 0;
49
- fetchObservable = fallbackFetchObservable;
50
- } else {
51
- fetchObservable = fallbackFetchObservable;
52
- }
53
- }
54
- var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, operation, {
55
- fetchPolicy: fetchPolicy,
56
- renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
57
- fetchKey: fetchKey,
58
- fetchObservable: fetchObservable
59
- }),
60
- queryResult = _getQueryResultOrFetc[0],
61
- effect = _getQueryResultOrFetc[1];
62
- useEffect(effect);
63
- var fragmentNode = queryResult.fragmentNode,
64
- fragmentRef = queryResult.fragmentRef;
65
- var data = useFragmentInternal(fragmentNode, fragmentRef, 'usePreloadedQuery()', {
66
- fetchPolicy: fetchPolicy,
67
- networkCacheConfig: networkCacheConfig
68
- });
69
- if (process.env.NODE_ENV !== "production") {
70
- useDebugValue({
71
- query: preloadedQuery.name,
72
- variables: preloadedQuery.variables,
73
- data: data,
74
- fetchKey: fetchKey,
75
- fetchPolicy: fetchPolicy,
76
- renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
77
- });
78
- }
79
- return data;
80
- }
81
- module.exports = usePreloadedQuery_REACT_CACHE;
@@ -1,40 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- * @flow strict-local
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
- 'use strict';
13
-
14
- const invariant = require('invariant');
15
- // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
16
- const {unstable_getCacheForType, unstable_getCacheSignal} = require('react');
17
- const {RelayFeatureFlags} = require('relay-runtime');
18
-
19
- function getCacheForType<T>(factory: () => T): T {
20
- invariant(
21
- typeof unstable_getCacheForType === 'function' &&
22
- RelayFeatureFlags.USE_REACT_CACHE,
23
- 'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.',
24
- );
25
- return unstable_getCacheForType(factory);
26
- }
27
-
28
- function getCacheSignal(): AbortSignal {
29
- invariant(
30
- typeof unstable_getCacheSignal === 'function' &&
31
- RelayFeatureFlags.USE_REACT_CACHE,
32
- 'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.',
33
- );
34
- return unstable_getCacheSignal();
35
- }
36
-
37
- module.exports = {
38
- getCacheForType,
39
- getCacheSignal,
40
- };