react-relay 14.1.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +19 -5
- package/ReactRelayQueryRenderer.js.flow +32 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +1 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +7 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +2 -2
- package/lib/ReactRelayContext.js +3 -3
- package/lib/ReactRelayFragmentContainer.js +39 -66
- package/lib/ReactRelayFragmentMockRenderer.js +2 -3
- package/lib/ReactRelayLocalQueryRenderer.js +18 -30
- package/lib/ReactRelayPaginationContainer.js +66 -159
- package/lib/ReactRelayQueryFetcher.js +48 -74
- package/lib/ReactRelayQueryRenderer.js +62 -82
- package/lib/ReactRelayQueryRendererContext.js +2 -1
- package/lib/ReactRelayRefetchContainer.js +52 -99
- package/lib/ReactRelayTestMocker.js +32 -66
- package/lib/ReactRelayTypes.js +2 -0
- package/lib/RelayContext.js +4 -6
- package/lib/assertFragmentMap.js +3 -4
- package/lib/buildReactRelayContainer.js +10 -25
- package/lib/getRootVariablesForFragments.js +5 -8
- package/lib/hooks.js +5 -17
- package/lib/index.js +5 -24
- package/lib/isRelayEnvironment.js +5 -3
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -7
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
- package/lib/relay-hooks/FragmentResource.js +102 -196
- package/lib/relay-hooks/HooksImplementation.js +2 -5
- package/lib/relay-hooks/InternalLogger.js +2 -2
- package/lib/relay-hooks/LRUCache.js +2 -19
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
- package/lib/relay-hooks/MatchContainer.js +14 -22
- package/lib/relay-hooks/ProfilerContext.js +3 -2
- package/lib/relay-hooks/QueryResource.js +30 -99
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
- package/lib/relay-hooks/SuspenseResource.js +8 -31
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +41 -77
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
- package/lib/relay-hooks/useClientQuery.js +3 -6
- package/lib/relay-hooks/useEntryPointLoader.js +17 -36
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
- package/lib/relay-hooks/useFragment.js +8 -18
- package/lib/relay-hooks/useFragmentNode.js +20 -31
- package/lib/relay-hooks/useIsMountedRef.js +4 -5
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
- package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
- package/lib/relay-hooks/useMemoVariables.js +15 -33
- package/lib/relay-hooks/useMutation.js +8 -25
- package/lib/relay-hooks/usePaginationFragment.js +61 -76
- package/lib/relay-hooks/usePreloadedQuery.js +12 -29
- package/lib/relay-hooks/useQueryLoader.js +23 -47
- package/lib/relay-hooks/useRefetchableFragment.js +8 -18
- package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
- package/lib/relay-hooks/useRelayEnvironment.js +4 -7
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
- package/lib/relay-hooks/useSubscription.js +5 -9
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- 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 +1 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
- package/relay-hooks/FragmentResource.js.flow +34 -8
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +5 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +4 -4
- package/relay-hooks/usePaginationFragment.js.flow +53 -46
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +85 -22
- package/relay-hooks/useRefetchableFragment.js.flow +64 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
package/ReactRelayContext.js
CHANGED
@@ -6,10 +6,11 @@
|
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
12
|
-
import type {GeneratedNodeMap, RelayProp
|
13
|
+
import type {$RelayProps, GeneratedNodeMap, RelayProp} from './ReactRelayTypes';
|
13
14
|
import type {
|
14
15
|
FragmentMap,
|
15
16
|
FragmentSpecResolver,
|
@@ -55,6 +56,7 @@ function createContainerWithFragments<
|
|
55
56
|
const containerName = getContainerName(Component);
|
56
57
|
|
57
58
|
return class extends React.Component<ContainerProps, ContainerState> {
|
59
|
+
// $FlowFixMe[missing-local-annot]
|
58
60
|
static displayName = containerName;
|
59
61
|
constructor(props: $FlowFixMe) {
|
60
62
|
super(props);
|
@@ -88,7 +90,7 @@ function createContainerWithFragments<
|
|
88
90
|
static getDerivedStateFromProps(
|
89
91
|
nextProps: ContainerProps,
|
90
92
|
prevState: ContainerState,
|
91
|
-
):
|
93
|
+
): Partial<ContainerState> | null {
|
92
94
|
// Any props change could impact the query, so we mirror props in state.
|
93
95
|
// This is an unusual pattern, but necessary for this container usecase.
|
94
96
|
const {prevProps} = prevState;
|
@@ -235,7 +237,9 @@ function createContainerWithFragments<
|
|
235
237
|
}
|
236
238
|
}
|
237
239
|
|
240
|
+
// $FlowFixMe[missing-local-annot]
|
238
241
|
render() {
|
242
|
+
// eslint-disable-next-line no-unused-vars
|
239
243
|
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
240
244
|
this.props;
|
241
245
|
return React.createElement(Component, {
|
@@ -6,12 +6,14 @@
|
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
|
14
15
|
import type {GraphQLTaggedNode, IEnvironment, Variables} from 'relay-runtime';
|
16
|
+
import type {SelectorData} from 'relay-runtime/store/RelayStoreTypes';
|
15
17
|
|
16
18
|
const ReactRelayContext = require('./ReactRelayContext');
|
17
19
|
const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
@@ -61,9 +63,9 @@ function ReactRelayLocalQueryRenderer(props: Props): React.Node {
|
|
61
63
|
|
62
64
|
// Use a ref to prevent rendering twice when data changes
|
63
65
|
// because of props change
|
64
|
-
const dataRef = useRef(null);
|
65
|
-
const [, forceUpdate] = useState(null);
|
66
|
-
const cleanupFnRef = useRef(null);
|
66
|
+
const dataRef = useRef<?SelectorData>(null);
|
67
|
+
const [, forceUpdate] = useState<?SelectorData>(null);
|
68
|
+
const cleanupFnRef = useRef<null | (() => void)>(null);
|
67
69
|
|
68
70
|
const snapshot = useMemo(() => {
|
69
71
|
environment.check(operation);
|
@@ -6,16 +6,18 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
12
13
|
|
14
|
+
import type {Sink} from '../relay-runtime/network/RelayObservable';
|
13
15
|
import type {
|
16
|
+
$RelayProps,
|
14
17
|
GeneratedNodeMap,
|
15
18
|
ObserverOrCallback,
|
16
19
|
RefetchOptions,
|
17
20
|
RelayPaginationProp,
|
18
|
-
$RelayProps,
|
19
21
|
} from './ReactRelayTypes';
|
20
22
|
import type {
|
21
23
|
CacheConfig,
|
@@ -254,9 +256,9 @@ function createGetFragmentVariables(
|
|
254
256
|
'ReactRelayPaginationContainer: Unable to synthesize a ' +
|
255
257
|
'getFragmentVariables function.',
|
256
258
|
);
|
257
|
-
return (prevVars: Variables, totalCount: number) => ({
|
259
|
+
return (prevVars: Variables, totalCount: number): Variables => ({
|
258
260
|
...prevVars,
|
259
|
-
[countVariable]: totalCount,
|
261
|
+
[(countVariable: string)]: totalCount,
|
260
262
|
});
|
261
263
|
}
|
262
264
|
|
@@ -346,6 +348,7 @@ function createContainerWithFragments<
|
|
346
348
|
createGetFragmentVariables(metadata);
|
347
349
|
|
348
350
|
return class extends React.Component<$FlowFixMeProps, ContainerState> {
|
351
|
+
// $FlowFixMe[missing-local-annot]
|
349
352
|
static displayName = containerName;
|
350
353
|
|
351
354
|
_isARequestInFlight: boolean;
|
@@ -564,6 +567,7 @@ function createContainerWithFragments<
|
|
564
567
|
...
|
565
568
|
} {
|
566
569
|
// Extract connection data and verify there are more edges to fetch
|
570
|
+
// eslint-disable-next-line no-unused-vars
|
567
571
|
const {componentRef: _, ...restProps} = this.props;
|
568
572
|
const props = {
|
569
573
|
...restProps,
|
@@ -694,7 +698,7 @@ function createContainerWithFragments<
|
|
694
698
|
const observer = toObserver(observerOrCallback);
|
695
699
|
const connectionData = this._getConnectionData();
|
696
700
|
if (!connectionData) {
|
697
|
-
Observable.create(sink => sink.complete()).subscribe(observer);
|
701
|
+
Observable.create<empty>(sink => sink.complete()).subscribe(observer);
|
698
702
|
return null;
|
699
703
|
}
|
700
704
|
const totalCount = connectionData.edgeCount + pageSize;
|
@@ -755,8 +759,11 @@ function createContainerWithFragments<
|
|
755
759
|
): Subscription {
|
756
760
|
const {environment} = assertRelayContext(this.props.__relayContext);
|
757
761
|
const {
|
762
|
+
// eslint-disable-next-line no-unused-vars
|
758
763
|
componentRef: _,
|
764
|
+
// eslint-disable-next-line no-unused-vars
|
759
765
|
__relayContext,
|
766
|
+
// eslint-disable-next-line no-unused-vars
|
760
767
|
__rootIsQueryRenderer,
|
761
768
|
...restProps
|
762
769
|
} = this.props;
|
@@ -764,7 +771,7 @@ function createContainerWithFragments<
|
|
764
771
|
...restProps,
|
765
772
|
...this.state.data,
|
766
773
|
};
|
767
|
-
let fragmentVariables;
|
774
|
+
let fragmentVariables: Variables;
|
768
775
|
const rootVariables = getRootVariablesForFragments(fragments, restProps);
|
769
776
|
fragmentVariables = getVariablesFromObject(fragments, restProps);
|
770
777
|
fragmentVariables = {
|
@@ -772,7 +779,7 @@ function createContainerWithFragments<
|
|
772
779
|
...fragmentVariables,
|
773
780
|
...this._refetchVariables,
|
774
781
|
};
|
775
|
-
let fetchVariables = connectionConfig.getVariables(
|
782
|
+
let fetchVariables: Variables = connectionConfig.getVariables(
|
776
783
|
props,
|
777
784
|
{
|
778
785
|
count: paginatingVariables.count,
|
@@ -787,14 +794,14 @@ function createContainerWithFragments<
|
|
787
794
|
fetchVariables,
|
788
795
|
componentName,
|
789
796
|
);
|
790
|
-
fetchVariables = {
|
797
|
+
fetchVariables = ({
|
791
798
|
...fetchVariables,
|
792
799
|
...this._refetchVariables,
|
793
|
-
};
|
794
|
-
fragmentVariables = {
|
800
|
+
}: Variables);
|
801
|
+
fragmentVariables = ({
|
795
802
|
...fetchVariables,
|
796
803
|
...fragmentVariables,
|
797
|
-
};
|
804
|
+
}: Variables);
|
798
805
|
|
799
806
|
const cacheConfig: ?CacheConfig = options
|
800
807
|
? {force: !!options.force}
|
@@ -865,8 +872,8 @@ function createContainerWithFragments<
|
|
865
872
|
operation,
|
866
873
|
preservePreviousReferences: true,
|
867
874
|
})
|
868
|
-
.mergeMap(payload =>
|
869
|
-
Observable.create(sink => {
|
875
|
+
.mergeMap<void>(payload =>
|
876
|
+
Observable.create<void>((sink: Sink<void>) => {
|
870
877
|
onNext(payload, () => {
|
871
878
|
sink.next(); // pass void to public observer's `next`
|
872
879
|
sink.complete();
|
@@ -902,7 +909,9 @@ function createContainerWithFragments<
|
|
902
909
|
}
|
903
910
|
}
|
904
911
|
|
912
|
+
// $FlowFixMe[missing-local-annot]
|
905
913
|
render() {
|
914
|
+
// eslint-disable-next-line no-unused-vars
|
906
915
|
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
907
916
|
this.props;
|
908
917
|
return (
|
@@ -6,6 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
@@ -62,7 +63,7 @@ class ReactRelayQueryFetcher {
|
|
62
63
|
_snapshot: ?Snapshot; // results of the root fragment;
|
63
64
|
_error: ?Error; // fetch error
|
64
65
|
_cacheSelectionReference: ?Disposable;
|
65
|
-
|
66
|
+
_didFetchFinish: boolean = false;
|
66
67
|
|
67
68
|
constructor(args?: {
|
68
69
|
cacheSelectionReference: ?Disposable,
|
@@ -102,6 +103,19 @@ class ReactRelayQueryFetcher {
|
|
102
103
|
return null;
|
103
104
|
}
|
104
105
|
|
106
|
+
getFetchResult(): ?{error?: Error, snapshot?: Snapshot} {
|
107
|
+
if (this._didFetchFinish) {
|
108
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
109
|
+
if (this._error != null) {
|
110
|
+
return {error: this._error};
|
111
|
+
} else if (this._snapshot != null) {
|
112
|
+
return {snapshot: this._snapshot};
|
113
|
+
}
|
114
|
+
} else {
|
115
|
+
return null;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
105
119
|
execute({
|
106
120
|
environment,
|
107
121
|
operation,
|
@@ -151,8 +165,8 @@ class ReactRelayQueryFetcher {
|
|
151
165
|
this._fetchOptions.onDataChangeCallbacks || [];
|
152
166
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
153
167
|
|
154
|
-
if (this.
|
155
|
-
// We don't reset '
|
168
|
+
if (this._didFetchFinish) {
|
169
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
156
170
|
if (this._error != null) {
|
157
171
|
onDataChange({error: this._error});
|
158
172
|
} else if (this._snapshot != null) {
|
@@ -215,7 +229,7 @@ class ReactRelayQueryFetcher {
|
|
215
229
|
next: () => {
|
216
230
|
// If we received a response,
|
217
231
|
// Make a note that to notify the callback when it's later added.
|
218
|
-
this.
|
232
|
+
this._didFetchFinish = true;
|
219
233
|
this._error = null;
|
220
234
|
|
221
235
|
// Only notify of the first result if `next` is being called **asynchronously**
|
@@ -225,7 +239,7 @@ class ReactRelayQueryFetcher {
|
|
225
239
|
error: err => {
|
226
240
|
// If we received a response when we didn't have a change callback,
|
227
241
|
// Make a note that to notify the callback when it's later added.
|
228
|
-
this.
|
242
|
+
this._didFetchFinish = true;
|
229
243
|
this._error = err;
|
230
244
|
this._snapshot = null;
|
231
245
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
@@ -26,6 +27,7 @@ const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
|
26
27
|
const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
27
28
|
const areEqual = require('areEqual');
|
28
29
|
const React = require('react');
|
30
|
+
const {RelayFeatureFlags} = require('relay-runtime');
|
29
31
|
const {
|
30
32
|
createOperationDescriptor,
|
31
33
|
deepFreeze,
|
@@ -169,7 +171,36 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
169
171
|
this._maybeHiddenOrFastRefresh = false;
|
170
172
|
// eslint-disable-next-line react/no-did-mount-set-state
|
171
173
|
this.setState(prevState => {
|
172
|
-
|
174
|
+
const newState = resetQueryStateForUpdate(this.props, prevState);
|
175
|
+
const {requestCacheKey, queryFetcher} = newState;
|
176
|
+
if (requestCacheKey != null && requestCache[requestCacheKey] != null) {
|
177
|
+
if (RelayFeatureFlags.ENABLE_QUERY_RENDERER_SET_STATE_PREVENTION) {
|
178
|
+
const fetchResult = queryFetcher.getFetchResult();
|
179
|
+
if (fetchResult != null) {
|
180
|
+
const snapshot = fetchResult.snapshot ?? null;
|
181
|
+
const error = fetchResult.error ?? null;
|
182
|
+
|
183
|
+
const {requestCacheKey: prevRequestCacheKey} = prevState;
|
184
|
+
if (prevRequestCacheKey != null) {
|
185
|
+
delete requestCache[prevRequestCacheKey];
|
186
|
+
}
|
187
|
+
|
188
|
+
newState.renderProps = getRenderProps(
|
189
|
+
error,
|
190
|
+
snapshot,
|
191
|
+
queryFetcher,
|
192
|
+
prevState.retryCallbacks,
|
193
|
+
);
|
194
|
+
newState.snapshot = snapshot;
|
195
|
+
newState.requestCacheKey = null;
|
196
|
+
} else {
|
197
|
+
queryFetcher.setOnDataChange(this._handleDataChange);
|
198
|
+
}
|
199
|
+
} else {
|
200
|
+
queryFetcher.setOnDataChange(this._handleDataChange);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
return newState;
|
173
204
|
});
|
174
205
|
return;
|
175
206
|
}
|
@@ -6,16 +6,17 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
import type {
|
15
|
+
$RelayProps,
|
14
16
|
GeneratedNodeMap,
|
15
17
|
ObserverOrCallback,
|
16
18
|
RefetchOptions,
|
17
19
|
RelayRefetchProp,
|
18
|
-
$RelayProps,
|
19
20
|
} from './ReactRelayTypes';
|
20
21
|
import type {
|
21
22
|
CacheConfig,
|
@@ -79,6 +80,7 @@ function createContainerWithFragments<
|
|
79
80
|
const containerName = getContainerName(Component);
|
80
81
|
|
81
82
|
return class extends React.Component<ContainerProps, ContainerState> {
|
83
|
+
// $FlowFixMe[missing-local-annot]
|
82
84
|
static displayName = containerName;
|
83
85
|
|
84
86
|
_refetchSubscription: ?Subscription;
|
@@ -142,7 +144,7 @@ function createContainerWithFragments<
|
|
142
144
|
static getDerivedStateFromProps(
|
143
145
|
nextProps: ContainerProps,
|
144
146
|
prevState: ContainerState,
|
145
|
-
):
|
147
|
+
): Partial<ContainerState> | null {
|
146
148
|
// Any props change could impact the query, so we mirror props in state.
|
147
149
|
// This is an unusual pattern, but necessary for this container usecase.
|
148
150
|
const {prevProps} = prevState;
|
@@ -369,7 +371,7 @@ function createContainerWithFragments<
|
|
369
371
|
|
370
372
|
// Declare refetchSubscription before assigning it in .start(), since
|
371
373
|
// synchronous completion may call callbacks .subscribe() returns.
|
372
|
-
let refetchSubscription;
|
374
|
+
let refetchSubscription: Subscription;
|
373
375
|
|
374
376
|
const storeSnapshot = this._getQueryFetcher().lookupInStore(
|
375
377
|
environment,
|
@@ -405,12 +407,12 @@ function createContainerWithFragments<
|
|
405
407
|
// TODO (T26430099): Cleanup old references
|
406
408
|
preservePreviousReferences: true,
|
407
409
|
})
|
408
|
-
.mergeMap(response => {
|
410
|
+
.mergeMap<void>(response => {
|
409
411
|
this.state.resolver.setVariables(
|
410
412
|
fragmentVariables,
|
411
413
|
operation.request.node,
|
412
414
|
);
|
413
|
-
return Observable.create(sink =>
|
415
|
+
return Observable.create<void>(sink =>
|
414
416
|
this.setState(
|
415
417
|
latestState => ({
|
416
418
|
data: latestState.resolver.resolve(),
|
@@ -447,7 +449,9 @@ function createContainerWithFragments<
|
|
447
449
|
};
|
448
450
|
};
|
449
451
|
|
452
|
+
// $FlowFixMe[missing-local-annot]
|
450
453
|
render() {
|
454
|
+
// eslint-disable-next-line no-unused-vars
|
451
455
|
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
452
456
|
this.props;
|
453
457
|
const {relayProp, contextForChildren} = this.state;
|
@@ -6,6 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
@@ -13,6 +14,7 @@
|
|
13
14
|
import type {
|
14
15
|
CacheConfig,
|
15
16
|
ConcreteRequest,
|
17
|
+
GraphQLResponse,
|
16
18
|
GraphQLSingularResponse,
|
17
19
|
IEnvironment,
|
18
20
|
PayloadError,
|
@@ -145,7 +147,7 @@ class ReactRelayTestMocker {
|
|
145
147
|
) => {
|
146
148
|
let resolve;
|
147
149
|
let reject;
|
148
|
-
const promise = new Promise((res, rej) => {
|
150
|
+
const promise = new Promise<GraphQLResponse>((res, rej) => {
|
149
151
|
resolve = res;
|
150
152
|
reject = rej;
|
151
153
|
});
|
package/ReactRelayTypes.js.flow
CHANGED
package/RelayContext.js.flow
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
@@ -139,7 +140,7 @@ module.exports = {
|
|
139
140
|
render(): React.Element<typeof Bar> {
|
140
141
|
return (
|
141
142
|
<Bar
|
142
|
-
componentRef={ref => {
|
143
|
+
componentRef={(ref: empty) => {
|
143
144
|
this._barRef = (ref: empty);
|
144
145
|
}}
|
145
146
|
requiredProp="bar"
|
package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<97ebbfa87de00690617b84f5dc0b3dd7>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow
CHANGED
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<493af2df808158f1c08ec6aafda2e783>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow
CHANGED
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<073d1d174775daaac06d462623886192>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
@@ -16,7 +18,7 @@
|
|
16
18
|
|
17
19
|
/*::
|
18
20
|
import type { ConcreteRequest, Query } from 'relay-runtime';
|
19
|
-
type ReactRelayPaginationContainerFlowtest_viewer$fragmentType
|
21
|
+
import type { ReactRelayPaginationContainerFlowtest_viewer$fragmentType } from "./ReactRelayPaginationContainerFlowtest_viewer.graphql";
|
20
22
|
export type ReactRelayPaginationContainerFlowtestQuery$variables = {|
|
21
23
|
count: number,
|
22
24
|
cursor?: ?string,
|
package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<03cbc84be1e0fb9c3986ea29a3e335db>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<909036439f4d2e9e2d5728ade52035dc>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
@@ -16,7 +18,7 @@
|
|
16
18
|
|
17
19
|
/*::
|
18
20
|
import type { ConcreteRequest, Query } from 'relay-runtime';
|
19
|
-
type ReactRelayRefetchContainerFlowtest_viewer$fragmentType
|
21
|
+
import type { ReactRelayRefetchContainerFlowtest_viewer$fragmentType } from "./ReactRelayRefetchContainerFlowtest_viewer.graphql";
|
20
22
|
export type ReactRelayRefetchContainerFlowtestQuery$variables = {|
|
21
23
|
count: number,
|
22
24
|
cursor?: ?string,
|
package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<6f9cebfabb127ad6db1de1705f8a9764>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
@@ -4,7 +4,9 @@
|
|
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.
|
6
6
|
*
|
7
|
-
* @
|
7
|
+
* @oncall relay
|
8
|
+
*
|
9
|
+
* @generated SignedSource<<1d67fc8ab171aeb4c45cb1df2d036371>>
|
8
10
|
* @flow
|
9
11
|
* @lightSyntaxTransform
|
10
12
|
* @nogrep
|
@@ -16,7 +18,7 @@
|
|
16
18
|
|
17
19
|
/*::
|
18
20
|
import type { Fragment, ReaderFragment } from 'relay-runtime';
|
19
|
-
type RelayModernFlowtest_user$fragmentType
|
21
|
+
import type { RelayModernFlowtest_user$fragmentType } from "./RelayModernFlowtest_user.graphql";
|
20
22
|
import type { FragmentType } from "relay-runtime";
|
21
23
|
declare export opaque type RelayModernFlowtest_badref$fragmentType: FragmentType;
|
22
24
|
export type RelayModernFlowtest_badref$data = {|
|