react-relay 14.1.0 → 16.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 +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -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 +10 -6
- 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 +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -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 +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- 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 +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- 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 +9 -7
- 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 +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- 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 +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- 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 +7 -6
- 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 +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- 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';
|
@@ -26,11 +27,7 @@ const {
|
|
26
27
|
isRelayModernEnvironment,
|
27
28
|
} = require('relay-runtime');
|
28
29
|
|
29
|
-
type OnDataChange = ({
|
30
|
-
error?: Error,
|
31
|
-
snapshot?: Snapshot,
|
32
|
-
...
|
33
|
-
}) => void;
|
30
|
+
type OnDataChange = ({error?: Error, snapshot?: Snapshot, ...}) => void;
|
34
31
|
|
35
32
|
/** The external API of 'fetch' **/
|
36
33
|
export type FetchOptions = {
|
@@ -62,7 +59,7 @@ class ReactRelayQueryFetcher {
|
|
62
59
|
_snapshot: ?Snapshot; // results of the root fragment;
|
63
60
|
_error: ?Error; // fetch error
|
64
61
|
_cacheSelectionReference: ?Disposable;
|
65
|
-
|
62
|
+
_didFetchFinish: boolean = false;
|
66
63
|
|
67
64
|
constructor(args?: {
|
68
65
|
cacheSelectionReference: ?Disposable,
|
@@ -102,6 +99,19 @@ class ReactRelayQueryFetcher {
|
|
102
99
|
return null;
|
103
100
|
}
|
104
101
|
|
102
|
+
getFetchResult(): ?{error?: Error, snapshot?: Snapshot} {
|
103
|
+
if (this._didFetchFinish) {
|
104
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
105
|
+
if (this._error != null) {
|
106
|
+
return {error: this._error};
|
107
|
+
} else if (this._snapshot != null) {
|
108
|
+
return {snapshot: this._snapshot};
|
109
|
+
}
|
110
|
+
} else {
|
111
|
+
return null;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
105
115
|
execute({
|
106
116
|
environment,
|
107
117
|
operation,
|
@@ -151,8 +161,8 @@ class ReactRelayQueryFetcher {
|
|
151
161
|
this._fetchOptions.onDataChangeCallbacks || [];
|
152
162
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
153
163
|
|
154
|
-
if (this.
|
155
|
-
// We don't reset '
|
164
|
+
if (this._didFetchFinish) {
|
165
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
156
166
|
if (this._error != null) {
|
157
167
|
onDataChange({error: this._error});
|
158
168
|
} else if (this._snapshot != null) {
|
@@ -215,7 +225,7 @@ class ReactRelayQueryFetcher {
|
|
215
225
|
next: () => {
|
216
226
|
// If we received a response,
|
217
227
|
// Make a note that to notify the callback when it's later added.
|
218
|
-
this.
|
228
|
+
this._didFetchFinish = true;
|
219
229
|
this._error = null;
|
220
230
|
|
221
231
|
// Only notify of the first result if `next` is being called **asynchronously**
|
@@ -225,7 +235,7 @@ class ReactRelayQueryFetcher {
|
|
225
235
|
error: err => {
|
226
236
|
// If we received a response when we didn't have a change callback,
|
227
237
|
// Make a note that to notify the callback when it's later added.
|
228
|
-
this.
|
238
|
+
this._didFetchFinish = true;
|
229
239
|
this._error = err;
|
230
240
|
this._snapshot = null;
|
231
241
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
12
|
'use strict';
|
@@ -35,11 +36,7 @@ const {
|
|
35
36
|
type RetryCallbacks = {
|
36
37
|
handleDataChange:
|
37
38
|
| null
|
38
|
-
| (({
|
39
|
-
error?: Error,
|
40
|
-
snapshot?: Snapshot,
|
41
|
-
...
|
42
|
-
}) => void),
|
39
|
+
| (({error?: Error, snapshot?: Snapshot, ...}) => void),
|
43
40
|
handleRetryAfterError: null | ((error: Error) => void),
|
44
41
|
};
|
45
42
|
|
@@ -64,14 +61,14 @@ const queryRendererContext: ReactRelayQueryRendererContextType = {
|
|
64
61
|
rootIsQueryRenderer: true,
|
65
62
|
};
|
66
63
|
|
67
|
-
export type Props = {
|
64
|
+
export type Props = $ReadOnly<{
|
68
65
|
cacheConfig?: ?CacheConfig,
|
69
66
|
fetchPolicy?: 'store-and-network' | 'network-only',
|
70
67
|
environment: IEnvironment,
|
71
68
|
query: ?GraphQLTaggedNode,
|
72
69
|
render: (renderProps: RenderProps<Object>) => React.Node,
|
73
70
|
variables: Variables,
|
74
|
-
}
|
71
|
+
}>;
|
75
72
|
|
76
73
|
type State = {
|
77
74
|
error: Error | null,
|
@@ -129,6 +126,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
129
126
|
|
130
127
|
this._maybeHiddenOrFastRefresh = false;
|
131
128
|
|
129
|
+
// $FlowFixMe[incompatible-type]
|
132
130
|
this.state = {
|
133
131
|
prevPropsEnvironment: props.environment,
|
134
132
|
prevPropsVariables: props.variables,
|
@@ -147,7 +145,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
147
145
|
static getDerivedStateFromProps(
|
148
146
|
nextProps: Props,
|
149
147
|
prevState: State,
|
150
|
-
):
|
148
|
+
): Partial<State> | null {
|
151
149
|
if (
|
152
150
|
prevState.prevQuery !== nextProps.query ||
|
153
151
|
prevState.prevPropsEnvironment !== nextProps.environment ||
|
@@ -169,7 +167,13 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
169
167
|
this._maybeHiddenOrFastRefresh = false;
|
170
168
|
// eslint-disable-next-line react/no-did-mount-set-state
|
171
169
|
this.setState(prevState => {
|
172
|
-
|
170
|
+
const newState = resetQueryStateForUpdate(this.props, prevState);
|
171
|
+
const {requestCacheKey, queryFetcher} = newState;
|
172
|
+
if (requestCacheKey != null && requestCache[requestCacheKey] != null) {
|
173
|
+
// $FlowFixMe[incompatible-use]
|
174
|
+
queryFetcher.setOnDataChange(this._handleDataChange);
|
175
|
+
}
|
176
|
+
return newState;
|
173
177
|
});
|
174
178
|
return;
|
175
179
|
}
|
@@ -335,7 +339,7 @@ function getRequestCacheKey(
|
|
335
339
|
function resetQueryStateForUpdate(
|
336
340
|
props: Props,
|
337
341
|
prevState: State,
|
338
|
-
):
|
342
|
+
): Partial<State> {
|
339
343
|
const {query} = props;
|
340
344
|
|
341
345
|
const prevSelectionReferences =
|
@@ -372,7 +376,7 @@ function fetchQueryAndComputeStateFromProps(
|
|
372
376
|
queryFetcher: ReactRelayQueryFetcher,
|
373
377
|
retryCallbacks: RetryCallbacks,
|
374
378
|
requestCacheKey: ?string,
|
375
|
-
):
|
379
|
+
): Partial<State> {
|
376
380
|
const {environment, query, variables, cacheConfig} = props;
|
377
381
|
const genericEnvironment = (environment: IEnvironment);
|
378
382
|
if (query) {
|
@@ -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
@@ -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';
|
@@ -101,6 +102,7 @@ export type $FragmentRef<T> = {
|
|
101
102
|
* `props.relay` and returns the props of the container.
|
102
103
|
*/
|
103
104
|
// prettier-ignore
|
105
|
+
// $FlowFixMe[extra-type-arg] xplat redux flow type error
|
104
106
|
export type $RelayProps<Props, RelayPropT = RelayProp> = $ObjMap<
|
105
107
|
$Diff<Props, { relay: RelayPropT | void, ... }>,
|
106
108
|
& (<T: { +$fragmentType: empty, ... }>( T) => T)
|
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,
|