relay-runtime 12.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 -17
- package/handlers/connection/MutationHandlers.js.flow +7 -11
- package/index.js +1 -1
- package/index.js.flow +40 -33
- package/lib/handlers/connection/ConnectionHandler.js +12 -18
- package/lib/handlers/connection/MutationHandlers.js +3 -6
- package/lib/index.js +45 -45
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +8 -4
- package/lib/multi-actor-environment/MultiActorEnvironment.js +35 -22
- package/lib/multi-actor-environment/index.js +2 -2
- 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 +12 -4
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +15 -14
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +6 -6
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayObservable.js +1 -3
- package/lib/network/RelayQueryResponseCache.js +2 -2
- package/lib/network/wrapNetworkWithLogObserver.js +2 -1
- package/lib/query/GraphQLTag.js +2 -1
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +16 -17
- package/lib/store/OperationExecutor.js +13 -13
- package/lib/store/RelayConcreteVariables.js +6 -9
- package/lib/store/RelayModernEnvironment.js +66 -42
- package/lib/store/RelayModernFragmentSpecResolver.js +8 -8
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +12 -11
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +14 -15
- package/lib/store/RelayPublishQueue.js +11 -5
- package/lib/store/RelayReader.js +130 -37
- package/lib/store/RelayReferenceMarker.js +10 -11
- package/lib/store/RelayResponseNormalizer.js +25 -22
- package/lib/store/RelayStoreReactFlightUtils.js +3 -3
- package/lib/store/RelayStoreSubscriptions.js +6 -4
- package/lib/store/RelayStoreUtils.js +5 -5
- package/lib/store/ResolverCache.js +6 -6
- package/lib/store/ResolverFragments.js +9 -5
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +3 -1
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +5 -5
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +7 -1
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationVariables.js +2 -3
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +27 -19
- package/multi-actor-environment/ActorUtils.js.flow +2 -2
- package/multi-actor-environment/MultiActorEnvironment.js.flow +45 -24
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +27 -11
- package/multi-actor-environment/index.js.flow +1 -2
- 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 +15 -5
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -48
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +19 -17
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayObservable.js.flow +1 -3
- package/network/RelayQueryResponseCache.js.flow +3 -3
- package/network/wrapNetworkWithLogObserver.js.flow +8 -7
- package/package.json +1 -1
- 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 +9 -2
- package/store/DataChecker.js.flow +20 -29
- package/store/OperationExecutor.js.flow +54 -62
- package/store/RelayConcreteVariables.js.flow +4 -10
- package/store/RelayModernEnvironment.js.flow +56 -27
- package/store/RelayModernFragmentSpecResolver.js.flow +17 -19
- package/store/RelayModernOperationDescriptor.js.flow +10 -11
- package/store/RelayModernRecord.js.flow +19 -12
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +21 -24
- package/store/RelayOperationTracker.js.flow +11 -17
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +42 -23
- package/store/RelayReader.js.flow +180 -60
- package/store/RelayRecordSource.js.flow +2 -2
- package/store/RelayReferenceMarker.js.flow +12 -15
- package/store/RelayResponseNormalizer.js.flow +43 -41
- package/store/RelayStoreReactFlightUtils.js.flow +3 -4
- package/store/RelayStoreSubscriptions.js.flow +9 -8
- package/store/RelayStoreTypes.js.flow +72 -29
- package/store/RelayStoreUtils.js.flow +8 -9
- package/store/ResolverCache.js.flow +16 -14
- package/store/ResolverFragments.js.flow +15 -22
- 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 +2 -2
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +16 -24
- package/util/ReaderNode.js.flow +9 -0
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +14 -2
- package/util/RelayReplaySubject.js.flow +2 -3
- package/util/RelayRuntimeTypes.js.flow +69 -2
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +5 -7
- package/util/getPaginationVariables.js.flow +5 -9
- package/util/getPendingOperationsForFragment.js.flow +2 -2
- package/util/getRefetchMetadata.js.flow +6 -7
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/resolveImmediate.js.flow +1 -1
|
@@ -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: interface {},
|
|
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,18 +97,10 @@ 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
|
-
/* $FlowFixMe[class-object-subtyping] added when improving typing for this
|
|
117
|
-
* parameters */
|
|
118
104
|
variables,
|
|
119
105
|
cacheConfig,
|
|
120
106
|
generateUniqueClientID(),
|
|
@@ -163,6 +149,7 @@ function commitMutation<T: MutationParameters>(
|
|
|
163
149
|
errors.push(...payload.errors);
|
|
164
150
|
}
|
|
165
151
|
}
|
|
152
|
+
config.onNext?.();
|
|
166
153
|
},
|
|
167
154
|
complete: () => {
|
|
168
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,31 +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
|
-
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
34
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
35
|
-
|
|
36
22
|
const {
|
|
37
23
|
ACTOR_CHANGE,
|
|
38
|
-
CONDITION,
|
|
39
24
|
CLIENT_COMPONENT,
|
|
40
25
|
CLIENT_EXTENSION,
|
|
26
|
+
CONDITION,
|
|
41
27
|
DEFER,
|
|
42
28
|
FLIGHT_FIELD,
|
|
43
29
|
FRAGMENT_SPREAD,
|
|
@@ -50,10 +36,26 @@ const {
|
|
|
50
36
|
STREAM,
|
|
51
37
|
TYPE_DISCRIMINATOR,
|
|
52
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;
|
|
53
51
|
|
|
54
52
|
let validateMutation = () => {};
|
|
55
53
|
if (__DEV__) {
|
|
56
|
-
const addFieldToDiff = (
|
|
54
|
+
const addFieldToDiff = (
|
|
55
|
+
path: string,
|
|
56
|
+
diff: Object,
|
|
57
|
+
isScalar: void | boolean,
|
|
58
|
+
) => {
|
|
57
59
|
let deepLoc = diff;
|
|
58
60
|
path.split('.').forEach((key, index, arr) => {
|
|
59
61
|
if (deepLoc[key] == 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.
|
|
@@ -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) {
|
|
@@ -355,13 +355,11 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
// $FlowFixMe[incompatible-call]
|
|
359
358
|
this.subscribe({
|
|
360
359
|
start,
|
|
361
360
|
next(value) {
|
|
362
361
|
try {
|
|
363
362
|
if (!sink.closed) {
|
|
364
|
-
// $FlowFixMe[incompatible-call]
|
|
365
363
|
RelayObservable.from(fn(value)).subscribe({
|
|
366
364
|
start,
|
|
367
365
|
next: sink.next,
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
const stableCopy = require('../util/stableCopy');
|
|
17
|
-
|
|
18
15
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
19
16
|
import type {
|
|
20
17
|
GraphQLResponse,
|
|
21
18
|
GraphQLSingularResponse,
|
|
22
19
|
} from './RelayNetworkTypes';
|
|
23
20
|
|
|
21
|
+
const stableCopy = require('../util/stableCopy');
|
|
22
|
+
const invariant = require('invariant');
|
|
23
|
+
|
|
24
24
|
type Response = {
|
|
25
25
|
fetchTime: number,
|
|
26
26
|
payload: GraphQLResponse,
|
|
@@ -11,20 +11,21 @@
|
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
|
-
|
|
15
|
-
const generateID = require('../util/generateID');
|
|
14
|
+
import type {Subscription} from './RelayObservable';
|
|
16
15
|
|
|
17
16
|
import type ActorSpecificEnvironment from '../multi-actor-environment/ActorSpecificEnvironment';
|
|
18
17
|
import type RelayModernEnvironment from '../store/RelayModernEnvironment';
|
|
19
18
|
import type {RequestParameters} from '../util/RelayConcreteNode';
|
|
20
19
|
import type {CacheConfig, Variables} from '../util/RelayRuntimeTypes';
|
|
21
20
|
import type {
|
|
22
|
-
INetwork,
|
|
23
21
|
GraphQLResponse,
|
|
22
|
+
INetwork,
|
|
24
23
|
UploadableMap,
|
|
25
24
|
} from './RelayNetworkTypes';
|
|
26
25
|
import type RelayObservable from './RelayObservable';
|
|
27
26
|
|
|
27
|
+
const generateID = require('../util/generateID');
|
|
28
|
+
|
|
28
29
|
/**
|
|
29
30
|
* Wraps the network with logging to ensure that network requests are
|
|
30
31
|
* always logged. Relying on each network callsite to be wrapped is
|
|
@@ -46,7 +47,7 @@ function wrapNetworkWithLogObserver(
|
|
|
46
47
|
): RelayObservable<GraphQLResponse> {
|
|
47
48
|
const networkRequestId = generateID();
|
|
48
49
|
const logObserver = {
|
|
49
|
-
start: subscription => {
|
|
50
|
+
start: (subscription: Subscription) => {
|
|
50
51
|
env.__log({
|
|
51
52
|
name: 'network.start',
|
|
52
53
|
networkRequestId,
|
|
@@ -55,14 +56,14 @@ function wrapNetworkWithLogObserver(
|
|
|
55
56
|
cacheConfig,
|
|
56
57
|
});
|
|
57
58
|
},
|
|
58
|
-
next: response => {
|
|
59
|
+
next: (response: GraphQLResponse) => {
|
|
59
60
|
env.__log({
|
|
60
61
|
name: 'network.next',
|
|
61
62
|
networkRequestId,
|
|
62
63
|
response,
|
|
63
64
|
});
|
|
64
65
|
},
|
|
65
|
-
error: error => {
|
|
66
|
+
error: (error: Error) => {
|
|
66
67
|
env.__log({
|
|
67
68
|
name: 'network.error',
|
|
68
69
|
networkRequestId,
|
|
@@ -82,7 +83,7 @@ function wrapNetworkWithLogObserver(
|
|
|
82
83
|
});
|
|
83
84
|
},
|
|
84
85
|
};
|
|
85
|
-
const logRequestInfo = info => {
|
|
86
|
+
const logRequestInfo = (info: mixed) => {
|
|
86
87
|
env.__log({
|
|
87
88
|
name: 'network.info',
|
|
88
89
|
networkRequestId,
|