relay-runtime 11.0.0 → 13.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/RelayDefaultHandlerProvider.js.flow +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -10
- package/handlers/connection/MutationHandlers.js.flow +31 -7
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +8 -8
- package/lib/handlers/connection/MutationHandlers.js +61 -5
- package/lib/index.js +58 -43
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +152 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +419 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +4 -1
- package/lib/mutations/RelayRecordProxy.js +3 -2
- package/lib/mutations/RelayRecordSourceMutator.js +3 -2
- package/lib/mutations/RelayRecordSourceProxy.js +12 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -5
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +14 -10
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +12 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -4
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +141 -60
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +532 -195
- package/lib/store/RelayConcreteVariables.js +24 -4
- package/lib/store/RelayModernEnvironment.js +175 -234
- package/lib/store/RelayModernFragmentSpecResolver.js +52 -26
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +47 -12
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +58 -29
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +287 -46
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +55 -31
- package/lib/store/RelayResponseNormalizer.js +250 -108
- package/lib/store/RelayStoreReactFlightUtils.js +8 -12
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +11 -5
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +61 -0
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +35 -9
- package/lib/util/RelayConcreteNode.js +4 -0
- package/lib/util/RelayFeatureFlags.js +11 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +225 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +506 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +261 -0
- package/multi-actor-environment/index.js.flow +26 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +32 -26
- package/mutations/RelayRecordProxy.js.flow +4 -5
- package/mutations/RelayRecordSourceMutator.js.flow +4 -6
- package/mutations/RelayRecordSourceProxy.js.flow +19 -10
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +22 -7
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -46
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +28 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -20
- package/network/wrapNetworkWithLogObserver.js.flow +100 -0
- package/package.json +3 -2
- package/query/GraphQLTag.js.flow +9 -9
- package/query/PreloadableQueryRegistry.js.flow +2 -1
- package/query/fetchQuery.js.flow +11 -13
- package/query/fetchQueryInternal.js.flow +6 -9
- package/query/fetchQuery_DEPRECATED.js.flow +6 -6
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +14 -3
- package/store/DataChecker.js.flow +162 -67
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +616 -283
- package/store/RelayConcreteVariables.js.flow +27 -5
- package/store/RelayModernEnvironment.js.flow +176 -235
- package/store/RelayModernFragmentSpecResolver.js.flow +55 -31
- package/store/RelayModernOperationDescriptor.js.flow +12 -7
- package/store/RelayModernRecord.js.flow +67 -11
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +72 -36
- package/store/RelayOperationTracker.js.flow +59 -43
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +79 -34
- package/store/RelayReader.js.flow +351 -72
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +60 -33
- package/store/RelayResponseNormalizer.js.flow +288 -102
- package/store/RelayStoreReactFlightUtils.js.flow +9 -13
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +210 -44
- package/store/RelayStoreUtils.js.flow +25 -11
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +121 -0
- package/store/StoreInspector.js.flow +2 -2
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +2 -2
- package/store/cloneRelayHandleSourceField.js.flow +5 -6
- package/store/cloneRelayScalarHandleSourceField.js.flow +5 -6
- package/store/createFragmentSpecResolver.js.flow +3 -4
- package/store/createRelayContext.js.flow +3 -3
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +54 -27
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +4 -0
- package/util/RelayFeatureFlags.js.flow +24 -8
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +73 -4
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/deepFreeze.js.flow +2 -1
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +72 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +79 -0
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/resolveImmediate.js.flow +1 -1
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -12,23 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
19
|
-
const validateMutation = require('./validateMutation');
|
|
20
|
-
const warning = require('warning');
|
|
21
|
-
|
|
22
|
-
const {getRequest} = require('../query/GraphQLTag');
|
|
23
|
-
const {generateUniqueClientID} = require('../store/ClientID');
|
|
24
|
-
const {
|
|
25
|
-
createOperationDescriptor,
|
|
26
|
-
} = require('../store/RelayModernOperationDescriptor');
|
|
27
|
-
|
|
28
15
|
import type {PayloadError, UploadableMap} from '../network/RelayNetworkTypes';
|
|
29
16
|
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
30
17
|
import type {
|
|
31
18
|
IEnvironment,
|
|
19
|
+
MutationParameters,
|
|
32
20
|
SelectorStoreUpdater,
|
|
33
21
|
} from '../store/RelayStoreTypes';
|
|
34
22
|
import type {
|
|
@@ -38,57 +26,63 @@ import type {
|
|
|
38
26
|
} from '../util/RelayRuntimeTypes';
|
|
39
27
|
import type {DeclarativeMutationConfig} from './RelayDeclarativeMutationConfig';
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
30
|
+
const {generateUniqueClientID} = require('../store/ClientID');
|
|
31
|
+
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
32
|
+
const {
|
|
33
|
+
createOperationDescriptor,
|
|
34
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
35
|
+
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
36
|
+
const validateMutation = require('./validateMutation');
|
|
37
|
+
const invariant = require('invariant');
|
|
38
|
+
const warning = require('warning');
|
|
39
|
+
|
|
40
|
+
export type DEPRECATED_MutationConfig<TMutationResponse> = {|
|
|
42
41
|
configs?: Array<DeclarativeMutationConfig>,
|
|
43
42
|
cacheConfig?: CacheConfig,
|
|
44
43
|
mutation: GraphQLTaggedNode,
|
|
45
44
|
variables: Variables,
|
|
46
45
|
uploadables?: UploadableMap,
|
|
47
|
-
onCompleted?: ?(
|
|
46
|
+
onCompleted?: ?(
|
|
47
|
+
response: TMutationResponse,
|
|
48
|
+
errors: ?Array<PayloadError>,
|
|
49
|
+
) => void,
|
|
48
50
|
onError?: ?(error: Error) => void,
|
|
49
51
|
onUnsubscribe?: ?() => void,
|
|
50
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
52
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
51
53
|
optimisticResponse?: Object,
|
|
52
|
-
updater?: ?SelectorStoreUpdater
|
|
54
|
+
updater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
53
55
|
|};
|
|
54
56
|
|
|
55
|
-
export type MutationParameters = {|
|
|
56
|
-
+response: {...},
|
|
57
|
-
+variables: {...},
|
|
58
|
-
+rawResponse?: {...},
|
|
59
|
-
|};
|
|
60
|
-
|
|
61
|
-
export type MutationConfig<T: MutationParameters> = {|
|
|
57
|
+
export type MutationConfig<TMutation: MutationParameters> = {|
|
|
62
58
|
configs?: Array<DeclarativeMutationConfig>,
|
|
63
59
|
cacheConfig?: CacheConfig,
|
|
64
60
|
mutation: GraphQLTaggedNode,
|
|
65
61
|
onError?: ?(error: Error) => void,
|
|
66
62
|
onCompleted?: ?(
|
|
67
|
-
response:
|
|
63
|
+
response: TMutation['response'],
|
|
68
64
|
errors: ?Array<PayloadError>,
|
|
69
65
|
) => void,
|
|
66
|
+
onNext?: ?() => void,
|
|
70
67
|
onUnsubscribe?: ?() => void,
|
|
71
|
-
optimisticResponse?:
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
>,
|
|
79
|
-
optimisticUpdater?: ?SelectorStoreUpdater,
|
|
80
|
-
updater?: ?SelectorStoreUpdater,
|
|
68
|
+
optimisticResponse?: {
|
|
69
|
+
+rawResponse?: {...},
|
|
70
|
+
...TMutation,
|
|
71
|
+
...
|
|
72
|
+
}['rawResponse'],
|
|
73
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
74
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
81
75
|
uploadables?: UploadableMap,
|
|
82
|
-
variables:
|
|
76
|
+
variables: TMutation['variables'],
|
|
83
77
|
|};
|
|
84
78
|
|
|
85
79
|
/**
|
|
86
80
|
* Higher-level helper function to execute a mutation against a specific
|
|
87
81
|
* environment.
|
|
88
82
|
*/
|
|
89
|
-
function commitMutation<
|
|
83
|
+
function commitMutation<TMutation: MutationParameters>(
|
|
90
84
|
environment: IEnvironment,
|
|
91
|
-
config: MutationConfig<
|
|
85
|
+
config: MutationConfig<TMutation>,
|
|
92
86
|
): Disposable {
|
|
93
87
|
invariant(
|
|
94
88
|
isRelayModernEnvironment(environment),
|
|
@@ -103,14 +97,8 @@ function commitMutation<T: MutationParameters>(
|
|
|
103
97
|
throw new Error('commitMutation: Expected mutation to be of type request');
|
|
104
98
|
}
|
|
105
99
|
let {optimisticResponse, optimisticUpdater, updater} = config;
|
|
106
|
-
const {
|
|
107
|
-
|
|
108
|
-
cacheConfig,
|
|
109
|
-
onError,
|
|
110
|
-
onUnsubscribe,
|
|
111
|
-
variables,
|
|
112
|
-
uploadables,
|
|
113
|
-
} = config;
|
|
100
|
+
const {configs, cacheConfig, onError, onUnsubscribe, variables, uploadables} =
|
|
101
|
+
config;
|
|
114
102
|
const operation = createOperationDescriptor(
|
|
115
103
|
mutation,
|
|
116
104
|
variables,
|
|
@@ -161,6 +149,7 @@ function commitMutation<T: MutationParameters>(
|
|
|
161
149
|
errors.push(...payload.errors);
|
|
162
150
|
}
|
|
163
151
|
}
|
|
152
|
+
config.onNext?.();
|
|
164
153
|
},
|
|
165
154
|
complete: () => {
|
|
166
155
|
const {onCompleted} = config;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @emails oncall+relay
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// flowlint ambiguous-object-type:error
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
17
|
+
import type {RecordProxy, RecordSourceProxy} from '../store/RelayStoreTypes';
|
|
18
|
+
import type {ReaderLinkedField, ReaderSelection} from '../util/ReaderNode';
|
|
19
|
+
import type {OperationType} from '../util/RelayRuntimeTypes';
|
|
20
|
+
|
|
21
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
22
|
+
const {getArgumentValues} = require('../store/RelayStoreUtils');
|
|
23
|
+
|
|
24
|
+
const nonUpdatableKeys = ['id', '__id', '__typename'];
|
|
25
|
+
|
|
26
|
+
function readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
27
|
+
query: GraphQLTaggedNode,
|
|
28
|
+
variables: TQuery['variables'],
|
|
29
|
+
proxy: RecordSourceProxy,
|
|
30
|
+
): TQuery['response'] {
|
|
31
|
+
// TODO assert that the concrete request is an updatable query
|
|
32
|
+
const request = getRequest(query);
|
|
33
|
+
|
|
34
|
+
const updatableProxy = {};
|
|
35
|
+
updateProxyFromSelections(
|
|
36
|
+
updatableProxy,
|
|
37
|
+
proxy.getRoot(),
|
|
38
|
+
variables,
|
|
39
|
+
request.fragment.selections,
|
|
40
|
+
proxy,
|
|
41
|
+
);
|
|
42
|
+
if (__DEV__) {
|
|
43
|
+
Object.freeze(updatableProxy);
|
|
44
|
+
}
|
|
45
|
+
return updatableProxy;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function updateProxyFromSelections<TQuery: OperationType>(
|
|
49
|
+
mutableUpdatableProxy: TQuery['response'],
|
|
50
|
+
recordProxy: RecordProxy,
|
|
51
|
+
queryVariables: TQuery['variables'],
|
|
52
|
+
selections: $ReadOnlyArray<ReaderSelection>,
|
|
53
|
+
root: RecordSourceProxy,
|
|
54
|
+
) {
|
|
55
|
+
for (const selection of selections) {
|
|
56
|
+
switch (selection.kind) {
|
|
57
|
+
case 'LinkedField':
|
|
58
|
+
// Linked fields are assignable if they contain fragment spreads or
|
|
59
|
+
// read-only otherwise.
|
|
60
|
+
const isAssignable = selection.selections.some(
|
|
61
|
+
item => item.kind === 'FragmentSpread',
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const set = !isAssignable
|
|
65
|
+
? undefined
|
|
66
|
+
: selection.plural
|
|
67
|
+
? createSetterForPluralLinkedField(
|
|
68
|
+
selection,
|
|
69
|
+
queryVariables,
|
|
70
|
+
recordProxy,
|
|
71
|
+
root,
|
|
72
|
+
)
|
|
73
|
+
: createSetterForSingularLinkedField(
|
|
74
|
+
selection,
|
|
75
|
+
queryVariables,
|
|
76
|
+
recordProxy,
|
|
77
|
+
root,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const get = selection.plural
|
|
81
|
+
? createGetterForPluralLinkedField(
|
|
82
|
+
selection,
|
|
83
|
+
queryVariables,
|
|
84
|
+
recordProxy,
|
|
85
|
+
root,
|
|
86
|
+
)
|
|
87
|
+
: createGetterForSingularLinkedField(
|
|
88
|
+
selection,
|
|
89
|
+
queryVariables,
|
|
90
|
+
recordProxy,
|
|
91
|
+
root,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
Object.defineProperty(
|
|
95
|
+
mutableUpdatableProxy,
|
|
96
|
+
selection.alias ?? selection.name,
|
|
97
|
+
{
|
|
98
|
+
get,
|
|
99
|
+
set,
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
break;
|
|
103
|
+
case 'ScalarField':
|
|
104
|
+
const scalarFieldName = selection.alias ?? selection.name;
|
|
105
|
+
Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
|
|
106
|
+
get: function () {
|
|
107
|
+
const variables = getArgumentValues(
|
|
108
|
+
selection.args ?? [],
|
|
109
|
+
queryVariables,
|
|
110
|
+
);
|
|
111
|
+
// Flow incorrect assumes that the return value for the get method must match
|
|
112
|
+
// the set parameter.
|
|
113
|
+
return (recordProxy.getValue(
|
|
114
|
+
selection.name,
|
|
115
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
116
|
+
(variables: any),
|
|
117
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
118
|
+
): any);
|
|
119
|
+
},
|
|
120
|
+
set: nonUpdatableKeys.includes(selection.name)
|
|
121
|
+
? undefined
|
|
122
|
+
: // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
123
|
+
function (newValue: ?any) {
|
|
124
|
+
const variables = getArgumentValues(
|
|
125
|
+
selection.args ?? [],
|
|
126
|
+
queryVariables,
|
|
127
|
+
);
|
|
128
|
+
recordProxy.setValue(
|
|
129
|
+
newValue,
|
|
130
|
+
selection.name,
|
|
131
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
132
|
+
(variables: any),
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
break;
|
|
137
|
+
case 'InlineFragment':
|
|
138
|
+
if (recordProxy.getType() === selection.type) {
|
|
139
|
+
updateProxyFromSelections(
|
|
140
|
+
mutableUpdatableProxy,
|
|
141
|
+
recordProxy,
|
|
142
|
+
queryVariables,
|
|
143
|
+
selection.selections,
|
|
144
|
+
root,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case 'FragmentSpread':
|
|
149
|
+
// Explicitly ignore
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
throw new Error(
|
|
153
|
+
'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function createSetterForPluralLinkedField<TQuery: OperationType>(
|
|
160
|
+
selection: ReaderLinkedField,
|
|
161
|
+
queryVariables: TQuery['variables'],
|
|
162
|
+
recordProxy: RecordProxy,
|
|
163
|
+
root: RecordSourceProxy,
|
|
164
|
+
) {
|
|
165
|
+
return function set(newValue: ?$ReadOnlyArray<{__id: string, ...}>) {
|
|
166
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
167
|
+
if (newValue == null) {
|
|
168
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
169
|
+
recordProxy.setValue(null, selection.name, (variables: any));
|
|
170
|
+
} else {
|
|
171
|
+
const recordProxies = newValue.map(item => {
|
|
172
|
+
if (item == null) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
'When assigning an array of items, none of the items should be null or undefined.',
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const {__id} = item;
|
|
178
|
+
if (__id == null) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
'The __id field must be present on each item passed to the setter. This indicates a bug in Relay.',
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
const newValueRecord = root.get(__id);
|
|
184
|
+
if (newValueRecord == null) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Did not find item with data id ${__id} in the store.`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return newValueRecord;
|
|
190
|
+
});
|
|
191
|
+
recordProxy.setLinkedRecords(
|
|
192
|
+
recordProxies,
|
|
193
|
+
selection.name,
|
|
194
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
195
|
+
(variables: any),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function createSetterForSingularLinkedField<TQuery: OperationType>(
|
|
201
|
+
selection: ReaderLinkedField,
|
|
202
|
+
queryVariables: TQuery['variables'],
|
|
203
|
+
recordProxy: RecordProxy,
|
|
204
|
+
root: RecordSourceProxy,
|
|
205
|
+
) {
|
|
206
|
+
return function set(newValue: ?{__id: string, ...}) {
|
|
207
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
208
|
+
if (newValue == null) {
|
|
209
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
210
|
+
recordProxy.setValue(null, selection.name, (variables: any));
|
|
211
|
+
} else {
|
|
212
|
+
const {__id} = newValue;
|
|
213
|
+
if (__id == null) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
'The __id field must be present on the argument. This indicates a bug in Relay.',
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const newValueRecord = root.get(__id);
|
|
219
|
+
if (newValueRecord == null) {
|
|
220
|
+
throw new Error(`Did not find item with data id ${__id} in the store.`);
|
|
221
|
+
}
|
|
222
|
+
recordProxy.setLinkedRecord(
|
|
223
|
+
newValueRecord,
|
|
224
|
+
selection.name,
|
|
225
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
226
|
+
(variables: any),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function createGetterForPluralLinkedField<TQuery: OperationType>(
|
|
233
|
+
selection: ReaderLinkedField,
|
|
234
|
+
queryVariables: TQuery['variables'],
|
|
235
|
+
recordProxy: RecordProxy,
|
|
236
|
+
root: RecordSourceProxy,
|
|
237
|
+
) {
|
|
238
|
+
return function () {
|
|
239
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
240
|
+
const linkedRecords = recordProxy.getLinkedRecords(
|
|
241
|
+
selection.name,
|
|
242
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
243
|
+
(variables: any),
|
|
244
|
+
);
|
|
245
|
+
if (linkedRecords != null) {
|
|
246
|
+
return (linkedRecords.map(linkedRecord => {
|
|
247
|
+
if (linkedRecord != null) {
|
|
248
|
+
const updatableProxy = {};
|
|
249
|
+
updateProxyFromSelections(
|
|
250
|
+
updatableProxy,
|
|
251
|
+
linkedRecord,
|
|
252
|
+
queryVariables,
|
|
253
|
+
selection.selections,
|
|
254
|
+
root,
|
|
255
|
+
);
|
|
256
|
+
if (__DEV__) {
|
|
257
|
+
Object.freeze(updatableProxy);
|
|
258
|
+
}
|
|
259
|
+
// Flow incorrect assumes that the return value for the get method must match
|
|
260
|
+
// the set parameter.
|
|
261
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
262
|
+
return (updatableProxy: any);
|
|
263
|
+
} else {
|
|
264
|
+
return linkedRecord;
|
|
265
|
+
}
|
|
266
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
267
|
+
}): any);
|
|
268
|
+
} else {
|
|
269
|
+
return linkedRecords;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function createGetterForSingularLinkedField<TQuery: OperationType>(
|
|
275
|
+
selection: ReaderLinkedField,
|
|
276
|
+
queryVariables: TQuery['variables'],
|
|
277
|
+
recordProxy: RecordProxy,
|
|
278
|
+
root: RecordSourceProxy,
|
|
279
|
+
) {
|
|
280
|
+
return function () {
|
|
281
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
282
|
+
const linkedRecord = recordProxy.getLinkedRecord(
|
|
283
|
+
selection.name,
|
|
284
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
285
|
+
(variables: any),
|
|
286
|
+
);
|
|
287
|
+
if (linkedRecord != null) {
|
|
288
|
+
const updatableProxy = {};
|
|
289
|
+
updateProxyFromSelections(
|
|
290
|
+
updatableProxy,
|
|
291
|
+
linkedRecord,
|
|
292
|
+
queryVariables,
|
|
293
|
+
selection.selections,
|
|
294
|
+
root,
|
|
295
|
+
);
|
|
296
|
+
if (__DEV__) {
|
|
297
|
+
Object.freeze(updatableProxy);
|
|
298
|
+
}
|
|
299
|
+
// Flow incorrect assumes that the return value for the get method must match
|
|
300
|
+
// the set parameter.
|
|
301
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
302
|
+
return (updatableProxy: any);
|
|
303
|
+
} else {
|
|
304
|
+
return linkedRecord;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
module.exports = {readUpdatableQuery_EXPERIMENTAL};
|
|
@@ -13,28 +13,17 @@
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
|
-
NormalizationSelection,
|
|
17
16
|
NormalizationField,
|
|
17
|
+
NormalizationSelection,
|
|
18
18
|
} from '../util/NormalizationNode';
|
|
19
19
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
20
20
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
21
21
|
|
|
22
|
-
type ValidationContext = {|
|
|
23
|
-
visitedPaths: Set<string>,
|
|
24
|
-
path: string,
|
|
25
|
-
variables: Variables,
|
|
26
|
-
missingDiff: Object,
|
|
27
|
-
extraDiff: Object,
|
|
28
|
-
moduleImportPaths: Set<string>,
|
|
29
|
-
|};
|
|
30
|
-
|
|
31
|
-
const warning = require('warning');
|
|
32
|
-
|
|
33
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
34
|
-
|
|
35
22
|
const {
|
|
36
|
-
|
|
23
|
+
ACTOR_CHANGE,
|
|
24
|
+
CLIENT_COMPONENT,
|
|
37
25
|
CLIENT_EXTENSION,
|
|
26
|
+
CONDITION,
|
|
38
27
|
DEFER,
|
|
39
28
|
FLIGHT_FIELD,
|
|
40
29
|
FRAGMENT_SPREAD,
|
|
@@ -47,10 +36,26 @@ const {
|
|
|
47
36
|
STREAM,
|
|
48
37
|
TYPE_DISCRIMINATOR,
|
|
49
38
|
} = require('../util/RelayConcreteNode');
|
|
39
|
+
const warning = require('warning');
|
|
40
|
+
|
|
41
|
+
type ValidationContext = {|
|
|
42
|
+
visitedPaths: Set<string>,
|
|
43
|
+
path: string,
|
|
44
|
+
variables: Variables,
|
|
45
|
+
missingDiff: Object,
|
|
46
|
+
extraDiff: Object,
|
|
47
|
+
moduleImportPaths: Set<string>,
|
|
48
|
+
|};
|
|
49
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
50
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
50
51
|
|
|
51
52
|
let validateMutation = () => {};
|
|
52
53
|
if (__DEV__) {
|
|
53
|
-
const addFieldToDiff = (
|
|
54
|
+
const addFieldToDiff = (
|
|
55
|
+
path: string,
|
|
56
|
+
diff: Object,
|
|
57
|
+
isScalar: void | boolean,
|
|
58
|
+
) => {
|
|
54
59
|
let deepLoc = diff;
|
|
55
60
|
path.split('.').forEach((key, index, arr) => {
|
|
56
61
|
if (deepLoc[key] == null) {
|
|
@@ -115,6 +120,7 @@ if (__DEV__) {
|
|
|
115
120
|
case CONDITION:
|
|
116
121
|
validateSelections(optimisticResponse, selection.selections, context);
|
|
117
122
|
return;
|
|
123
|
+
case CLIENT_COMPONENT:
|
|
118
124
|
case FRAGMENT_SPREAD:
|
|
119
125
|
validateSelections(
|
|
120
126
|
optimisticResponse,
|
|
@@ -126,6 +132,12 @@ if (__DEV__) {
|
|
|
126
132
|
case LINKED_FIELD:
|
|
127
133
|
case FLIGHT_FIELD:
|
|
128
134
|
return validateField(optimisticResponse, selection, context);
|
|
135
|
+
case ACTOR_CHANGE:
|
|
136
|
+
return validateField(
|
|
137
|
+
optimisticResponse,
|
|
138
|
+
selection.linkedField,
|
|
139
|
+
context,
|
|
140
|
+
);
|
|
129
141
|
case INLINE_FRAGMENT:
|
|
130
142
|
const type = selection.type;
|
|
131
143
|
const isConcreteType = selection.abstractKey == null;
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayObservable = require('./RelayObservable');
|
|
16
|
-
|
|
17
15
|
import type {ExecuteFunction, FetchFunction} from './RelayNetworkTypes';
|
|
18
16
|
|
|
17
|
+
const RelayObservable = require('./RelayObservable');
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
20
|
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
21
21
|
*/
|
|
@@ -12,22 +12,21 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
|
|
17
|
-
const {convertFetch} = require('./ConvertToExecuteFunction');
|
|
18
|
-
|
|
19
15
|
import type {RequestParameters} from '../util/RelayConcreteNode';
|
|
20
16
|
import type {CacheConfig, Variables} from '../util/RelayRuntimeTypes';
|
|
21
17
|
import type {
|
|
22
18
|
FetchFunction,
|
|
23
19
|
GraphQLResponse,
|
|
24
|
-
LogRequestInfoFunction,
|
|
25
20
|
INetwork,
|
|
21
|
+
LogRequestInfoFunction,
|
|
26
22
|
SubscribeFunction,
|
|
27
23
|
UploadableMap,
|
|
28
24
|
} from './RelayNetworkTypes';
|
|
29
25
|
import type RelayObservable from './RelayObservable';
|
|
30
26
|
|
|
27
|
+
const {convertFetch} = require('./ConvertToExecuteFunction');
|
|
28
|
+
const invariant = require('invariant');
|
|
29
|
+
|
|
31
30
|
/**
|
|
32
31
|
* Creates an implementation of the `Network` interface defined in
|
|
33
32
|
* `RelayNetworkTypes` given `fetch` and `subscribe` functions.
|
|
@@ -20,14 +20,15 @@ import type RelayObservable, {ObservableFromValue} from './RelayObservable';
|
|
|
20
20
|
* An interface for fetching the data for one or more (possibly interdependent)
|
|
21
21
|
* queries.
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
24
|
-
execute: ExecuteFunction
|
|
25
|
-
|
|
23
|
+
export interface INetwork {
|
|
24
|
+
+execute: ExecuteFunction;
|
|
25
|
+
}
|
|
26
|
+
|
|
26
27
|
export type LogRequestInfoFunction = mixed => void;
|
|
27
28
|
|
|
28
|
-
export type PayloadData = {[key: string]: mixed
|
|
29
|
+
export type PayloadData = interface {[key: string]: mixed};
|
|
29
30
|
|
|
30
|
-
export type PayloadError = {
|
|
31
|
+
export type PayloadError = interface {
|
|
31
32
|
message: string,
|
|
32
33
|
locations?: Array<{
|
|
33
34
|
line: number,
|
|
@@ -36,14 +37,13 @@ export type PayloadError = {
|
|
|
36
37
|
}>,
|
|
37
38
|
// Not officially part of the spec, but used at Facebook
|
|
38
39
|
severity?: 'CRITICAL' | 'ERROR' | 'WARNING',
|
|
39
|
-
...
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type PayloadExtensions = {[key: string]: mixed, ...};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* The shape of a GraphQL response as dictated by the
|
|
46
|
-
* [spec](https://graphql.
|
|
46
|
+
* [spec](https://spec.graphql.org/June2018/#sec-Response-Format).
|
|
47
47
|
*/
|
|
48
48
|
export type GraphQLResponseWithData = {|
|
|
49
49
|
+data: PayloadData,
|
|
@@ -120,7 +120,7 @@ export type SubscribeFunction = (
|
|
|
120
120
|
) => RelayObservable<GraphQLResponse>;
|
|
121
121
|
|
|
122
122
|
export type Uploadable = File | Blob;
|
|
123
|
-
export type UploadableMap = {[key: string]: Uploadable
|
|
123
|
+
export type UploadableMap = interface {[key: string]: Uploadable};
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* React Flight tree created on the server.
|
|
@@ -132,6 +132,13 @@ export type ReactFlightPayloadQuery = {|
|
|
|
132
132
|
+response: GraphQLSingularResponse,
|
|
133
133
|
+variables: Variables,
|
|
134
134
|
|};
|
|
135
|
+
export type ReactFlightPayloadFragment = {|
|
|
136
|
+
+__id: string,
|
|
137
|
+
+__typename: string,
|
|
138
|
+
+module: mixed,
|
|
139
|
+
+response: GraphQLSingularResponse,
|
|
140
|
+
+variables: Variables,
|
|
141
|
+
|};
|
|
135
142
|
export type ReactFlightServerError = {
|
|
136
143
|
+message: string,
|
|
137
144
|
+stack: string,
|
|
@@ -147,10 +154,12 @@ export type ReactFlightServerError = {
|
|
|
147
154
|
* - queries: an array of queries that the server preloaded for the client.
|
|
148
155
|
* - errors: an array of errors that were encountered while rendering the
|
|
149
156
|
* Server Component.
|
|
157
|
+
* - fragments: an array of fragments that the server preloaded for the client.
|
|
150
158
|
*/
|
|
151
159
|
export type ReactFlightPayloadData = {|
|
|
152
160
|
+status: string,
|
|
153
161
|
+tree: ?Array<ReactFlightServerTree>,
|
|
154
162
|
+queries: Array<ReactFlightPayloadQuery>,
|
|
155
163
|
+errors: Array<ReactFlightServerError>,
|
|
164
|
+
+fragments: Array<ReactFlightPayloadFragment>,
|
|
156
165
|
|};
|
|
@@ -223,7 +223,7 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
223
223
|
do(observer: Observer<T>): RelayObservable<T> {
|
|
224
224
|
return RelayObservable.create(sink => {
|
|
225
225
|
const both = (action: any) =>
|
|
226
|
-
function() {
|
|
226
|
+
function () {
|
|
227
227
|
try {
|
|
228
228
|
observer[action] && observer[action].apply(observer, arguments);
|
|
229
229
|
} catch (error) {
|