react-relay 12.0.0 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +1 -1
- package/README.md +47 -0
- package/ReactRelayContainerUtils.js.flow +1 -1
- package/ReactRelayContext.js +2 -2
- package/ReactRelayContext.js.flow +3 -4
- package/ReactRelayFragmentContainer.js.flow +11 -17
- package/ReactRelayFragmentMockRenderer.js.flow +2 -2
- package/ReactRelayLocalQueryRenderer.js.flow +7 -8
- package/ReactRelayPaginationContainer.js.flow +30 -40
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +16 -16
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +25 -33
- package/ReactRelayTestMocker.js.flow +17 -15
- package/ReactRelayTypes.js.flow +11 -11
- package/RelayContext.js.flow +4 -4
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +2 -3
- package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +14 -11
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +14 -11
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +14 -9
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +14 -11
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +14 -9
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +14 -11
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +16 -13
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +16 -13
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +14 -11
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +14 -11
- package/assertFragmentMap.js.flow +3 -3
- package/buildReactRelayContainer.js.flow +12 -11
- package/getRootVariablesForFragments.js.flow +3 -5
- package/hooks.js +2 -2
- package/hooks.js.flow +4 -6
- package/index.js +2 -2
- package/index.js.flow +5 -7
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/enqueueTask.js.flow +2 -2
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +2 -4
- package/legacy.js +2 -2
- package/legacy.js.flow +1 -1
- package/lib/ReactRelayContainerUtils.js +1 -1
- package/lib/ReactRelayContext.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +5 -5
- package/lib/ReactRelayFragmentMockRenderer.js +3 -3
- package/lib/ReactRelayLocalQueryRenderer.js +8 -9
- package/lib/ReactRelayPaginationContainer.js +19 -23
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +5 -5
- package/lib/ReactRelayQueryRendererContext.js +1 -1
- package/lib/ReactRelayRefetchContainer.js +13 -15
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +4 -3
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +8 -8
- package/lib/getRootVariablesForFragments.js +2 -3
- package/lib/hooks.js +6 -6
- package/lib/index.js +8 -8
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/jest-react/enqueueTask.js +1 -1
- package/lib/jest-react/internalAct.js +3 -4
- package/lib/legacy.js +1 -1
- package/lib/multi-actor/ActorChange.js +3 -3
- package/lib/multi-actor/index.js +1 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +3 -3
- package/lib/readContext.js +1 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
- package/lib/relay-hooks/FragmentResource.js +242 -46
- package/lib/relay-hooks/InternalLogger.js +1 -1
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +1 -1
- package/lib/relay-hooks/QueryResource.js +84 -5
- package/lib/relay-hooks/RelayEnvironmentProvider.js +1 -1
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadEntryPoint.js +1 -1
- package/lib/relay-hooks/loadQuery.js +9 -10
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -11
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
- package/lib/relay-hooks/useBlockingPaginationFragment.js +3 -3
- package/lib/relay-hooks/useEntryPointLoader.js +3 -3
- package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
- package/lib/relay-hooks/useFragment.js +7 -7
- package/lib/relay-hooks/useFragmentNode.js +5 -5
- package/lib/relay-hooks/useIsMountedRef.js +1 -1
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
- package/lib/relay-hooks/useLazyLoadQueryNode.js +5 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +8 -10
- package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
- package/lib/relay-hooks/useMemoVariables.js +3 -3
- package/lib/relay-hooks/useMutation.js +18 -7
- package/lib/relay-hooks/usePaginationFragment.js +1 -1
- package/lib/relay-hooks/usePreloadedQuery.js +6 -6
- package/lib/relay-hooks/useQueryLoader.js +5 -5
- package/lib/relay-hooks/useRefetchableFragment.js +1 -1
- package/lib/relay-hooks/useRefetchableFragmentNode.js +11 -13
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
- package/lib/relay-hooks/useSubscription.js +1 -1
- package/multi-actor/ActorChange.js.flow +4 -5
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +6 -8
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +3 -3
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +3 -3
- package/react-relay.js +2 -2
- package/react-relay.min.js +3 -3
- package/readContext.js.flow +1 -1
- package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
- package/relay-hooks/EntryPointTypes.flow.js.flow +19 -25
- package/relay-hooks/FragmentResource.js.flow +221 -35
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
- package/relay-hooks/MatchContainer.js.flow +4 -3
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +120 -18
- package/relay-hooks/RelayEnvironmentProvider.js.flow +10 -10
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/utils.js.flow +21 -32
- package/relay-hooks/loadEntryPoint.js.flow +7 -13
- package/relay-hooks/loadQuery.js.flow +23 -24
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +30 -14
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
- package/relay-hooks/useBlockingPaginationFragment.js.flow +13 -14
- package/relay-hooks/useEntryPointLoader.js.flow +8 -11
- package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
- package/relay-hooks/useFragment.js.flow +31 -62
- package/relay-hooks/useFragmentNode.js.flow +6 -8
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
- package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
- package/relay-hooks/useLazyLoadQueryNode.js.flow +12 -14
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -28
- package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
- package/relay-hooks/useMemoVariables.js.flow +7 -7
- package/relay-hooks/useMutation.js.flow +27 -27
- package/relay-hooks/usePaginationFragment.js.flow +38 -47
- package/relay-hooks/usePreloadedQuery.js.flow +14 -20
- package/relay-hooks/useQueryLoader.js.flow +14 -17
- package/relay-hooks/useRefetchableFragment.js.flow +8 -9
- package/relay-hooks/useRefetchableFragmentNode.js.flow +23 -31
- package/relay-hooks/useRelayEnvironment.js.flow +3 -5
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
- package/relay-hooks/useSubscription.js.flow +7 -8
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -12,15 +12,6 @@
|
|
12
12
|
// flowlint ambiguous-object-type:error
|
13
13
|
|
14
14
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
15
|
-
import usePaginationFragment from '../usePaginationFragment';
|
16
|
-
import {
|
17
|
-
fragmentInput,
|
18
|
-
fragmentData,
|
19
|
-
keyAnotherNonNullable,
|
20
|
-
keyAnotherNullable,
|
21
|
-
keyNonNullable,
|
22
|
-
keyNullable,
|
23
|
-
} from './utils';
|
24
15
|
import type {
|
25
16
|
FetchFn,
|
26
17
|
NonNullableData,
|
@@ -31,6 +22,16 @@ import type {
|
|
31
22
|
} from './utils';
|
32
23
|
import type {IEnvironment, OperationType} from 'relay-runtime';
|
33
24
|
|
25
|
+
import usePaginationFragment from '../usePaginationFragment';
|
26
|
+
import {
|
27
|
+
fragmentData,
|
28
|
+
fragmentInput,
|
29
|
+
keyAnotherNonNullable,
|
30
|
+
keyAnotherNullable,
|
31
|
+
keyNonNullable,
|
32
|
+
keyNullable,
|
33
|
+
} from './utils';
|
34
|
+
|
34
35
|
type ExpectedReturnType<
|
35
36
|
TQuery: OperationType,
|
36
37
|
TQueryVariables,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -11,15 +11,6 @@
|
|
11
11
|
|
12
12
|
// flowlint ambiguous-object-type:error
|
13
13
|
|
14
|
-
import useRefetchableFragment from '../useRefetchableFragment';
|
15
|
-
import {
|
16
|
-
fragmentInput,
|
17
|
-
keyAnotherNonNullable,
|
18
|
-
keyAnotherNullable,
|
19
|
-
keyNonNullable,
|
20
|
-
keyNullable,
|
21
|
-
fragmentData,
|
22
|
-
} from './utils';
|
23
14
|
import type {
|
24
15
|
FetchFn,
|
25
16
|
NonNullableData,
|
@@ -30,6 +21,16 @@ import type {
|
|
30
21
|
} from './utils';
|
31
22
|
import type {IEnvironment} from 'relay-runtime';
|
32
23
|
|
24
|
+
import useRefetchableFragment from '../useRefetchableFragment';
|
25
|
+
import {
|
26
|
+
fragmentData,
|
27
|
+
fragmentInput,
|
28
|
+
keyAnotherNonNullable,
|
29
|
+
keyAnotherNullable,
|
30
|
+
keyNonNullable,
|
31
|
+
keyNullable,
|
32
|
+
} from './utils';
|
33
|
+
|
33
34
|
/* eslint-disable react-hooks/rules-of-hooks */
|
34
35
|
|
35
36
|
// Nullability of returned data type is correct
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,21 +13,26 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
import type {
|
17
|
-
Disposable,
|
18
|
-
FragmentReference,
|
19
|
-
GraphQLTaggedNode,
|
20
|
-
} from 'relay-runtime';
|
16
|
+
import type {Disposable, Fragment, FragmentType} from 'relay-runtime';
|
21
17
|
|
22
|
-
declare export var fragmentInput:
|
18
|
+
declare export var fragmentInput: Fragment<
|
19
|
+
Example_user$fragmentType,
|
20
|
+
Example_user$data,
|
21
|
+
>;
|
22
|
+
|
23
|
+
declare export opaque type Example_user$fragmentType: FragmentType;
|
24
|
+
export type Example_user$data = NonNullableData;
|
25
|
+
export type Example_user$key = {
|
26
|
+
+$data?: Example_user$data,
|
27
|
+
+$fragmentSpreads: Example_user$fragmentType,
|
28
|
+
...
|
29
|
+
};
|
23
30
|
|
24
31
|
export type NonNullableData = {|
|
25
32
|
+id: string,
|
26
33
|
+count: number,
|
27
34
|
|};
|
28
|
-
|
29
35
|
export type NullableData = ?NonNullableData;
|
30
|
-
|
31
36
|
export type NonNullablePluralData = $ReadOnlyArray<NonNullableData>;
|
32
37
|
export type NullablePluralData = ?$ReadOnlyArray<NonNullableData>;
|
33
38
|
|
@@ -36,44 +41,28 @@ export type AnotherNonNullableData = {|
|
|
36
41
|
+friends: ?number,
|
37
42
|
|};
|
38
43
|
|
39
|
-
declare export var keyNonNullable:
|
40
|
-
+$data?: NonNullableData,
|
41
|
-
+$fragmentRefs: FragmentReference,
|
42
|
-
...
|
43
|
-
};
|
44
|
+
declare export var keyNonNullable: Example_user$key;
|
44
45
|
|
45
|
-
declare export var keyNonNullablePlural: $ReadOnlyArray<
|
46
|
-
+$data?: NonNullablePluralData,
|
47
|
-
+$fragmentRefs: FragmentReference,
|
48
|
-
...
|
49
|
-
}>;
|
46
|
+
declare export var keyNonNullablePlural: $ReadOnlyArray<Example_user$key>;
|
50
47
|
|
51
|
-
declare export var keyNullablePlural: ?$ReadOnlyArray<
|
52
|
-
+$data?: NonNullablePluralData,
|
53
|
-
+$fragmentRefs: FragmentReference,
|
54
|
-
...
|
55
|
-
}>;
|
48
|
+
declare export var keyNullablePlural: ?$ReadOnlyArray<Example_user$key>;
|
56
49
|
|
57
|
-
declare export var keyNullable: ?
|
58
|
-
+$data?: NonNullableData,
|
59
|
-
+$fragmentRefs: FragmentReference,
|
60
|
-
...
|
61
|
-
};
|
50
|
+
declare export var keyNullable: ?Example_user$key;
|
62
51
|
|
63
52
|
declare export var keyAnotherNonNullable: {
|
64
53
|
+$data: AnotherNonNullableData,
|
65
|
-
+$
|
54
|
+
+$fragmentSpreads: FragmentType,
|
66
55
|
...
|
67
56
|
};
|
68
57
|
|
69
58
|
declare export var keyAnotherNullable: ?{
|
70
59
|
+$data: AnotherNonNullableData,
|
71
|
-
+$
|
60
|
+
+$fragmentSpreads: FragmentType,
|
72
61
|
...
|
73
62
|
};
|
74
63
|
|
75
64
|
declare export var fragmentData: {
|
76
|
-
+$
|
65
|
+
+$fragmentType: FragmentType,
|
77
66
|
...
|
78
67
|
};
|
79
68
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -11,8 +11,6 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
const {loadQuery} = require('./loadQuery');
|
15
|
-
|
16
14
|
import type {
|
17
15
|
EntryPoint,
|
18
16
|
EntryPointComponent,
|
@@ -21,6 +19,8 @@ import type {
|
|
21
19
|
PreloadedEntryPoint,
|
22
20
|
} from './EntryPointTypes.flow';
|
23
21
|
|
22
|
+
const {loadQuery} = require('./loadQuery');
|
23
|
+
|
24
24
|
function loadEntryPoint<
|
25
25
|
TEntryPointParams: {...},
|
26
26
|
TPreloadedQueries: {...},
|
@@ -51,12 +51,8 @@ function loadEntryPoint<
|
|
51
51
|
if (queries != null) {
|
52
52
|
const queriesPropNames = Object.keys(queries);
|
53
53
|
queriesPropNames.forEach(queryPropName => {
|
54
|
-
const {
|
55
|
-
|
56
|
-
options,
|
57
|
-
parameters,
|
58
|
-
variables,
|
59
|
-
} = queries[queryPropName];
|
54
|
+
const {environmentProviderOptions, options, parameters, variables} =
|
55
|
+
queries[queryPropName];
|
60
56
|
|
61
57
|
const environment = environmentProvider.getEnvironment(
|
62
58
|
environmentProviderOptions,
|
@@ -83,10 +79,8 @@ function loadEntryPoint<
|
|
83
79
|
if (entryPointDescription == null) {
|
84
80
|
return;
|
85
81
|
}
|
86
|
-
const {
|
87
|
-
|
88
|
-
entryPointParams: nestedParams,
|
89
|
-
} = entryPointDescription;
|
82
|
+
const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
|
83
|
+
entryPointDescription;
|
90
84
|
preloadedEntryPoints[entryPointPropName] = loadEntryPoint(
|
91
85
|
environmentProvider,
|
92
86
|
nestedEntryPoint,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -11,37 +11,35 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
const React = require('react');
|
15
|
-
|
16
|
-
const invariant = require('invariant');
|
17
|
-
const warning = require('warning');
|
18
|
-
|
19
|
-
const {
|
20
|
-
PreloadableQueryRegistry,
|
21
|
-
ReplaySubject,
|
22
|
-
createOperationDescriptor,
|
23
|
-
getRequest,
|
24
|
-
getRequestIdentifier,
|
25
|
-
Observable,
|
26
|
-
RelayFeatureFlags,
|
27
|
-
__internal: {fetchQueryDeduped},
|
28
|
-
} = require('relay-runtime');
|
29
|
-
|
30
14
|
import type {
|
15
|
+
LoadQueryOptions,
|
31
16
|
PreloadableConcreteRequest,
|
32
17
|
PreloadedQueryInner,
|
33
|
-
LoadQueryOptions,
|
34
18
|
} from './EntryPointTypes.flow';
|
35
19
|
import type {
|
20
|
+
GraphQLResponse,
|
21
|
+
GraphQLTaggedNode,
|
36
22
|
IEnvironment,
|
37
23
|
OperationDescriptor,
|
38
24
|
OperationType,
|
39
|
-
GraphQLTaggedNode,
|
40
|
-
GraphQLResponse,
|
41
25
|
RequestIdentifier,
|
42
26
|
RequestParameters,
|
43
27
|
} from 'relay-runtime';
|
44
28
|
|
29
|
+
const invariant = require('invariant');
|
30
|
+
const React = require('react');
|
31
|
+
const {
|
32
|
+
Observable,
|
33
|
+
PreloadableQueryRegistry,
|
34
|
+
RelayFeatureFlags,
|
35
|
+
ReplaySubject,
|
36
|
+
__internal: {fetchQueryDeduped},
|
37
|
+
createOperationDescriptor,
|
38
|
+
getRequest,
|
39
|
+
getRequestIdentifier,
|
40
|
+
} = require('relay-runtime');
|
41
|
+
const warning = require('warning');
|
42
|
+
|
45
43
|
let RenderDispatcher = null;
|
46
44
|
let fetchKey = 100001;
|
47
45
|
|
@@ -59,7 +57,7 @@ function useTrackLoadQueryInRender() {
|
|
59
57
|
function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
60
58
|
environment: IEnvironment,
|
61
59
|
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
|
62
|
-
variables:
|
60
|
+
variables: TQuery['variables'],
|
63
61
|
options?: ?LoadQueryOptions,
|
64
62
|
environmentProviderOptions?: ?TEnvironmentProviderOptions,
|
65
63
|
): PreloadedQueryInner<TQuery, TEnvironmentProviderOptions> {
|
@@ -274,7 +272,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
274
272
|
let cancelOnLoadCallback;
|
275
273
|
let queryId;
|
276
274
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
277
|
-
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
275
|
+
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
276
|
+
(preloadableRequest: $FlowFixMe);
|
278
277
|
({params} = preloadableConcreteRequest);
|
279
278
|
|
280
279
|
({id: queryId} = params);
|
@@ -300,7 +299,6 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
300
299
|
fetchPolicy === 'store-only' ? null : makeNetworkRequest(params);
|
301
300
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
302
301
|
({dispose: cancelOnLoadCallback} = PreloadableQueryRegistry.onLoad(
|
303
|
-
// $FlowFixMe[incompatible-call]
|
304
302
|
queryId,
|
305
303
|
preloadedModule => {
|
306
304
|
cancelOnLoadCallback();
|
@@ -319,7 +317,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
319
317
|
));
|
320
318
|
}
|
321
319
|
} else {
|
322
|
-
const graphQlTaggedNode: GraphQLTaggedNode =
|
320
|
+
const graphQlTaggedNode: GraphQLTaggedNode =
|
321
|
+
(preloadableRequest: $FlowFixMe);
|
323
322
|
const request = getRequest(graphQlTaggedNode);
|
324
323
|
params = request.params;
|
325
324
|
queryId = params.cacheID != null ? params.cacheID : params.id;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,15 +13,6 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const {
|
17
|
-
createOperationDescriptor,
|
18
|
-
getRequest,
|
19
|
-
getRequestIdentifier,
|
20
|
-
Observable,
|
21
|
-
PreloadableQueryRegistry,
|
22
|
-
ReplaySubject,
|
23
|
-
} = require('relay-runtime');
|
24
|
-
|
25
16
|
import type {
|
26
17
|
PreloadableConcreteRequest,
|
27
18
|
PreloadedQueryInner_DEPRECATED,
|
@@ -39,6 +30,16 @@ import type {
|
|
39
30
|
Subscription,
|
40
31
|
} from 'relay-runtime';
|
41
32
|
|
33
|
+
const {
|
34
|
+
Observable,
|
35
|
+
PreloadableQueryRegistry,
|
36
|
+
RelayFeatureFlags,
|
37
|
+
ReplaySubject,
|
38
|
+
createOperationDescriptor,
|
39
|
+
getRequest,
|
40
|
+
getRequestIdentifier,
|
41
|
+
} = require('relay-runtime');
|
42
|
+
|
42
43
|
// Expire results by this delay after they resolve.
|
43
44
|
const DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
|
44
45
|
|
@@ -111,7 +112,23 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
111
112
|
}
|
112
113
|
return () => {
|
113
114
|
subscription?.unsubscribe();
|
114
|
-
|
115
|
+
if (environment.isServer()) {
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
if (
|
119
|
+
RelayFeatureFlags.DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES ===
|
120
|
+
true
|
121
|
+
) {
|
122
|
+
setTimeout(() => {
|
123
|
+
// Clear the cache entry after the default timeout
|
124
|
+
// null-check for Flow
|
125
|
+
if (queryEntry != null) {
|
126
|
+
cleanup(pendingQueries, queryEntry);
|
127
|
+
}
|
128
|
+
}, DEFAULT_PREFETCH_TIMEOUT);
|
129
|
+
} else {
|
130
|
+
cleanup(pendingQueries, queryEntry);
|
131
|
+
}
|
115
132
|
};
|
116
133
|
})
|
117
134
|
: null;
|
@@ -140,7 +157,8 @@ function preloadQueryDeduped<TQuery: OperationType>(
|
|
140
157
|
let params;
|
141
158
|
let query: ?ConcreteRequest;
|
142
159
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
143
|
-
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
160
|
+
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
161
|
+
(preloadableRequest: $FlowFixMe);
|
144
162
|
params = preloadableConcreteRequest.params;
|
145
163
|
query = params.id != null ? PreloadableQueryRegistry.get(params.id) : null;
|
146
164
|
} else {
|
@@ -238,9 +256,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
|
|
238
256
|
} else {
|
239
257
|
nextQueryEntry = prevQueryEntry;
|
240
258
|
}
|
241
|
-
// $FlowFixMe[incompatible-call]
|
242
259
|
pendingQueries.set(cacheKey, nextQueryEntry);
|
243
|
-
// $FlowFixMe[incompatible-return]
|
244
260
|
return nextQueryEntry;
|
245
261
|
}
|
246
262
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,8 +13,6 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const preloadQuery = require('./preloadQuery_DEPRECATED');
|
17
|
-
|
18
16
|
import type {
|
19
17
|
EntryPoint,
|
20
18
|
EntryPointComponent,
|
@@ -22,6 +20,8 @@ import type {
|
|
22
20
|
IEnvironmentProvider,
|
23
21
|
} from './EntryPointTypes.flow';
|
24
22
|
|
23
|
+
const preloadQuery = require('./preloadQuery_DEPRECATED');
|
24
|
+
|
25
25
|
function prepareEntryPoint<
|
26
26
|
TEntryPointParams: {...},
|
27
27
|
TPreloadedQueries: {...},
|
@@ -51,12 +51,8 @@ function prepareEntryPoint<
|
|
51
51
|
if (queries != null) {
|
52
52
|
const queriesPropNames = Object.keys(queries);
|
53
53
|
queriesPropNames.forEach(queryPropName => {
|
54
|
-
const {
|
55
|
-
|
56
|
-
options,
|
57
|
-
parameters,
|
58
|
-
variables,
|
59
|
-
} = queries[queryPropName];
|
54
|
+
const {environmentProviderOptions, options, parameters, variables} =
|
55
|
+
queries[queryPropName];
|
60
56
|
|
61
57
|
const environment = environmentProvider.getEnvironment(
|
62
58
|
environmentProviderOptions,
|
@@ -79,10 +75,8 @@ function prepareEntryPoint<
|
|
79
75
|
if (entryPointDescription == null) {
|
80
76
|
return;
|
81
77
|
}
|
82
|
-
const {
|
83
|
-
|
84
|
-
entryPointParams: nestedParams,
|
85
|
-
} = entryPointDescription;
|
78
|
+
const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
|
79
|
+
entryPointDescription;
|
86
80
|
preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(
|
87
81
|
environmentProvider,
|
88
82
|
nestedEntryPoint,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,11 +13,20 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
16
|
+
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
17
|
+
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
|
18
|
+
import type {
|
19
|
+
FragmentType,
|
20
|
+
GraphQLResponse,
|
21
|
+
GraphQLTaggedNode,
|
22
|
+
Observer,
|
23
|
+
OperationType,
|
24
|
+
} from 'relay-runtime';
|
25
|
+
|
17
26
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
18
27
|
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
19
28
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
20
|
-
|
29
|
+
const invariant = require('invariant');
|
21
30
|
const {useCallback, useEffect, useRef, useState} = require('react');
|
22
31
|
const {
|
23
32
|
getFragment,
|
@@ -25,16 +34,6 @@ const {
|
|
25
34
|
getPaginationMetadata,
|
26
35
|
} = require('relay-runtime');
|
27
36
|
|
28
|
-
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
29
|
-
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
|
30
|
-
import type {
|
31
|
-
FragmentReference,
|
32
|
-
GraphQLResponse,
|
33
|
-
GraphQLTaggedNode,
|
34
|
-
Observer,
|
35
|
-
OperationType,
|
36
|
-
} from 'relay-runtime';
|
37
|
-
|
38
37
|
export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
|
39
38
|
data: TFragmentData,
|
40
39
|
loadNext: LoadMoreFn<TQuery>,
|
@@ -46,7 +45,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
|
|
46
45
|
|
47
46
|
function useBlockingPaginationFragment<
|
48
47
|
TQuery: OperationType,
|
49
|
-
TKey: ?{+$data?: mixed, +$
|
48
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
50
49
|
>(
|
51
50
|
fragmentInput: GraphQLTaggedNode,
|
52
51
|
parentFragmentRef: TKey,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,12 +13,6 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const loadEntryPoint = require('./loadEntryPoint');
|
17
|
-
const useIsMountedRef = require('./useIsMountedRef');
|
18
|
-
|
19
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
20
|
-
const {useCallback, useEffect, useRef, useState} = require('react');
|
21
|
-
|
22
16
|
import type {
|
23
17
|
EntryPoint,
|
24
18
|
EntryPointComponent,
|
@@ -27,6 +21,11 @@ import type {
|
|
27
21
|
PreloadedEntryPoint,
|
28
22
|
} from './EntryPointTypes.flow';
|
29
23
|
|
24
|
+
const loadEntryPoint = require('./loadEntryPoint');
|
25
|
+
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
26
|
+
const useIsMountedRef = require('./useIsMountedRef');
|
27
|
+
const {useCallback, useEffect, useRef, useState} = require('react');
|
28
|
+
|
30
29
|
type UseEntryPointLoaderHookReturnType<
|
31
30
|
TEntryPointParams: {...},
|
32
31
|
TPreloadedQueries: {...},
|
@@ -121,10 +120,8 @@ function useLoadEntryPoint<
|
|
121
120
|
const [entryPointReference, setEntryPointReference] = useState<
|
122
121
|
PreloadedEntryPoint<TEntryPointComponent> | NullEntryPointReference,
|
123
122
|
>(initialEntryPointReferenceInternal);
|
124
|
-
const [
|
125
|
-
|
126
|
-
setEntryPointParams,
|
127
|
-
] = useState<TEntryPointParams | null>(initialEntryPointParamsInternal);
|
123
|
+
const [entryPointParams, setEntryPointParams] =
|
124
|
+
useState<TEntryPointParams | null>(initialEntryPointParamsInternal);
|
128
125
|
|
129
126
|
const disposeEntryPoint = useCallback(() => {
|
130
127
|
if (isMountedRef.current) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,10 +13,10 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const {useCallback, useEffect, useRef} = require('react');
|
17
|
-
|
18
16
|
import type {Subscription} from 'relay-runtime';
|
19
17
|
|
18
|
+
const {useCallback, useEffect, useRef} = require('react');
|
19
|
+
|
20
20
|
/**
|
21
21
|
* This hook returns a mutable React ref that holds the value of whether a
|
22
22
|
* fetch request is in flight. The reason this is a mutable ref instead of
|