react-relay 12.0.0 → 13.0.0-rc.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -3
- package/ReactRelayFragmentContainer.js.flow +10 -16
- package/ReactRelayFragmentMockRenderer.js.flow +1 -1
- package/ReactRelayLocalQueryRenderer.js.flow +6 -7
- package/ReactRelayPaginationContainer.js.flow +29 -39
- package/ReactRelayQueryFetcher.js.flow +9 -10
- package/ReactRelayQueryRenderer.js.flow +15 -15
- package/ReactRelayRefetchContainer.js.flow +24 -32
- package/ReactRelayTestMocker.js.flow +16 -14
- package/ReactRelayTypes.js.flow +10 -10
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +1 -2
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -2
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -2
- package/__flowtests__/RelayModern-flowtest.js.flow +78 -46
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +4 -3
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +4 -3
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +13 -8
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +13 -8
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +15 -12
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +15 -12
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +13 -10
- package/assertFragmentMap.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +11 -10
- package/getRootVariablesForFragments.js.flow +2 -4
- package/hooks.js +1 -1
- package/hooks.js.flow +3 -5
- package/index.js +1 -1
- package/index.js.flow +4 -6
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -2
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +4 -4
- package/lib/ReactRelayFragmentMockRenderer.js +2 -2
- package/lib/ReactRelayLocalQueryRenderer.js +7 -8
- package/lib/ReactRelayPaginationContainer.js +18 -22
- package/lib/ReactRelayQueryFetcher.js +2 -2
- package/lib/ReactRelayQueryRenderer.js +4 -4
- package/lib/ReactRelayRefetchContainer.js +12 -14
- package/lib/ReactRelayTestMocker.js +7 -8
- package/lib/RelayContext.js +3 -2
- package/lib/assertFragmentMap.js +2 -1
- package/lib/buildReactRelayContainer.js +7 -7
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +5 -5
- package/lib/index.js +7 -7
- package/lib/jest-react/internalAct.js +2 -2
- package/lib/multi-actor/ActorChange.js +2 -2
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -2
- package/lib/relay-hooks/EntryPointContainer.react.js +3 -3
- package/lib/relay-hooks/FragmentResource.js +241 -45
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +4 -4
- package/lib/relay-hooks/MatchContainer.js +1 -1
- package/lib/relay-hooks/QueryResource.js +83 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadQuery.js +8 -9
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +24 -10
- package/lib/relay-hooks/useBlockingPaginationFragment.js +2 -2
- package/lib/relay-hooks/useEntryPointLoader.js +2 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +2 -1
- package/lib/relay-hooks/useFragment.js +8 -7
- package/lib/relay-hooks/useFragmentNode.js +4 -4
- package/lib/relay-hooks/useIsOperationNodeActive.js +2 -2
- package/lib/relay-hooks/useLazyLoadQuery.js +3 -3
- package/lib/relay-hooks/useLazyLoadQueryNode.js +4 -4
- package/lib/relay-hooks/useLoadMoreFunction.js +7 -9
- package/lib/relay-hooks/useMemoOperationDescriptor.js +2 -2
- package/lib/relay-hooks/useMemoVariables.js +2 -2
- package/lib/relay-hooks/useMutation.js +17 -6
- package/lib/relay-hooks/usePreloadedQuery.js +5 -5
- package/lib/relay-hooks/useQueryLoader.js +4 -4
- package/lib/relay-hooks/useRefetchableFragmentNode.js +10 -12
- package/lib/relay-hooks/useRelayEnvironment.js +2 -2
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -2
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +2 -1
- package/multi-actor/ActorChange.js.flow +3 -4
- package/multi-actor/useRelayActorEnvironment.js.flow +5 -7
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +8 -15
- package/relay-hooks/EntryPointTypes.flow.js.flow +18 -24
- package/relay-hooks/FragmentResource.js.flow +220 -34
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +32 -46
- package/relay-hooks/MatchContainer.js.flow +3 -2
- package/relay-hooks/QueryResource.js.flow +119 -17
- package/relay-hooks/RelayEnvironmentProvider.js.flow +9 -9
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +4 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +8 -7
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/utils.js.flow +8 -12
- package/relay-hooks/loadEntryPoint.js.flow +6 -12
- package/relay-hooks/loadQuery.js.flow +22 -23
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +29 -13
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +6 -12
- package/relay-hooks/useBlockingPaginationFragment.js.flow +12 -13
- package/relay-hooks/useEntryPointLoader.js.flow +7 -10
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -2
- package/relay-hooks/useFragment.js.flow +26 -46
- package/relay-hooks/useFragmentNode.js.flow +5 -7
- package/relay-hooks/useIsOperationNodeActive.js.flow +3 -5
- package/relay-hooks/useIsParentQueryActive.js.flow +3 -4
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -10
- package/relay-hooks/useLazyLoadQueryNode.js.flow +11 -13
- package/relay-hooks/useLoadMoreFunction.js.flow +19 -27
- package/relay-hooks/useMemoOperationDescriptor.js.flow +5 -7
- package/relay-hooks/useMemoVariables.js.flow +6 -6
- package/relay-hooks/useMutation.js.flow +26 -26
- package/relay-hooks/usePaginationFragment.js.flow +37 -46
- package/relay-hooks/usePreloadedQuery.js.flow +13 -19
- package/relay-hooks/useQueryLoader.js.flow +13 -16
- package/relay-hooks/useRefetchableFragment.js.flow +7 -8
- package/relay-hooks/useRefetchableFragmentNode.js.flow +22 -30
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +2 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +3 -6
- package/relay-hooks/useSubscription.js.flow +6 -7
@@ -13,14 +13,14 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
17
|
-
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
18
|
-
|
16
|
+
import type {IEnvironment} from 'relay-runtime';
|
19
17
|
import type {
|
20
|
-
IActorEnvironment,
|
21
18
|
ActorIdentifier,
|
19
|
+
IActorEnvironment,
|
22
20
|
} from 'relay-runtime/multi-actor-environment';
|
23
|
-
|
21
|
+
|
22
|
+
const React = require('react');
|
23
|
+
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
24
24
|
|
25
25
|
const {useMemo} = React;
|
26
26
|
|
@@ -34,10 +34,10 @@ type Props = $ReadOnly<{|
|
|
34
34
|
|
35
35
|
function RelayEnvironmentProvider(props: Props): React.Node {
|
36
36
|
const {children, environment, getEnvironmentForActor} = props;
|
37
|
-
const context = useMemo(
|
38
|
-
environment,
|
39
|
-
getEnvironmentForActor,
|
40
|
-
|
37
|
+
const context = useMemo(
|
38
|
+
() => ({environment, getEnvironmentForActor}),
|
39
|
+
[environment, getEnvironmentForActor],
|
40
|
+
);
|
41
41
|
return (
|
42
42
|
<ReactRelayContext.Provider value={context}>
|
43
43
|
{children}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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 {Disposable, IEnvironment} from 'relay-runtime';
|
17
|
+
|
18
|
+
const invariant = require('invariant');
|
19
|
+
|
20
|
+
const TEMPORARY_RETAIN_DURATION_MS = 5 * 60 * 1000;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Allows you to retain a resource as part of a component lifecycle accounting
|
24
|
+
* for Suspense. You temporarily retain the resource during render, then
|
25
|
+
* permanently retain it during commit and release it during unmount.
|
26
|
+
*/
|
27
|
+
class SuspenseResource {
|
28
|
+
_retainCount = 0;
|
29
|
+
_retainDisposable: ?Disposable = null;
|
30
|
+
_releaseTemporaryRetain: ?() => void = null;
|
31
|
+
_retain: IEnvironment => Disposable;
|
32
|
+
|
33
|
+
constructor(retain: (environment: IEnvironment) => Disposable) {
|
34
|
+
this._retain = (environment: IEnvironment): Disposable => {
|
35
|
+
this._retainCount++;
|
36
|
+
if (this._retainCount === 1) {
|
37
|
+
this._retainDisposable = retain(environment);
|
38
|
+
}
|
39
|
+
return {
|
40
|
+
dispose: () => {
|
41
|
+
this._retainCount = Math.max(0, this._retainCount - 1);
|
42
|
+
if (this._retainCount === 0) {
|
43
|
+
invariant(
|
44
|
+
this._retainDisposable != null,
|
45
|
+
'Relay: Expected disposable to release query to be defined.' +
|
46
|
+
"If you're seeing this, this is likely a bug in Relay.",
|
47
|
+
);
|
48
|
+
this._retainDisposable.dispose();
|
49
|
+
this._retainDisposable = null;
|
50
|
+
}
|
51
|
+
},
|
52
|
+
};
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
temporaryRetain(environment: IEnvironment): Disposable {
|
57
|
+
// If we're executing in a server environment, there's no need
|
58
|
+
// to create temporary retains, since the component will never commit.
|
59
|
+
if (environment.isServer()) {
|
60
|
+
return {dispose: () => {}};
|
61
|
+
}
|
62
|
+
|
63
|
+
// temporaryRetain is called during the render phase. However,
|
64
|
+
// given that we can't tell if this render will eventually commit or not,
|
65
|
+
// we create a timer to autodispose of this retain in case the associated
|
66
|
+
// component never commits.
|
67
|
+
// If the component /does/ commit, permanentRetain will clear this timeout
|
68
|
+
// and permanently retain the data.
|
69
|
+
const retention = this._retain(environment);
|
70
|
+
let releaseQueryTimeout = null;
|
71
|
+
const releaseTemporaryRetain = () => {
|
72
|
+
clearTimeout(releaseQueryTimeout);
|
73
|
+
releaseQueryTimeout = null;
|
74
|
+
this._releaseTemporaryRetain = null;
|
75
|
+
retention.dispose();
|
76
|
+
};
|
77
|
+
releaseQueryTimeout = setTimeout(
|
78
|
+
releaseTemporaryRetain,
|
79
|
+
TEMPORARY_RETAIN_DURATION_MS,
|
80
|
+
);
|
81
|
+
|
82
|
+
// NOTE: Since temporaryRetain can be called multiple times, we release
|
83
|
+
// the previous temporary retain after we re-establish a new one, since
|
84
|
+
// we only ever need a single temporary retain until the permanent retain is
|
85
|
+
// established.
|
86
|
+
// temporaryRetain may be called multiple times by React during the render
|
87
|
+
// phase, as well as multiple times by other query components that are
|
88
|
+
// rendering the same query/variables.
|
89
|
+
this._releaseTemporaryRetain?.();
|
90
|
+
this._releaseTemporaryRetain = releaseTemporaryRetain;
|
91
|
+
|
92
|
+
return {
|
93
|
+
dispose: () => {
|
94
|
+
this._releaseTemporaryRetain?.();
|
95
|
+
},
|
96
|
+
};
|
97
|
+
}
|
98
|
+
|
99
|
+
permanentRetain(environment: IEnvironment): Disposable {
|
100
|
+
const disposable = this._retain(environment);
|
101
|
+
this.releaseTemporaryRetain();
|
102
|
+
return disposable;
|
103
|
+
}
|
104
|
+
|
105
|
+
releaseTemporaryRetain(): void {
|
106
|
+
this._releaseTemporaryRetain?.();
|
107
|
+
this._releaseTemporaryRetain = null;
|
108
|
+
}
|
109
|
+
|
110
|
+
getRetainCount(): number {
|
111
|
+
return this._retainCount;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
module.exports = SuspenseResource;
|
@@ -13,8 +13,8 @@
|
|
13
13
|
|
14
14
|
import type {
|
15
15
|
EntryPoint,
|
16
|
-
EntryPointProps,
|
17
16
|
EntryPointElementConfig,
|
17
|
+
EntryPointProps,
|
18
18
|
} from '../../EntryPointTypes.flow';
|
19
19
|
|
20
20
|
type MyComponentOtherProps = $ReadOnly<{|
|
@@ -30,10 +30,11 @@ type PreloadParams = $ReadOnly<{||}>;
|
|
30
30
|
type MyComponentEntryPointType = EntryPoint<PreloadParams, typeof MyComponent>;
|
31
31
|
|
32
32
|
// This gets the "other props" of the component through the entrypoint's typing
|
33
|
-
type MyComponentEntryPointProps =
|
33
|
+
type MyComponentEntryPointProps =
|
34
|
+
EntryPointElementConfig<MyComponentEntryPointType>;
|
34
35
|
|
35
36
|
// This gets the "other props" directly from the component's prop typings
|
36
|
-
type OtherProps =
|
37
|
+
type OtherProps = MyComponentProps['props'];
|
37
38
|
|
38
39
|
// We want to make sure that `OtherProps` and `MyComponentEntryPointProps` are exactly the same.
|
39
40
|
opaque type __SUBTYPE_CHECK_1__: OtherProps = MyComponentEntryPointProps;
|
@@ -11,12 +11,12 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
import type {JSResourceReference} from 'JSResourceReference';
|
14
15
|
import type {
|
15
16
|
EntryPoint,
|
16
17
|
EntryPointProps,
|
17
18
|
PreloadedEntryPoint,
|
18
19
|
} from '../../EntryPointTypes.flow';
|
19
|
-
import type {JSResourceReference} from 'JSResourceReference';
|
20
20
|
|
21
21
|
declare function mockJSResource<TModule>(
|
22
22
|
module: TModule,
|
@@ -11,16 +11,7 @@
|
|
11
11
|
|
12
12
|
// flowlint ambiguous-object-type:error
|
13
13
|
|
14
|
-
import useBlockingPaginationFragment from '../useBlockingPaginationFragment';
|
15
14
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
16
|
-
import {
|
17
|
-
fragmentData,
|
18
|
-
fragmentInput,
|
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 useBlockingPaginationFragment from '../useBlockingPaginationFragment';
|
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,
|
@@ -11,8 +11,16 @@
|
|
11
11
|
|
12
12
|
// flowlint ambiguous-object-type:error
|
13
13
|
|
14
|
+
import type {
|
15
|
+
NonNullableData,
|
16
|
+
NonNullablePluralData,
|
17
|
+
NullableData,
|
18
|
+
NullablePluralData,
|
19
|
+
} from './utils';
|
20
|
+
|
14
21
|
import useFragment from '../useFragment';
|
15
22
|
import {
|
23
|
+
fragmentData,
|
16
24
|
fragmentInput,
|
17
25
|
keyAnotherNonNullable,
|
18
26
|
keyAnotherNullable,
|
@@ -20,13 +28,6 @@ import {
|
|
20
28
|
keyNonNullablePlural,
|
21
29
|
keyNullable,
|
22
30
|
keyNullablePlural,
|
23
|
-
fragmentData,
|
24
|
-
} from './utils';
|
25
|
-
import type {
|
26
|
-
NonNullableData,
|
27
|
-
NonNullablePluralData,
|
28
|
-
NullableData,
|
29
|
-
NullablePluralData,
|
30
31
|
} from './utils';
|
31
32
|
|
32
33
|
/* eslint-disable react-hooks/rules-of-hooks */
|
@@ -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,
|
@@ -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
|
@@ -13,11 +13,7 @@
|
|
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, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
|
21
17
|
|
22
18
|
declare export var fragmentInput: GraphQLTaggedNode;
|
23
19
|
|
@@ -38,42 +34,42 @@ export type AnotherNonNullableData = {|
|
|
38
34
|
|
39
35
|
declare export var keyNonNullable: {
|
40
36
|
+$data?: NonNullableData,
|
41
|
-
+$
|
37
|
+
+$fragmentSpreads: FragmentType,
|
42
38
|
...
|
43
39
|
};
|
44
40
|
|
45
41
|
declare export var keyNonNullablePlural: $ReadOnlyArray<{
|
46
42
|
+$data?: NonNullablePluralData,
|
47
|
-
+$
|
43
|
+
+$fragmentSpreads: FragmentType,
|
48
44
|
...
|
49
45
|
}>;
|
50
46
|
|
51
47
|
declare export var keyNullablePlural: ?$ReadOnlyArray<{
|
52
48
|
+$data?: NonNullablePluralData,
|
53
|
-
+$
|
49
|
+
+$fragmentSpreads: FragmentType,
|
54
50
|
...
|
55
51
|
}>;
|
56
52
|
|
57
53
|
declare export var keyNullable: ?{
|
58
54
|
+$data?: NonNullableData,
|
59
|
-
+$
|
55
|
+
+$fragmentSpreads: FragmentType,
|
60
56
|
...
|
61
57
|
};
|
62
58
|
|
63
59
|
declare export var keyAnotherNonNullable: {
|
64
60
|
+$data: AnotherNonNullableData,
|
65
|
-
+$
|
61
|
+
+$fragmentSpreads: FragmentType,
|
66
62
|
...
|
67
63
|
};
|
68
64
|
|
69
65
|
declare export var keyAnotherNullable: ?{
|
70
66
|
+$data: AnotherNonNullableData,
|
71
|
-
+$
|
67
|
+
+$fragmentSpreads: FragmentType,
|
72
68
|
...
|
73
69
|
};
|
74
70
|
|
75
71
|
declare export var fragmentData: {
|
76
|
-
+$
|
72
|
+
+$fragmentType: FragmentType,
|
77
73
|
...
|
78
74
|
};
|
79
75
|
|
@@ -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,
|
@@ -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;
|
@@ -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
|
|
@@ -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,
|
@@ -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,
|