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
package/ReactRelayContext.js
CHANGED
@@ -11,14 +11,13 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
|
13
13
|
'use strict';
|
14
|
-
|
14
|
+
import type {RelayContext} from 'relay-runtime/store/RelayStoreTypes';
|
15
15
|
|
16
|
+
const React = require('react');
|
16
17
|
const {
|
17
18
|
__internal: {createRelayContext},
|
18
19
|
} = require('relay-runtime');
|
19
20
|
|
20
|
-
import type {RelayContext} from 'relay-runtime/store/RelayStoreTypes';
|
21
|
-
|
22
21
|
module.exports = (createRelayContext(
|
23
22
|
React,
|
24
23
|
): React$Context<RelayContext | null>);
|
@@ -12,26 +12,24 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
|
15
|
+
import type {GeneratedNodeMap, RelayProp, $RelayProps} from './ReactRelayTypes';
|
16
|
+
import type {
|
17
|
+
FragmentMap,
|
18
|
+
FragmentSpecResolver,
|
19
|
+
RelayContext,
|
20
|
+
} from 'relay-runtime';
|
16
21
|
|
17
|
-
const areEqual = require('areEqual');
|
18
22
|
const buildReactRelayContainer = require('./buildReactRelayContainer');
|
19
|
-
|
20
23
|
const {getContainerName} = require('./ReactRelayContainerUtils');
|
21
24
|
const {assertRelayContext} = require('./RelayContext');
|
25
|
+
const areEqual = require('areEqual');
|
26
|
+
const React = require('react');
|
22
27
|
const {
|
23
28
|
createFragmentSpecResolver,
|
24
29
|
getDataIDsFromObject,
|
25
30
|
isScalarAndEqual,
|
26
31
|
} = require('relay-runtime');
|
27
32
|
|
28
|
-
import type {$RelayProps, GeneratedNodeMap, RelayProp} from './ReactRelayTypes';
|
29
|
-
import type {
|
30
|
-
FragmentMap,
|
31
|
-
FragmentSpecResolver,
|
32
|
-
RelayContext,
|
33
|
-
} from 'relay-runtime';
|
34
|
-
|
35
33
|
type ContainerProps = $FlowFixMeProps;
|
36
34
|
type ContainerState = {
|
37
35
|
data: {[key: string]: mixed, ...},
|
@@ -237,12 +235,8 @@ function createContainerWithFragments<
|
|
237
235
|
}
|
238
236
|
|
239
237
|
render() {
|
240
|
-
const {
|
241
|
-
|
242
|
-
__relayContext,
|
243
|
-
__rootIsQueryRenderer,
|
244
|
-
...props
|
245
|
-
} = this.props;
|
238
|
+
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
239
|
+
this.props;
|
246
240
|
return React.createElement(Component, {
|
247
241
|
...props,
|
248
242
|
...this.state.data,
|
@@ -12,21 +12,20 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
|
15
|
+
import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
|
16
|
+
import type {GraphQLTaggedNode, IEnvironment, Variables} from 'relay-runtime';
|
17
|
+
|
16
18
|
const ReactRelayContext = require('./ReactRelayContext');
|
17
19
|
const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
18
|
-
|
19
|
-
const
|
20
|
+
const areEqual = require('areEqual');
|
21
|
+
const React = require('react');
|
20
22
|
const {
|
21
23
|
createOperationDescriptor,
|
22
24
|
deepFreeze,
|
23
25
|
getRequest,
|
24
26
|
} = require('relay-runtime');
|
25
27
|
|
26
|
-
const
|
27
|
-
|
28
|
-
import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
|
29
|
-
import type {GraphQLTaggedNode, IEnvironment, Variables} from 'relay-runtime';
|
28
|
+
const {useLayoutEffect, useState, useRef, useMemo} = React;
|
30
29
|
|
31
30
|
type Props = {
|
32
31
|
environment: IEnvironment,
|
@@ -12,39 +12,12 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
const ReactRelayContext = require('./ReactRelayContext');
|
17
|
-
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
18
|
-
|
19
|
-
const areEqual = require('areEqual');
|
20
|
-
const buildReactRelayContainer = require('./buildReactRelayContainer');
|
21
|
-
const getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
22
|
-
const invariant = require('invariant');
|
23
|
-
const warning = require('warning');
|
24
|
-
|
25
|
-
const {
|
26
|
-
getComponentName,
|
27
|
-
getContainerName,
|
28
|
-
} = require('./ReactRelayContainerUtils');
|
29
|
-
const {assertRelayContext} = require('./RelayContext');
|
30
|
-
const {
|
31
|
-
ConnectionInterface,
|
32
|
-
Observable,
|
33
|
-
createFragmentSpecResolver,
|
34
|
-
createOperationDescriptor,
|
35
|
-
getDataIDsFromObject,
|
36
|
-
getRequest,
|
37
|
-
getVariablesFromObject,
|
38
|
-
isScalarAndEqual,
|
39
|
-
RelayFeatureFlags,
|
40
|
-
} = require('relay-runtime');
|
41
|
-
|
42
15
|
import type {
|
43
|
-
$RelayProps,
|
44
|
-
ObserverOrCallback,
|
45
16
|
GeneratedNodeMap,
|
17
|
+
ObserverOrCallback,
|
46
18
|
RefetchOptions,
|
47
19
|
RelayPaginationProp,
|
20
|
+
$RelayProps,
|
48
21
|
} from './ReactRelayTypes';
|
49
22
|
import type {
|
50
23
|
CacheConfig,
|
@@ -60,6 +33,31 @@ import type {
|
|
60
33
|
Variables,
|
61
34
|
} from 'relay-runtime';
|
62
35
|
|
36
|
+
const buildReactRelayContainer = require('./buildReactRelayContainer');
|
37
|
+
const getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
38
|
+
const {
|
39
|
+
getComponentName,
|
40
|
+
getContainerName,
|
41
|
+
} = require('./ReactRelayContainerUtils');
|
42
|
+
const ReactRelayContext = require('./ReactRelayContext');
|
43
|
+
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
44
|
+
const {assertRelayContext} = require('./RelayContext');
|
45
|
+
const areEqual = require('areEqual');
|
46
|
+
const invariant = require('invariant');
|
47
|
+
const React = require('react');
|
48
|
+
const {
|
49
|
+
ConnectionInterface,
|
50
|
+
Observable,
|
51
|
+
RelayFeatureFlags,
|
52
|
+
createFragmentSpecResolver,
|
53
|
+
createOperationDescriptor,
|
54
|
+
getDataIDsFromObject,
|
55
|
+
getRequest,
|
56
|
+
getVariablesFromObject,
|
57
|
+
isScalarAndEqual,
|
58
|
+
} = require('relay-runtime');
|
59
|
+
const warning = require('warning');
|
60
|
+
|
63
61
|
type ContainerState = {
|
64
62
|
data: {[key: string]: mixed, ...},
|
65
63
|
relayProp: RelayPaginationProp,
|
@@ -258,7 +256,6 @@ function createGetFragmentVariables(
|
|
258
256
|
'ReactRelayPaginationContainer: Unable to synthesize a ' +
|
259
257
|
'getFragmentVariables function.',
|
260
258
|
);
|
261
|
-
// $FlowFixMe[cannot-spread-interface]
|
262
259
|
return (prevVars: Variables, totalCount: number) => ({
|
263
260
|
...prevVars,
|
264
261
|
[countVariable]: totalCount,
|
@@ -766,9 +763,7 @@ function createContainerWithFragments<
|
|
766
763
|
};
|
767
764
|
let fragmentVariables;
|
768
765
|
const rootVariables = getRootVariablesForFragments(fragments, restProps);
|
769
|
-
// $FlowFixMe[cannot-spread-interface]
|
770
766
|
fragmentVariables = getVariablesFromObject(fragments, restProps);
|
771
|
-
// $FlowFixMe[cannot-spread-interface]
|
772
767
|
fragmentVariables = {
|
773
768
|
...rootVariables,
|
774
769
|
...fragmentVariables,
|
@@ -789,7 +784,6 @@ function createContainerWithFragments<
|
|
789
784
|
fetchVariables,
|
790
785
|
componentName,
|
791
786
|
);
|
792
|
-
// $FlowFixMe[cannot-spread-interface]
|
793
787
|
fetchVariables = {
|
794
788
|
...fetchVariables,
|
795
789
|
...this._refetchVariables,
|
@@ -906,12 +900,8 @@ function createContainerWithFragments<
|
|
906
900
|
}
|
907
901
|
|
908
902
|
render() {
|
909
|
-
const {
|
910
|
-
|
911
|
-
__relayContext,
|
912
|
-
__rootIsQueryRenderer,
|
913
|
-
...props
|
914
|
-
} = this.props;
|
903
|
+
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
904
|
+
this.props;
|
915
905
|
return (
|
916
906
|
<ReactRelayContext.Provider value={this.state.contextForChildren}>
|
917
907
|
<Component
|
@@ -12,14 +12,6 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const invariant = require('invariant');
|
16
|
-
|
17
|
-
const {
|
18
|
-
createOperationDescriptor,
|
19
|
-
isRelayModernEnvironment,
|
20
|
-
__internal: {fetchQuery},
|
21
|
-
} = require('relay-runtime');
|
22
|
-
|
23
15
|
import type {
|
24
16
|
CacheConfig,
|
25
17
|
Disposable,
|
@@ -29,6 +21,13 @@ import type {
|
|
29
21
|
Snapshot,
|
30
22
|
} from 'relay-runtime';
|
31
23
|
|
24
|
+
const invariant = require('invariant');
|
25
|
+
const {
|
26
|
+
__internal: {fetchQuery},
|
27
|
+
createOperationDescriptor,
|
28
|
+
isRelayModernEnvironment,
|
29
|
+
} = require('relay-runtime');
|
30
|
+
|
32
31
|
type OnDataChange = ({
|
33
32
|
error?: Error,
|
34
33
|
snapshot?: Snapshot,
|
@@ -341,8 +340,8 @@ class ReactRelayQueryFetcher {
|
|
341
340
|
this._rootSubscription = environment.subscribe(this._snapshot, snapshot => {
|
342
341
|
// Read from this._fetchOptions in case onDataChange() was lazily added.
|
343
342
|
if (this._fetchOptions != null) {
|
344
|
-
const maybeNewOnDataChangeCallbacks =
|
345
|
-
.onDataChangeCallbacks;
|
343
|
+
const maybeNewOnDataChangeCallbacks =
|
344
|
+
this._fetchOptions.onDataChangeCallbacks;
|
346
345
|
if (Array.isArray(maybeNewOnDataChangeCallbacks)) {
|
347
346
|
maybeNewOnDataChangeCallbacks.forEach(onDataChange =>
|
348
347
|
onDataChange({snapshot}),
|
@@ -12,20 +12,6 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
const ReactRelayContext = require('./ReactRelayContext');
|
17
|
-
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
18
|
-
const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
19
|
-
|
20
|
-
const areEqual = require('areEqual');
|
21
|
-
|
22
|
-
const {
|
23
|
-
createOperationDescriptor,
|
24
|
-
deepFreeze,
|
25
|
-
getRequest,
|
26
|
-
RelayFeatureFlags,
|
27
|
-
} = require('relay-runtime');
|
28
|
-
|
29
15
|
import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
|
30
16
|
import type {
|
31
17
|
CacheConfig,
|
@@ -36,6 +22,19 @@ import type {
|
|
36
22
|
Snapshot,
|
37
23
|
Variables,
|
38
24
|
} from 'relay-runtime';
|
25
|
+
|
26
|
+
const ReactRelayContext = require('./ReactRelayContext');
|
27
|
+
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
28
|
+
const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
29
|
+
const areEqual = require('areEqual');
|
30
|
+
const React = require('react');
|
31
|
+
const {
|
32
|
+
RelayFeatureFlags,
|
33
|
+
createOperationDescriptor,
|
34
|
+
deepFreeze,
|
35
|
+
getRequest,
|
36
|
+
} = require('relay-runtime');
|
37
|
+
|
39
38
|
type RetryCallbacks = {|
|
40
39
|
handleDataChange:
|
41
40
|
| null
|
@@ -340,7 +339,8 @@ function resetQueryStateForUpdate(
|
|
340
339
|
): $Shape<State> {
|
341
340
|
const {query} = props;
|
342
341
|
|
343
|
-
const prevSelectionReferences =
|
342
|
+
const prevSelectionReferences =
|
343
|
+
prevState.queryFetcher.getSelectionReferences();
|
344
344
|
prevState.queryFetcher.disposeRequest();
|
345
345
|
|
346
346
|
let queryFetcher;
|
@@ -12,33 +12,12 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
const ReactRelayContext = require('./ReactRelayContext');
|
17
|
-
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
18
|
-
|
19
|
-
const areEqual = require('areEqual');
|
20
|
-
const buildReactRelayContainer = require('./buildReactRelayContainer');
|
21
|
-
const getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
22
|
-
const warning = require('warning');
|
23
|
-
|
24
|
-
const {getContainerName} = require('./ReactRelayContainerUtils');
|
25
|
-
const {assertRelayContext} = require('./RelayContext');
|
26
|
-
const {
|
27
|
-
Observable,
|
28
|
-
createFragmentSpecResolver,
|
29
|
-
createOperationDescriptor,
|
30
|
-
getDataIDsFromObject,
|
31
|
-
getRequest,
|
32
|
-
getVariablesFromObject,
|
33
|
-
isScalarAndEqual,
|
34
|
-
} = require('relay-runtime');
|
35
|
-
|
36
15
|
import type {
|
37
|
-
$RelayProps,
|
38
|
-
ObserverOrCallback,
|
39
16
|
GeneratedNodeMap,
|
17
|
+
ObserverOrCallback,
|
40
18
|
RefetchOptions,
|
41
19
|
RelayRefetchProp,
|
20
|
+
$RelayProps,
|
42
21
|
} from './ReactRelayTypes';
|
43
22
|
import type {
|
44
23
|
CacheConfig,
|
@@ -51,6 +30,25 @@ import type {
|
|
51
30
|
} from 'relay-runtime';
|
52
31
|
import type {FragmentSpecResolver} from 'relay-runtime';
|
53
32
|
|
33
|
+
const buildReactRelayContainer = require('./buildReactRelayContainer');
|
34
|
+
const getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
35
|
+
const {getContainerName} = require('./ReactRelayContainerUtils');
|
36
|
+
const ReactRelayContext = require('./ReactRelayContext');
|
37
|
+
const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
38
|
+
const {assertRelayContext} = require('./RelayContext');
|
39
|
+
const areEqual = require('areEqual');
|
40
|
+
const React = require('react');
|
41
|
+
const {
|
42
|
+
Observable,
|
43
|
+
createFragmentSpecResolver,
|
44
|
+
createOperationDescriptor,
|
45
|
+
getDataIDsFromObject,
|
46
|
+
getRequest,
|
47
|
+
getVariablesFromObject,
|
48
|
+
isScalarAndEqual,
|
49
|
+
} = require('relay-runtime');
|
50
|
+
const warning = require('warning');
|
51
|
+
|
54
52
|
type ContainerProps = $FlowFixMeProps;
|
55
53
|
|
56
54
|
type ContainerState = {
|
@@ -332,11 +330,9 @@ function createContainerWithFragments<
|
|
332
330
|
typeof refetchVariables === 'function'
|
333
331
|
? refetchVariables(this._getFragmentVariables())
|
334
332
|
: refetchVariables;
|
335
|
-
// $FlowFixMe[cannot-spread-interface]
|
336
333
|
fetchVariables = {...rootVariables, ...fetchVariables};
|
337
334
|
const fragmentVariables = renderVariables
|
338
|
-
?
|
339
|
-
{...fetchVariables, ...renderVariables}
|
335
|
+
? {...fetchVariables, ...renderVariables}
|
340
336
|
: fetchVariables;
|
341
337
|
|
342
338
|
const cacheConfig: ?CacheConfig = options
|
@@ -452,12 +448,8 @@ function createContainerWithFragments<
|
|
452
448
|
};
|
453
449
|
|
454
450
|
render() {
|
455
|
-
const {
|
456
|
-
|
457
|
-
__relayContext,
|
458
|
-
__rootIsQueryRenderer,
|
459
|
-
...props
|
460
|
-
} = this.props;
|
451
|
+
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
452
|
+
this.props;
|
461
453
|
const {relayProp, contextForChildren} = this.state;
|
462
454
|
return (
|
463
455
|
<ReactRelayContext.Provider value={contextForChildren}>
|
@@ -12,16 +12,6 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const areEqual = require('areEqual');
|
16
|
-
const invariant = require('invariant');
|
17
|
-
const warning = require('warning');
|
18
|
-
|
19
|
-
const {
|
20
|
-
createOperationDescriptor,
|
21
|
-
isRelayModernEnvironment,
|
22
|
-
Network,
|
23
|
-
} = require('relay-runtime');
|
24
|
-
|
25
15
|
import type {
|
26
16
|
CacheConfig,
|
27
17
|
ConcreteRequest,
|
@@ -32,6 +22,15 @@ import type {
|
|
32
22
|
Variables,
|
33
23
|
} from 'relay-runtime';
|
34
24
|
|
25
|
+
const areEqual = require('areEqual');
|
26
|
+
const invariant = require('invariant');
|
27
|
+
const {
|
28
|
+
Network,
|
29
|
+
createOperationDescriptor,
|
30
|
+
isRelayModernEnvironment,
|
31
|
+
} = require('relay-runtime');
|
32
|
+
const warning = require('warning');
|
33
|
+
|
35
34
|
export type DataWriteConfig = {
|
36
35
|
query: ConcreteRequest,
|
37
36
|
variables: Variables,
|
@@ -66,7 +65,7 @@ let nextId = 0;
|
|
66
65
|
|
67
66
|
class ReactRelayTestMocker {
|
68
67
|
_environment: IEnvironment;
|
69
|
-
_defaults: {[string]:
|
68
|
+
_defaults: {[string]: NetworkWriteConfig['payload'], ...} = {};
|
70
69
|
_pendingFetches: Array<PendingFetch> = [];
|
71
70
|
|
72
71
|
constructor(env: IEnvironment) {
|
@@ -118,7 +117,6 @@ class ReactRelayTestMocker {
|
|
118
117
|
* annoying to test (e.g. client_mutation_id, actor_id)
|
119
118
|
*/
|
120
119
|
static stripUnused(variables: Variables): Variables {
|
121
|
-
// $FlowFixMe[prop-missing]
|
122
120
|
if (variables.input) {
|
123
121
|
const toRemove = [
|
124
122
|
'client_mutation_id',
|
@@ -126,7 +124,6 @@ class ReactRelayTestMocker {
|
|
126
124
|
'clientMutationId',
|
127
125
|
'actorId',
|
128
126
|
];
|
129
|
-
// $FlowFixMe[cannot-spread-interface]
|
130
127
|
const strippedVariables = {...variables, input: {...variables.input}};
|
131
128
|
toRemove.forEach(item => (strippedVariables.input[item] = undefined));
|
132
129
|
return strippedVariables;
|
@@ -143,7 +140,11 @@ class ReactRelayTestMocker {
|
|
143
140
|
* their components behave under error conditions.
|
144
141
|
*/
|
145
142
|
_mockNetworkLayer(env: IEnvironment): IEnvironment {
|
146
|
-
const fetch = (
|
143
|
+
const fetch = (
|
144
|
+
request: RequestParameters,
|
145
|
+
variables: Variables,
|
146
|
+
cacheConfig: CacheConfig,
|
147
|
+
) => {
|
147
148
|
let resolve;
|
148
149
|
let reject;
|
149
150
|
const promise = new Promise((res, rej) => {
|
@@ -314,6 +315,7 @@ class ReactRelayTestMocker {
|
|
314
315
|
);
|
315
316
|
|
316
317
|
const realPayload =
|
318
|
+
// $FlowFixMe[incompatible-call]
|
317
319
|
typeof payload === 'function' ? payload(toResolve.variables) : payload;
|
318
320
|
|
319
321
|
// if there are errors, reject the query
|
package/ReactRelayTypes.js.flow
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
import type {
|
16
16
|
Disposable,
|
17
|
-
|
17
|
+
FragmentType,
|
18
18
|
GraphQLTaggedNode,
|
19
19
|
IEnvironment,
|
20
20
|
Observer,
|
@@ -94,7 +94,7 @@ export type RefetchOptions = {|
|
|
94
94
|
*
|
95
95
|
*/
|
96
96
|
export type $FragmentRef<T> = {
|
97
|
-
+$
|
97
|
+
+$fragmentSpreads: T['$fragmentType'],
|
98
98
|
...
|
99
99
|
};
|
100
100
|
|
@@ -105,14 +105,14 @@ export type $FragmentRef<T> = {
|
|
105
105
|
// prettier-ignore
|
106
106
|
export type $RelayProps<Props, RelayPropT = RelayProp> = $ObjMap<
|
107
107
|
$Diff<Props, { relay: RelayPropT | void, ... }>,
|
108
|
-
& (<T: { +$
|
109
|
-
& (<T: { +$
|
110
|
-
& (<
|
111
|
-
& (<
|
112
|
-
& (<
|
113
|
-
& (<
|
114
|
-
& (<
|
115
|
-
& (<
|
108
|
+
& (<T: { +$fragmentType: empty, ... }>( T) => T)
|
109
|
+
& (<T: { +$fragmentType: empty, ... }>(?T) => ?T)
|
110
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( T ) => $FragmentRef<T> )
|
111
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(? T ) => ? $FragmentRef<T> )
|
112
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef<T>>)
|
113
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef<T>>)
|
114
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray<?T>) => $ReadOnlyArray<?$FragmentRef<T>>)
|
115
|
+
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray<?T>) => ?$ReadOnlyArray<?$FragmentRef<T>>)
|
116
116
|
& (<T>(T) => T),
|
117
117
|
>;
|
118
118
|
|
package/RelayContext.js.flow
CHANGED
@@ -12,11 +12,11 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const invariant = require('invariant');
|
16
|
-
const isRelayEnvironment = require('./isRelayEnvironment');
|
17
|
-
|
18
15
|
import type {RelayContext} from 'relay-runtime';
|
19
16
|
|
17
|
+
const isRelayEnvironment = require('./isRelayEnvironment');
|
18
|
+
const invariant = require('invariant');
|
19
|
+
|
20
20
|
/**
|
21
21
|
* Asserts that the input is a matches the `RelayContext` type defined in
|
22
22
|
* `RelayEnvironmentTypes` and returns it as that type.
|
@@ -12,11 +12,10 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
|
17
15
|
const {
|
18
16
|
createContainer: createFragmentContainer,
|
19
17
|
} = require('../ReactRelayFragmentContainer');
|
18
|
+
const React = require('react');
|
20
19
|
const {graphql} = require('relay-runtime');
|
21
20
|
|
22
21
|
/**
|
@@ -12,11 +12,10 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
|
17
15
|
const {
|
18
16
|
createContainer: createPaginationContainer,
|
19
17
|
} = require('../ReactRelayPaginationContainer');
|
18
|
+
const React = require('react');
|
20
19
|
const {graphql} = require('relay-runtime');
|
21
20
|
|
22
21
|
/**
|
@@ -12,11 +12,10 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
const React = require('react');
|
16
|
-
|
17
15
|
const {
|
18
16
|
createContainer: createRefetchContainer,
|
19
17
|
} = require('../ReactRelayRefetchContainer');
|
18
|
+
const React = require('react');
|
20
19
|
const {graphql} = require('relay-runtime');
|
21
20
|
|
22
21
|
/**
|