react-relay 0.0.0-main-1e923be9 → 0.0.0-main-764af24d

Sign up to get free protection for your applications and to get access to all the features.
@@ -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;