react-relay 0.0.0-main-9ee9d8d0 → 0.0.0-main-6e8b52f6
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/relay-hooks/react-cache/RelayReactCache.js +37 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +197 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +400 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +45 -0
- package/package.json +2 -2
- package/react-relay-hooks.js +1 -1
- package/react-relay-hooks.min.js +1 -1
- package/react-relay-legacy.js +1 -1
- package/react-relay-legacy.min.js +1 -1
- package/react-relay.js +1 -1
- package/react-relay.min.js +1 -1
- package/relay-hooks/FragmentResource.js.flow +1 -1
- package/relay-hooks/react-cache/RelayReactCache.js.flow +42 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +243 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +418 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +66 -0
@@ -0,0 +1,66 @@
|
|
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
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
// flowlint ambiguous-object-type:error
|
13
|
+
|
14
|
+
'use strict';
|
15
|
+
|
16
|
+
import type {
|
17
|
+
CacheConfig,
|
18
|
+
FetchPolicy,
|
19
|
+
Query,
|
20
|
+
RenderPolicy,
|
21
|
+
Variables,
|
22
|
+
} from 'relay-runtime';
|
23
|
+
|
24
|
+
const {useTrackLoadQueryInRender} = require('../loadQuery');
|
25
|
+
const useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
26
|
+
const useRelayEnvironment = require('../useRelayEnvironment');
|
27
|
+
const getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
28
|
+
const useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
29
|
+
|
30
|
+
function useLazyLoadQuery_REACT_CACHE<TVariables: Variables, TData>(
|
31
|
+
gqlQuery: Query<TVariables, TData>,
|
32
|
+
variables: TVariables,
|
33
|
+
options?: {|
|
34
|
+
fetchKey?: string | number,
|
35
|
+
fetchPolicy?: FetchPolicy,
|
36
|
+
networkCacheConfig?: CacheConfig,
|
37
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
38
|
+
|},
|
39
|
+
): TData {
|
40
|
+
useTrackLoadQueryInRender();
|
41
|
+
const environment = useRelayEnvironment();
|
42
|
+
|
43
|
+
const queryOperationDescriptor = useMemoOperationDescriptor(
|
44
|
+
gqlQuery,
|
45
|
+
variables,
|
46
|
+
options?.networkCacheConfig ?? {force: true},
|
47
|
+
);
|
48
|
+
|
49
|
+
// Get the query going if needed -- this may suspend.
|
50
|
+
const queryResult = getQueryResultOrFetchQuery(
|
51
|
+
environment,
|
52
|
+
queryOperationDescriptor,
|
53
|
+
options?.fetchPolicy,
|
54
|
+
);
|
55
|
+
|
56
|
+
// Read the query's root fragment -- this may suspend.
|
57
|
+
const {fragmentNode, fragmentRef} = queryResult;
|
58
|
+
|
59
|
+
// $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
60
|
+
return useFragmentInternal(fragmentNode, fragmentRef, 'useLazyLoadQuery()', {
|
61
|
+
fetchPolicy: options?.fetchPolicy,
|
62
|
+
networkCacheConfig: options?.networkCacheConfig,
|
63
|
+
}).data;
|
64
|
+
}
|
65
|
+
|
66
|
+
module.exports = useLazyLoadQuery_REACT_CACHE;
|