relay-runtime 12.0.0 → 13.0.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/LICENSE +1 -1
- package/README.md +67 -0
- package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
- package/handlers/connection/ConnectionHandler.js.flow +9 -18
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/handlers/connection/MutationHandlers.js.flow +8 -12
- package/index.js +2 -2
- package/index.js.flow +43 -34
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/ConnectionInterface.js +1 -1
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +49 -46
- package/lib/multi-actor-environment/ActorIdentifier.js +1 -1
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +9 -5
- package/lib/multi-actor-environment/ActorUtils.js +1 -1
- package/lib/multi-actor-environment/MultiActorEnvironment.js +36 -23
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
- package/lib/multi-actor-environment/index.js +3 -3
- package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
- package/lib/mutations/RelayRecordProxy.js +4 -3
- package/lib/mutations/RelayRecordSourceMutator.js +4 -3
- package/lib/mutations/RelayRecordSourceProxy.js +13 -5
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +13 -5
- package/lib/mutations/applyOptimisticMutation.js +7 -7
- package/lib/mutations/commitLocalUpdate.js +1 -1
- package/lib/mutations/commitMutation.js +16 -15
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
- package/lib/mutations/validateMutation.js +7 -7
- package/lib/network/ConvertToExecuteFunction.js +3 -2
- package/lib/network/RelayNetwork.js +4 -3
- package/lib/network/RelayNetworkTypes.js +1 -1
- package/lib/network/RelayObservable.js +2 -4
- package/lib/network/RelayQueryResponseCache.js +3 -3
- package/lib/network/wrapNetworkWithLogObserver.js +3 -2
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/PreloadableQueryRegistry.js +1 -1
- package/lib/query/fetchQuery.js +7 -6
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +3 -2
- package/lib/store/ClientID.js +8 -2
- package/lib/store/DataChecker.js +17 -18
- package/lib/store/OperationExecutor.js +14 -14
- package/lib/store/RelayConcreteVariables.js +7 -10
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +67 -43
- package/lib/store/RelayModernFragmentSpecResolver.js +9 -9
- package/lib/store/RelayModernOperationDescriptor.js +3 -2
- package/lib/store/RelayModernRecord.js +13 -12
- package/lib/store/RelayModernSelector.js +15 -9
- package/lib/store/RelayModernStore.js +15 -16
- package/lib/store/RelayOperationTracker.js +1 -1
- package/lib/store/RelayOptimisticRecordSource.js +1 -1
- package/lib/store/RelayPublishQueue.js +12 -6
- package/lib/store/RelayReader.js +131 -40
- package/lib/store/RelayRecordSource.js +1 -1
- package/lib/store/RelayRecordState.js +1 -1
- package/lib/store/RelayReferenceMarker.js +11 -12
- package/lib/store/RelayResponseNormalizer.js +26 -23
- package/lib/store/RelayStoreReactFlightUtils.js +4 -4
- package/lib/store/RelayStoreSubscriptions.js +7 -5
- package/lib/store/RelayStoreTypes.js +1 -1
- package/lib/store/RelayStoreUtils.js +6 -6
- package/lib/store/ResolverCache.js +7 -7
- package/lib/store/ResolverFragments.js +12 -8
- package/lib/store/StoreInspector.js +1 -1
- package/lib/store/TypeID.js +1 -1
- package/lib/store/ViewerPattern.js +1 -1
- package/lib/store/cloneRelayHandleSourceField.js +6 -5
- package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
- package/lib/store/createFragmentSpecResolver.js +1 -1
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/defaultGetDataID.js +1 -1
- package/lib/store/defaultRequiredFieldLogger.js +1 -1
- package/lib/store/hasOverlappingIDs.js +1 -1
- package/lib/store/isRelayModernEnvironment.js +1 -1
- package/lib/store/normalizeRelayPayload.js +1 -1
- package/lib/store/readInlineData.js +7 -3
- package/lib/subscription/requestSubscription.js +4 -6
- package/lib/util/JSResourceTypes.flow.js +1 -1
- package/lib/util/NormalizationNode.js +1 -1
- package/lib/util/ReaderNode.js +1 -1
- package/lib/util/RelayConcreteNode.js +2 -1
- package/lib/util/RelayDefaultHandleKey.js +1 -1
- package/lib/util/RelayError.js +1 -1
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +1 -1
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/RelayRuntimeTypes.js +1 -7
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/createPayloadFor3DField.js +1 -1
- package/lib/util/deepFreeze.js +1 -1
- package/lib/util/generateID.js +1 -1
- package/lib/util/getAllRootVariables.js +29 -0
- package/lib/util/getFragmentIdentifier.js +16 -8
- package/lib/util/getOperation.js +3 -2
- package/lib/util/getPaginationMetadata.js +1 -1
- package/lib/util/getPaginationVariables.js +3 -4
- package/lib/util/getPendingOperationsForFragment.js +1 -1
- package/lib/util/getRefetchMetadata.js +1 -1
- package/lib/util/getRelayHandleKey.js +3 -3
- package/lib/util/getRequestIdentifier.js +3 -3
- package/lib/util/getValueAtPath.js +1 -1
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/isPromise.js +1 -1
- package/lib/util/isScalarAndEqual.js +1 -1
- package/lib/util/recycleNodesInto.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +1 -1
- package/lib/util/reportMissingRequiredFields.js +1 -1
- package/lib/util/resolveImmediate.js +1 -1
- package/lib/util/stableCopy.js +1 -1
- package/lib/util/withDuration.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +1 -1
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +28 -20
- package/multi-actor-environment/ActorUtils.js.flow +3 -3
- package/multi-actor-environment/MultiActorEnvironment.js.flow +46 -25
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +28 -12
- package/multi-actor-environment/index.js.flow +2 -3
- package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -28
- package/mutations/RelayRecordProxy.js.flow +5 -6
- package/mutations/RelayRecordSourceMutator.js.flow +5 -7
- package/mutations/RelayRecordSourceProxy.js.flow +20 -11
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +16 -6
- package/mutations/applyOptimisticMutation.js.flow +14 -15
- package/mutations/commitLocalUpdate.js.flow +2 -2
- package/mutations/commitMutation.js.flow +36 -49
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
- package/mutations/validateMutation.js.flow +20 -18
- package/network/ConvertToExecuteFunction.js.flow +3 -3
- package/network/RelayNetwork.js.flow +5 -6
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/network/RelayObservable.js.flow +2 -4
- package/network/RelayQueryResponseCache.js.flow +4 -4
- package/network/wrapNetworkWithLogObserver.js.flow +9 -9
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +11 -11
- package/query/PreloadableQueryRegistry.js.flow +5 -3
- package/query/fetchQuery.js.flow +19 -19
- package/query/fetchQueryInternal.js.flow +7 -10
- package/query/fetchQuery_DEPRECATED.js.flow +7 -7
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +3 -3
- package/store/ClientID.js.flow +10 -3
- package/store/DataChecker.js.flow +21 -30
- package/store/OperationExecutor.js.flow +55 -63
- package/store/RelayConcreteVariables.js.flow +5 -11
- package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
- package/store/RelayModernEnvironment.js.flow +57 -28
- package/store/RelayModernFragmentSpecResolver.js.flow +18 -20
- package/store/RelayModernOperationDescriptor.js.flow +11 -12
- package/store/RelayModernRecord.js.flow +20 -13
- package/store/RelayModernSelector.js.flow +25 -15
- package/store/RelayModernStore.js.flow +22 -26
- package/store/RelayOperationTracker.js.flow +12 -18
- package/store/RelayOptimisticRecordSource.js.flow +3 -3
- package/store/RelayPublishQueue.js.flow +43 -24
- package/store/RelayReader.js.flow +181 -68
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +13 -16
- package/store/RelayResponseNormalizer.js.flow +44 -42
- package/store/RelayStoreReactFlightUtils.js.flow +4 -5
- package/store/RelayStoreSubscriptions.js.flow +10 -9
- package/store/RelayStoreTypes.js.flow +73 -30
- package/store/RelayStoreUtils.js.flow +9 -10
- package/store/ResolverCache.js.flow +17 -15
- package/store/ResolverFragments.js.flow +18 -25
- package/store/StoreInspector.js.flow +3 -3
- package/store/TypeID.js.flow +2 -2
- package/store/ViewerPattern.js.flow +3 -3
- package/store/cloneRelayHandleSourceField.js.flow +6 -7
- package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
- package/store/createFragmentSpecResolver.js.flow +4 -5
- package/store/createRelayContext.js.flow +3 -3
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/defaultRequiredFieldLogger.js.flow +1 -1
- package/store/hasOverlappingIDs.js.flow +1 -1
- package/store/isRelayModernEnvironment.js.flow +1 -1
- package/store/normalizeRelayPayload.js.flow +7 -8
- package/store/readInlineData.js.flow +8 -9
- package/subscription/requestSubscription.js.flow +16 -25
- package/util/JSResourceTypes.flow.js.flow +1 -1
- package/util/NormalizationNode.js.flow +1 -1
- package/util/ReaderNode.js.flow +10 -1
- package/util/RelayConcreteNode.js.flow +4 -1
- package/util/RelayDefaultHandleKey.js.flow +1 -1
- package/util/RelayError.js.flow +1 -1
- package/util/RelayFeatureFlags.js.flow +15 -5
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +3 -4
- package/util/RelayRuntimeTypes.js.flow +70 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +4 -4
- package/util/deepFreeze.js.flow +1 -1
- package/util/generateID.js.flow +1 -1
- package/util/getAllRootVariables.js.flow +36 -0
- package/util/getFragmentIdentifier.js.flow +28 -16
- package/util/getOperation.js.flow +3 -3
- package/util/getPaginationMetadata.js.flow +6 -11
- package/util/getPaginationVariables.js.flow +6 -10
- package/util/getPendingOperationsForFragment.js.flow +3 -3
- package/util/getRefetchMetadata.js.flow +8 -12
- package/util/getRelayHandleKey.js.flow +2 -3
- package/util/getRequestIdentifier.js.flow +4 -4
- package/util/getValueAtPath.js.flow +1 -1
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.js.flow +1 -1
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +1 -1
- package/util/registerEnvironmentWithDevTools.js.flow +1 -1
- package/util/reportMissingRequiredFields.js.flow +1 -1
- package/util/resolveImmediate.js.flow +2 -2
- package/util/stableCopy.js.flow +1 -1
- package/util/withDuration.js.flow +1 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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 'ClientExtension':
|
|
149
|
+
updateProxyFromSelections(
|
|
150
|
+
mutableUpdatableProxy,
|
|
151
|
+
recordProxy,
|
|
152
|
+
queryVariables,
|
|
153
|
+
selection.selections,
|
|
154
|
+
root,
|
|
155
|
+
);
|
|
156
|
+
break;
|
|
157
|
+
case 'FragmentSpread':
|
|
158
|
+
// Explicitly ignore
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
throw new Error(
|
|
162
|
+
'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function createSetterForPluralLinkedField<TQuery: OperationType>(
|
|
169
|
+
selection: ReaderLinkedField,
|
|
170
|
+
queryVariables: TQuery['variables'],
|
|
171
|
+
recordProxy: RecordProxy,
|
|
172
|
+
root: RecordSourceProxy,
|
|
173
|
+
) {
|
|
174
|
+
return function set(newValue: ?$ReadOnlyArray<{__id: string, ...}>) {
|
|
175
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
176
|
+
if (newValue == null) {
|
|
177
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
178
|
+
recordProxy.setValue(null, selection.name, (variables: any));
|
|
179
|
+
} else {
|
|
180
|
+
const recordProxies = newValue.map(item => {
|
|
181
|
+
if (item == null) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
'When assigning an array of items, none of the items should be null or undefined.',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const {__id} = item;
|
|
187
|
+
if (__id == null) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
'The __id field must be present on each item passed to the setter. This indicates a bug in Relay.',
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const newValueRecord = root.get(__id);
|
|
193
|
+
if (newValueRecord == null) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Did not find item with data id ${__id} in the store.`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return newValueRecord;
|
|
199
|
+
});
|
|
200
|
+
recordProxy.setLinkedRecords(
|
|
201
|
+
recordProxies,
|
|
202
|
+
selection.name,
|
|
203
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
204
|
+
(variables: any),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function createSetterForSingularLinkedField<TQuery: OperationType>(
|
|
210
|
+
selection: ReaderLinkedField,
|
|
211
|
+
queryVariables: TQuery['variables'],
|
|
212
|
+
recordProxy: RecordProxy,
|
|
213
|
+
root: RecordSourceProxy,
|
|
214
|
+
) {
|
|
215
|
+
return function set(newValue: ?{__id: string, ...}) {
|
|
216
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
217
|
+
if (newValue == null) {
|
|
218
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
219
|
+
recordProxy.setValue(null, selection.name, (variables: any));
|
|
220
|
+
} else {
|
|
221
|
+
const {__id} = newValue;
|
|
222
|
+
if (__id == null) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
'The __id field must be present on the argument. This indicates a bug in Relay.',
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
const newValueRecord = root.get(__id);
|
|
228
|
+
if (newValueRecord == null) {
|
|
229
|
+
throw new Error(`Did not find item with data id ${__id} in the store.`);
|
|
230
|
+
}
|
|
231
|
+
recordProxy.setLinkedRecord(
|
|
232
|
+
newValueRecord,
|
|
233
|
+
selection.name,
|
|
234
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
235
|
+
(variables: any),
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function createGetterForPluralLinkedField<TQuery: OperationType>(
|
|
242
|
+
selection: ReaderLinkedField,
|
|
243
|
+
queryVariables: TQuery['variables'],
|
|
244
|
+
recordProxy: RecordProxy,
|
|
245
|
+
root: RecordSourceProxy,
|
|
246
|
+
) {
|
|
247
|
+
return function () {
|
|
248
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
249
|
+
const linkedRecords = recordProxy.getLinkedRecords(
|
|
250
|
+
selection.name,
|
|
251
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
252
|
+
(variables: any),
|
|
253
|
+
);
|
|
254
|
+
if (linkedRecords != null) {
|
|
255
|
+
return (linkedRecords.map(linkedRecord => {
|
|
256
|
+
if (linkedRecord != null) {
|
|
257
|
+
const updatableProxy = {};
|
|
258
|
+
updateProxyFromSelections(
|
|
259
|
+
updatableProxy,
|
|
260
|
+
linkedRecord,
|
|
261
|
+
queryVariables,
|
|
262
|
+
selection.selections,
|
|
263
|
+
root,
|
|
264
|
+
);
|
|
265
|
+
if (__DEV__) {
|
|
266
|
+
Object.freeze(updatableProxy);
|
|
267
|
+
}
|
|
268
|
+
// Flow incorrect assumes that the return value for the get method must match
|
|
269
|
+
// the set parameter.
|
|
270
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
271
|
+
return (updatableProxy: any);
|
|
272
|
+
} else {
|
|
273
|
+
return linkedRecord;
|
|
274
|
+
}
|
|
275
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
276
|
+
}): any);
|
|
277
|
+
} else {
|
|
278
|
+
return linkedRecords;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function createGetterForSingularLinkedField<TQuery: OperationType>(
|
|
284
|
+
selection: ReaderLinkedField,
|
|
285
|
+
queryVariables: TQuery['variables'],
|
|
286
|
+
recordProxy: RecordProxy,
|
|
287
|
+
root: RecordSourceProxy,
|
|
288
|
+
) {
|
|
289
|
+
return function () {
|
|
290
|
+
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
291
|
+
const linkedRecord = recordProxy.getLinkedRecord(
|
|
292
|
+
selection.name,
|
|
293
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
294
|
+
(variables: any),
|
|
295
|
+
);
|
|
296
|
+
if (linkedRecord != null) {
|
|
297
|
+
const updatableProxy = {};
|
|
298
|
+
updateProxyFromSelections(
|
|
299
|
+
updatableProxy,
|
|
300
|
+
linkedRecord,
|
|
301
|
+
queryVariables,
|
|
302
|
+
selection.selections,
|
|
303
|
+
root,
|
|
304
|
+
);
|
|
305
|
+
if (__DEV__) {
|
|
306
|
+
Object.freeze(updatableProxy);
|
|
307
|
+
}
|
|
308
|
+
// Flow incorrect assumes that the return value for the get method must match
|
|
309
|
+
// the set parameter.
|
|
310
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
311
|
+
return (updatableProxy: any);
|
|
312
|
+
} else {
|
|
313
|
+
return linkedRecord;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
module.exports = {readUpdatableQuery_EXPERIMENTAL};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -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) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -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
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -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.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
|
-
|
|
15
|
-
const generateID = require('../util/generateID');
|
|
16
|
-
|
|
17
14
|
import type ActorSpecificEnvironment from '../multi-actor-environment/ActorSpecificEnvironment';
|
|
18
15
|
import type RelayModernEnvironment from '../store/RelayModernEnvironment';
|
|
19
16
|
import type {RequestParameters} from '../util/RelayConcreteNode';
|
|
20
17
|
import type {CacheConfig, Variables} from '../util/RelayRuntimeTypes';
|
|
21
18
|
import type {
|
|
22
|
-
INetwork,
|
|
23
19
|
GraphQLResponse,
|
|
20
|
+
INetwork,
|
|
24
21
|
UploadableMap,
|
|
25
22
|
} from './RelayNetworkTypes';
|
|
26
23
|
import type RelayObservable from './RelayObservable';
|
|
24
|
+
import type {Subscription} from './RelayObservable';
|
|
25
|
+
|
|
26
|
+
const generateID = require('../util/generateID');
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Wraps the network with logging to ensure that network requests are
|
|
@@ -46,7 +46,7 @@ function wrapNetworkWithLogObserver(
|
|
|
46
46
|
): RelayObservable<GraphQLResponse> {
|
|
47
47
|
const networkRequestId = generateID();
|
|
48
48
|
const logObserver = {
|
|
49
|
-
start: subscription => {
|
|
49
|
+
start: (subscription: Subscription) => {
|
|
50
50
|
env.__log({
|
|
51
51
|
name: 'network.start',
|
|
52
52
|
networkRequestId,
|
|
@@ -55,14 +55,14 @@ function wrapNetworkWithLogObserver(
|
|
|
55
55
|
cacheConfig,
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
|
-
next: response => {
|
|
58
|
+
next: (response: GraphQLResponse) => {
|
|
59
59
|
env.__log({
|
|
60
60
|
name: 'network.next',
|
|
61
61
|
networkRequestId,
|
|
62
62
|
response,
|
|
63
63
|
});
|
|
64
64
|
},
|
|
65
|
-
error: error => {
|
|
65
|
+
error: (error: Error) => {
|
|
66
66
|
env.__log({
|
|
67
67
|
name: 'network.error',
|
|
68
68
|
networkRequestId,
|
|
@@ -82,7 +82,7 @@ function wrapNetworkWithLogObserver(
|
|
|
82
82
|
});
|
|
83
83
|
},
|
|
84
84
|
};
|
|
85
|
-
const logRequestInfo = info => {
|
|
85
|
+
const logRequestInfo = (info: mixed) => {
|
|
86
86
|
env.__log({
|
|
87
87
|
name: 'network.info',
|
|
88
88
|
networkRequestId,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-runtime",
|
|
3
3
|
"description": "A core runtime for building GraphQL-driven applications.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "13.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"repository": "facebook/relay",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@babel/runtime": "^7.0.0",
|
|
15
|
-
"fbjs": "^3.0.
|
|
15
|
+
"fbjs": "^3.0.2",
|
|
16
16
|
"invariant": "^2.2.4"
|
|
17
17
|
},
|
|
18
18
|
"directories": {
|
package/query/GraphQLTag.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
const warning = require('warning');
|
|
19
|
-
|
|
20
15
|
import type {
|
|
21
16
|
ReaderFragment,
|
|
22
|
-
ReaderRefetchableFragment,
|
|
23
|
-
ReaderPaginationFragment,
|
|
24
17
|
ReaderInlineDataFragment,
|
|
18
|
+
ReaderPaginationFragment,
|
|
19
|
+
ReaderRefetchableFragment,
|
|
25
20
|
} from '../util/ReaderNode';
|
|
26
21
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
27
22
|
|
|
23
|
+
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
24
|
+
const invariant = require('invariant');
|
|
25
|
+
const warning = require('warning');
|
|
26
|
+
|
|
28
27
|
// The type of a graphql`...` tagged template expression.
|
|
29
28
|
export type GraphQLTaggedNode =
|
|
30
29
|
| ReaderFragment
|
|
30
|
+
| ReaderInlineDataFragment
|
|
31
31
|
| ConcreteRequest
|
|
32
32
|
| {
|
|
33
33
|
// This is this case when we `require()` a generated ES6 module
|
|
34
|
-
default: ReaderFragment | ConcreteRequest,
|
|
34
|
+
default: ReaderFragment | ReaderInlineDataFragment | ConcreteRequest,
|
|
35
35
|
...
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -39,7 +39,7 @@ export type GraphQLTaggedNode =
|
|
|
39
39
|
* Runtime function to correspond to the `graphql` tagged template function.
|
|
40
40
|
* All calls to this function should be transformed by the plugin.
|
|
41
41
|
*/
|
|
42
|
-
function graphql(strings: Array<string>):
|
|
42
|
+
function graphql(strings: Array<string>): any {
|
|
43
43
|
invariant(
|
|
44
44
|
false,
|
|
45
45
|
'graphql: Unexpected invocation at runtime. Either the Babel transform ' +
|
|
@@ -51,7 +51,7 @@ function graphql(strings: Array<string>): GraphQLTaggedNode {
|
|
|
51
51
|
|
|
52
52
|
function getNode(
|
|
53
53
|
taggedNode: GraphQLTaggedNode,
|
|
54
|
-
): ReaderFragment | ConcreteRequest {
|
|
54
|
+
): ReaderFragment | ReaderInlineDataFragment | ConcreteRequest {
|
|
55
55
|
let node = taggedNode;
|
|
56
56
|
if (typeof node === 'function') {
|
|
57
57
|
node = (node(): ReaderFragment | ConcreteRequest);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
import type {ConcreteRequest
|
|
14
|
+
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
15
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
15
16
|
|
|
16
17
|
type Callback = (concreteRequest: ConcreteRequest) => void;
|
|
17
18
|
|
|
@@ -60,6 +61,7 @@ class PreloadableQueryRegistry {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
const preloadableQueryRegistry: PreloadableQueryRegistry =
|
|
64
|
+
const preloadableQueryRegistry: PreloadableQueryRegistry =
|
|
65
|
+
new PreloadableQueryRegistry();
|
|
64
66
|
|
|
65
67
|
module.exports = preloadableQueryRegistry;
|