react-relay 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +47 -0
- package/ReactRelayContainerUtils.js.flow +1 -1
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +3 -4
- package/ReactRelayFragmentContainer.js.flow +25 -25
- package/ReactRelayFragmentMockRenderer.js.flow +2 -2
- package/ReactRelayLocalQueryRenderer.js.flow +7 -8
- package/ReactRelayPaginationContainer.js.flow +112 -59
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +116 -82
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +42 -39
- package/ReactRelayTestMocker.js.flow +17 -15
- package/ReactRelayTypes.js.flow +11 -11
- package/RelayContext.js.flow +4 -4
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
- package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
- package/assertFragmentMap.js.flow +3 -3
- package/buildReactRelayContainer.js.flow +12 -11
- package/getRootVariablesForFragments.js.flow +3 -5
- package/hooks.js +1 -1
- package/hooks.js.flow +6 -7
- package/index.js +1 -1
- package/index.js.flow +7 -8
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/enqueueTask.js.flow +56 -0
- package/jest-react/index.js.flow +12 -0
- package/jest-react/internalAct.js.flow +138 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -1
- package/lib/ReactRelayContainerUtils.js +1 -1
- package/lib/ReactRelayContext.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +22 -16
- package/lib/ReactRelayFragmentMockRenderer.js +3 -3
- package/lib/ReactRelayLocalQueryRenderer.js +8 -9
- package/lib/ReactRelayPaginationContainer.js +97 -39
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +87 -54
- package/lib/ReactRelayQueryRendererContext.js +1 -1
- package/lib/ReactRelayRefetchContainer.js +39 -26
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +4 -3
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +8 -8
- package/lib/getRootVariablesForFragments.js +2 -3
- package/lib/hooks.js +6 -6
- package/lib/index.js +8 -8
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/jest-react/enqueueTask.js +53 -0
- package/lib/jest-react/index.js +13 -0
- package/lib/jest-react/internalAct.js +115 -0
- package/lib/legacy.js +1 -1
- package/lib/multi-actor/ActorChange.js +30 -0
- package/lib/multi-actor/index.js +11 -0
- package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
- package/lib/readContext.js +1 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
- package/lib/relay-hooks/FragmentResource.js +342 -89
- package/lib/relay-hooks/InternalLogger.js +1 -1
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +1 -1
- package/lib/relay-hooks/QueryResource.js +172 -29
- package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadEntryPoint.js +1 -1
- package/lib/relay-hooks/loadQuery.js +42 -20
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
- package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
- package/lib/relay-hooks/useEntryPointLoader.js +3 -3
- package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
- package/lib/relay-hooks/useFragment.js +7 -7
- package/lib/relay-hooks/useFragmentNode.js +5 -5
- package/lib/relay-hooks/useIsMountedRef.js +1 -1
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
- package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
- package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
- package/lib/relay-hooks/useMemoVariables.js +3 -3
- package/lib/relay-hooks/useMutation.js +18 -7
- package/lib/relay-hooks/usePaginationFragment.js +3 -4
- package/lib/relay-hooks/usePreloadedQuery.js +6 -6
- package/lib/relay-hooks/useQueryLoader.js +31 -11
- package/lib/relay-hooks/useRefetchableFragment.js +1 -1
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
- package/lib/relay-hooks/useSubscription.js +11 -8
- package/multi-actor/ActorChange.js.flow +58 -0
- package/multi-actor/index.js.flow +14 -0
- package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
- package/package.json +3 -3
- 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/readContext.js.flow +1 -1
- package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
- package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
- package/relay-hooks/FragmentResource.js.flow +359 -93
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
- package/relay-hooks/MatchContainer.js.flow +4 -3
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +217 -26
- package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/utils.js.flow +21 -32
- package/relay-hooks/loadEntryPoint.js.flow +7 -13
- package/relay-hooks/loadQuery.js.flow +50 -32
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
- package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
- package/relay-hooks/useEntryPointLoader.js.flow +8 -11
- package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
- package/relay-hooks/useFragment.js.flow +31 -62
- package/relay-hooks/useFragmentNode.js.flow +6 -8
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
- package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
- package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
- package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
- package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
- package/relay-hooks/useMemoVariables.js.flow +7 -7
- package/relay-hooks/useMutation.js.flow +27 -27
- package/relay-hooks/usePaginationFragment.js.flow +39 -45
- package/relay-hooks/usePreloadedQuery.js.flow +14 -20
- package/relay-hooks/useQueryLoader.js.flow +42 -23
- package/relay-hooks/useRefetchableFragment.js.flow +8 -9
- package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
- package/relay-hooks/useRelayEnvironment.js.flow +3 -5
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
- package/relay-hooks/useSubscription.js.flow +21 -11
- package/lib/relay-hooks/getPaginationMetadata.js +0 -41
- package/lib/relay-hooks/getPaginationVariables.js +0 -67
- package/lib/relay-hooks/getRefetchMetadata.js +0 -36
- package/lib/relay-hooks/getValueAtPath.js +0 -51
- package/relay-hooks/getPaginationMetadata.js.flow +0 -74
- package/relay-hooks/getPaginationVariables.js.flow +0 -110
- package/relay-hooks/getRefetchMetadata.js.flow +0 -80
- package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,74 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @emails oncall+relay
|
8
|
-
* @flow strict-local
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const getRefetchMetadata = require('./getRefetchMetadata');
|
17
|
-
const invariant = require('invariant');
|
18
|
-
|
19
|
-
import type {
|
20
|
-
ConcreteRequest,
|
21
|
-
ReaderFragment,
|
22
|
-
ReaderPaginationMetadata,
|
23
|
-
} from 'relay-runtime';
|
24
|
-
|
25
|
-
function getPaginationMetadata(
|
26
|
-
fragmentNode: ReaderFragment,
|
27
|
-
componentDisplayName: string,
|
28
|
-
): {|
|
29
|
-
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
30
|
-
identifierField: ?string,
|
31
|
-
paginationRequest: ConcreteRequest,
|
32
|
-
paginationMetadata: ReaderPaginationMetadata,
|
33
|
-
stream: boolean,
|
34
|
-
|} {
|
35
|
-
const {
|
36
|
-
refetchableRequest: paginationRequest,
|
37
|
-
refetchMetadata,
|
38
|
-
} = getRefetchMetadata(fragmentNode, componentDisplayName);
|
39
|
-
|
40
|
-
const paginationMetadata = refetchMetadata.connection;
|
41
|
-
invariant(
|
42
|
-
paginationMetadata != null,
|
43
|
-
'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' +
|
44
|
-
'connection when using `%s`. Did you forget to add a @connection ' +
|
45
|
-
'directive to the connection field in the fragment?',
|
46
|
-
componentDisplayName,
|
47
|
-
fragmentNode.name,
|
48
|
-
);
|
49
|
-
const connectionPathInFragmentData = paginationMetadata.path;
|
50
|
-
|
51
|
-
const connectionMetadata = (fragmentNode.metadata?.connection ?? [])[0];
|
52
|
-
invariant(
|
53
|
-
connectionMetadata != null,
|
54
|
-
'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' +
|
55
|
-
'connection when using `%s`. Did you forget to add a @connection ' +
|
56
|
-
'directive to the connection field in the fragment?',
|
57
|
-
componentDisplayName,
|
58
|
-
fragmentNode.name,
|
59
|
-
);
|
60
|
-
const identifierField = refetchMetadata.identifierField;
|
61
|
-
invariant(
|
62
|
-
identifierField == null || typeof identifierField === 'string',
|
63
|
-
'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.',
|
64
|
-
);
|
65
|
-
return {
|
66
|
-
connectionPathInFragmentData,
|
67
|
-
identifierField,
|
68
|
-
paginationRequest,
|
69
|
-
paginationMetadata,
|
70
|
-
stream: connectionMetadata.stream === true,
|
71
|
-
};
|
72
|
-
}
|
73
|
-
|
74
|
-
module.exports = getPaginationMetadata;
|
@@ -1,110 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @emails oncall+relay
|
8
|
-
* @flow strict-local
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const invariant = require('invariant');
|
17
|
-
const warning = require('warning');
|
18
|
-
|
19
|
-
import type {Direction} from './useLoadMoreFunction';
|
20
|
-
import type {ReaderPaginationMetadata, Variables} from 'relay-runtime';
|
21
|
-
|
22
|
-
function getPaginationVariables(
|
23
|
-
direction: Direction,
|
24
|
-
count: number,
|
25
|
-
cursor: ?string,
|
26
|
-
baseVariables: Variables,
|
27
|
-
extraVariables: Variables,
|
28
|
-
paginationMetadata: ReaderPaginationMetadata,
|
29
|
-
): {[string]: mixed, ...} {
|
30
|
-
const {
|
31
|
-
backward: backwardMetadata,
|
32
|
-
forward: forwardMetadata,
|
33
|
-
} = paginationMetadata;
|
34
|
-
|
35
|
-
if (direction === 'backward') {
|
36
|
-
invariant(
|
37
|
-
backwardMetadata != null &&
|
38
|
-
backwardMetadata.count != null &&
|
39
|
-
backwardMetadata.cursor != null,
|
40
|
-
'Relay: Expected backward pagination metadata to be available. ' +
|
41
|
-
"If you're seeing this, this is likely a bug in Relay.",
|
42
|
-
);
|
43
|
-
warning(
|
44
|
-
!extraVariables.hasOwnProperty(backwardMetadata.cursor),
|
45
|
-
'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
|
46
|
-
'contain cursor variable `%s`. This variable is automatically ' +
|
47
|
-
'determined by Relay.',
|
48
|
-
backwardMetadata.cursor,
|
49
|
-
);
|
50
|
-
warning(
|
51
|
-
!extraVariables.hasOwnProperty(backwardMetadata.count),
|
52
|
-
'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
|
53
|
-
'contain count variable `%s`. This variable is automatically ' +
|
54
|
-
'determined by Relay.',
|
55
|
-
backwardMetadata.count,
|
56
|
-
);
|
57
|
-
// $FlowFixMe[cannot-spread-interface]
|
58
|
-
const paginationVariables = {
|
59
|
-
...baseVariables,
|
60
|
-
...extraVariables,
|
61
|
-
[backwardMetadata.cursor]: cursor,
|
62
|
-
[backwardMetadata.count]: count,
|
63
|
-
};
|
64
|
-
if (forwardMetadata && forwardMetadata.cursor) {
|
65
|
-
paginationVariables[forwardMetadata.cursor] = null;
|
66
|
-
}
|
67
|
-
if (forwardMetadata && forwardMetadata.count) {
|
68
|
-
paginationVariables[forwardMetadata.count] = null;
|
69
|
-
}
|
70
|
-
return paginationVariables;
|
71
|
-
}
|
72
|
-
|
73
|
-
invariant(
|
74
|
-
forwardMetadata != null &&
|
75
|
-
forwardMetadata.count != null &&
|
76
|
-
forwardMetadata.cursor != null,
|
77
|
-
'Relay: Expected forward pagination metadata to be available. ' +
|
78
|
-
"If you're seeing this, this is likely a bug in Relay.",
|
79
|
-
);
|
80
|
-
warning(
|
81
|
-
!extraVariables.hasOwnProperty(forwardMetadata.cursor),
|
82
|
-
'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
|
83
|
-
'contain cursor variable `%s`. This variable is automatically ' +
|
84
|
-
'determined by Relay.',
|
85
|
-
forwardMetadata.cursor,
|
86
|
-
);
|
87
|
-
warning(
|
88
|
-
!extraVariables.hasOwnProperty(forwardMetadata.count),
|
89
|
-
'Relay: `UNSTABLE_extraVariables` provided by caller should not ' +
|
90
|
-
'contain count variable `%s`. This variable is automatically ' +
|
91
|
-
'determined by Relay.',
|
92
|
-
forwardMetadata.count,
|
93
|
-
);
|
94
|
-
// $FlowFixMe[cannot-spread-interface]
|
95
|
-
const paginationVariables = {
|
96
|
-
...baseVariables,
|
97
|
-
...extraVariables,
|
98
|
-
[forwardMetadata.cursor]: cursor,
|
99
|
-
[forwardMetadata.count]: count,
|
100
|
-
};
|
101
|
-
if (backwardMetadata && backwardMetadata.cursor) {
|
102
|
-
paginationVariables[backwardMetadata.cursor] = null;
|
103
|
-
}
|
104
|
-
if (backwardMetadata && backwardMetadata.count) {
|
105
|
-
paginationVariables[backwardMetadata.count] = null;
|
106
|
-
}
|
107
|
-
return paginationVariables;
|
108
|
-
}
|
109
|
-
|
110
|
-
module.exports = getPaginationVariables;
|
@@ -1,80 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @emails oncall+relay
|
8
|
-
* @flow strict-local
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const invariant = require('invariant');
|
17
|
-
|
18
|
-
import type {
|
19
|
-
ConcreteRequest,
|
20
|
-
ReaderFragment,
|
21
|
-
ReaderRefetchMetadata,
|
22
|
-
} from 'relay-runtime';
|
23
|
-
|
24
|
-
function getRefetchMetadata(
|
25
|
-
fragmentNode: ReaderFragment,
|
26
|
-
componentDisplayName: string,
|
27
|
-
): {|
|
28
|
-
fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
|
29
|
-
identifierField: ?string,
|
30
|
-
refetchableRequest: ConcreteRequest,
|
31
|
-
refetchMetadata: ReaderRefetchMetadata,
|
32
|
-
|} {
|
33
|
-
invariant(
|
34
|
-
fragmentNode.metadata?.plural !== true,
|
35
|
-
'Relay: getRefetchMetadata(): Expected fragment `%s` not to be plural when using ' +
|
36
|
-
'`%s`. Remove `@relay(plural: true)` from fragment `%s` ' +
|
37
|
-
'in order to use it with `%s`.',
|
38
|
-
fragmentNode.name,
|
39
|
-
componentDisplayName,
|
40
|
-
fragmentNode.name,
|
41
|
-
componentDisplayName,
|
42
|
-
);
|
43
|
-
|
44
|
-
const refetchMetadata = fragmentNode.metadata?.refetch;
|
45
|
-
invariant(
|
46
|
-
refetchMetadata != null,
|
47
|
-
'Relay: getRefetchMetadata(): Expected fragment `%s` to be refetchable when using `%s`. ' +
|
48
|
-
'Did you forget to add a @refetchable directive to the fragment?',
|
49
|
-
componentDisplayName,
|
50
|
-
fragmentNode.name,
|
51
|
-
);
|
52
|
-
|
53
|
-
// handle both commonjs and es modules
|
54
|
-
const refetchableRequest:
|
55
|
-
| ConcreteRequest
|
56
|
-
| string = (refetchMetadata: $FlowFixMe).operation.default
|
57
|
-
? (refetchMetadata: $FlowFixMe).operation.default
|
58
|
-
: refetchMetadata.operation;
|
59
|
-
const fragmentRefPathInResponse = refetchMetadata.fragmentPathInResult;
|
60
|
-
invariant(
|
61
|
-
typeof refetchableRequest !== 'string',
|
62
|
-
'Relay: getRefetchMetadata(): Expected refetch query to be an ' +
|
63
|
-
"operation and not a string when using `%s`. If you're seeing this, " +
|
64
|
-
'this is likely a bug in Relay.',
|
65
|
-
componentDisplayName,
|
66
|
-
);
|
67
|
-
const identifierField = refetchMetadata.identifierField;
|
68
|
-
invariant(
|
69
|
-
identifierField == null || typeof identifierField === 'string',
|
70
|
-
'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.',
|
71
|
-
);
|
72
|
-
return {
|
73
|
-
fragmentRefPathInResponse,
|
74
|
-
identifierField,
|
75
|
-
refetchableRequest,
|
76
|
-
refetchMetadata,
|
77
|
-
};
|
78
|
-
}
|
79
|
-
|
80
|
-
module.exports = getRefetchMetadata;
|
@@ -1,46 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
* @emails oncall+relay
|
8
|
-
* @flow strict-local
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const invariant = require('invariant');
|
17
|
-
|
18
|
-
function getValueAtPath(
|
19
|
-
data: mixed,
|
20
|
-
path: $ReadOnlyArray<string | number>,
|
21
|
-
): mixed {
|
22
|
-
let result = data;
|
23
|
-
for (const key of path) {
|
24
|
-
if (result == null) {
|
25
|
-
return null;
|
26
|
-
}
|
27
|
-
if (typeof key === 'number') {
|
28
|
-
invariant(
|
29
|
-
Array.isArray(result),
|
30
|
-
'Relay: Expected an array when extracting value at path. ' +
|
31
|
-
"If you're seeing this, this is likely a bug in Relay.",
|
32
|
-
);
|
33
|
-
result = result[key];
|
34
|
-
} else {
|
35
|
-
invariant(
|
36
|
-
typeof result === 'object' && !Array.isArray(result),
|
37
|
-
'Relay: Expected an object when extracting value at path. ' +
|
38
|
-
"If you're seeing this, this is likely a bug in Relay.",
|
39
|
-
);
|
40
|
-
result = result[key];
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return result;
|
44
|
-
}
|
45
|
-
|
46
|
-
module.exports = getValueAtPath;
|