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
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @emails oncall+relay
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
|
+
|
|
16
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
17
|
+
|
|
18
|
+
var _require = require('../query/GraphQLTag'),
|
|
19
|
+
getRequest = _require.getRequest;
|
|
20
|
+
|
|
21
|
+
var _require2 = require('../store/RelayStoreUtils'),
|
|
22
|
+
getArgumentValues = _require2.getArgumentValues;
|
|
23
|
+
|
|
24
|
+
var nonUpdatableKeys = ['id', '__id', '__typename'];
|
|
25
|
+
|
|
26
|
+
function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
|
|
27
|
+
// TODO assert that the concrete request is an updatable query
|
|
28
|
+
var request = getRequest(query);
|
|
29
|
+
var updatableProxy = {};
|
|
30
|
+
updateProxyFromSelections(updatableProxy, proxy.getRoot(), variables, request.fragment.selections, proxy);
|
|
31
|
+
|
|
32
|
+
if (process.env.NODE_ENV !== "production") {
|
|
33
|
+
Object.freeze(updatableProxy);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return updatableProxy;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selections, root) {
|
|
40
|
+
var _selection$alias, _selection$alias2;
|
|
41
|
+
|
|
42
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
|
|
43
|
+
_step;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
var _loop = function _loop() {
|
|
47
|
+
var selection = _step.value;
|
|
48
|
+
|
|
49
|
+
switch (selection.kind) {
|
|
50
|
+
case 'LinkedField':
|
|
51
|
+
// Linked fields are assignable if they contain fragment spreads or
|
|
52
|
+
// read-only otherwise.
|
|
53
|
+
var isAssignable = selection.selections.some(function (item) {
|
|
54
|
+
return item.kind === 'FragmentSpread';
|
|
55
|
+
});
|
|
56
|
+
var set = !isAssignable ? undefined : selection.plural ? createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
|
|
57
|
+
var get = selection.plural ? createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
|
|
58
|
+
Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
|
|
59
|
+
get: get,
|
|
60
|
+
set: set
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'ScalarField':
|
|
65
|
+
var scalarFieldName = (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name;
|
|
66
|
+
Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
|
|
67
|
+
get: function get() {
|
|
68
|
+
var _selection$args;
|
|
69
|
+
|
|
70
|
+
var variables = getArgumentValues((_selection$args = selection.args) !== null && _selection$args !== void 0 ? _selection$args : [], queryVariables); // Flow incorrect assumes that the return value for the get method must match
|
|
71
|
+
// the set parameter.
|
|
72
|
+
|
|
73
|
+
return recordProxy.getValue(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
74
|
+
variables // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
set: nonUpdatableKeys.includes(selection.name) ? undefined : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
78
|
+
function (newValue) {
|
|
79
|
+
var _selection$args2;
|
|
80
|
+
|
|
81
|
+
var variables = getArgumentValues((_selection$args2 = selection.args) !== null && _selection$args2 !== void 0 ? _selection$args2 : [], queryVariables);
|
|
82
|
+
recordProxy.setValue(newValue, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
83
|
+
variables);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'InlineFragment':
|
|
89
|
+
if (recordProxy.getType() === selection.type) {
|
|
90
|
+
updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selection.selections, root);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case 'FragmentSpread':
|
|
96
|
+
// Explicitly ignore
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
throw new Error('Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
105
|
+
_loop();
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
_iterator.e(err);
|
|
109
|
+
} finally {
|
|
110
|
+
_iterator.f();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
|
|
115
|
+
return function set(newValue) {
|
|
116
|
+
var _selection$args3;
|
|
117
|
+
|
|
118
|
+
var variables = getArgumentValues((_selection$args3 = selection.args) !== null && _selection$args3 !== void 0 ? _selection$args3 : [], queryVariables);
|
|
119
|
+
|
|
120
|
+
if (newValue == null) {
|
|
121
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
122
|
+
recordProxy.setValue(null, selection.name, variables);
|
|
123
|
+
} else {
|
|
124
|
+
var recordProxies = newValue.map(function (item) {
|
|
125
|
+
if (item == null) {
|
|
126
|
+
throw new Error('When assigning an array of items, none of the items should be null or undefined.');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var __id = item.__id;
|
|
130
|
+
|
|
131
|
+
if (__id == null) {
|
|
132
|
+
throw new Error('The __id field must be present on each item passed to the setter. This indicates a bug in Relay.');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var newValueRecord = root.get(__id);
|
|
136
|
+
|
|
137
|
+
if (newValueRecord == null) {
|
|
138
|
+
throw new Error("Did not find item with data id ".concat(__id, " in the store."));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return newValueRecord;
|
|
142
|
+
});
|
|
143
|
+
recordProxy.setLinkedRecords(recordProxies, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
144
|
+
variables);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
|
|
150
|
+
return function set(newValue) {
|
|
151
|
+
var _selection$args4;
|
|
152
|
+
|
|
153
|
+
var variables = getArgumentValues((_selection$args4 = selection.args) !== null && _selection$args4 !== void 0 ? _selection$args4 : [], queryVariables);
|
|
154
|
+
|
|
155
|
+
if (newValue == null) {
|
|
156
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
157
|
+
recordProxy.setValue(null, selection.name, variables);
|
|
158
|
+
} else {
|
|
159
|
+
var __id = newValue.__id;
|
|
160
|
+
|
|
161
|
+
if (__id == null) {
|
|
162
|
+
throw new Error('The __id field must be present on the argument. This indicates a bug in Relay.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var newValueRecord = root.get(__id);
|
|
166
|
+
|
|
167
|
+
if (newValueRecord == null) {
|
|
168
|
+
throw new Error("Did not find item with data id ".concat(__id, " in the store."));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
recordProxy.setLinkedRecord(newValueRecord, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
172
|
+
variables);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
|
|
178
|
+
return function () {
|
|
179
|
+
var _selection$args5;
|
|
180
|
+
|
|
181
|
+
var variables = getArgumentValues((_selection$args5 = selection.args) !== null && _selection$args5 !== void 0 ? _selection$args5 : [], queryVariables);
|
|
182
|
+
var linkedRecords = recordProxy.getLinkedRecords(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
183
|
+
variables);
|
|
184
|
+
|
|
185
|
+
if (linkedRecords != null) {
|
|
186
|
+
return linkedRecords.map(function (linkedRecord) {
|
|
187
|
+
if (linkedRecord != null) {
|
|
188
|
+
var updatableProxy = {};
|
|
189
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
|
|
190
|
+
|
|
191
|
+
if (process.env.NODE_ENV !== "production") {
|
|
192
|
+
Object.freeze(updatableProxy);
|
|
193
|
+
} // Flow incorrect assumes that the return value for the get method must match
|
|
194
|
+
// the set parameter.
|
|
195
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
return updatableProxy;
|
|
199
|
+
} else {
|
|
200
|
+
return linkedRecord;
|
|
201
|
+
} // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
202
|
+
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
return linkedRecords;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
|
|
211
|
+
return function () {
|
|
212
|
+
var _selection$args6;
|
|
213
|
+
|
|
214
|
+
var variables = getArgumentValues((_selection$args6 = selection.args) !== null && _selection$args6 !== void 0 ? _selection$args6 : [], queryVariables);
|
|
215
|
+
var linkedRecord = recordProxy.getLinkedRecord(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
216
|
+
variables);
|
|
217
|
+
|
|
218
|
+
if (linkedRecord != null) {
|
|
219
|
+
var updatableProxy = {};
|
|
220
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
|
|
221
|
+
|
|
222
|
+
if (process.env.NODE_ENV !== "production") {
|
|
223
|
+
Object.freeze(updatableProxy);
|
|
224
|
+
} // Flow incorrect assumes that the return value for the get method must match
|
|
225
|
+
// the set parameter.
|
|
226
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
return updatableProxy;
|
|
230
|
+
} else {
|
|
231
|
+
return linkedRecord;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
module.exports = {
|
|
237
|
+
readUpdatableQuery_EXPERIMENTAL: readUpdatableQuery_EXPERIMENTAL
|
|
238
|
+
};
|
|
@@ -14,13 +14,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var warning = require("fbjs/lib/warning");
|
|
18
|
-
|
|
19
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
20
|
-
|
|
21
17
|
var _require = require('../util/RelayConcreteNode'),
|
|
22
|
-
|
|
18
|
+
ACTOR_CHANGE = _require.ACTOR_CHANGE,
|
|
19
|
+
CLIENT_COMPONENT = _require.CLIENT_COMPONENT,
|
|
23
20
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
21
|
+
CONDITION = _require.CONDITION,
|
|
24
22
|
DEFER = _require.DEFER,
|
|
25
23
|
FLIGHT_FIELD = _require.FLIGHT_FIELD,
|
|
26
24
|
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
@@ -33,6 +31,11 @@ var _require = require('../util/RelayConcreteNode'),
|
|
|
33
31
|
STREAM = _require.STREAM,
|
|
34
32
|
TYPE_DISCRIMINATOR = _require.TYPE_DISCRIMINATOR;
|
|
35
33
|
|
|
34
|
+
var warning = require("fbjs/lib/warning");
|
|
35
|
+
|
|
36
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
37
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
38
|
+
|
|
36
39
|
var validateMutation = function validateMutation() {};
|
|
37
40
|
|
|
38
41
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -79,6 +82,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
79
82
|
validateSelections(optimisticResponse, selection.selections, context);
|
|
80
83
|
return;
|
|
81
84
|
|
|
85
|
+
case CLIENT_COMPONENT:
|
|
82
86
|
case FRAGMENT_SPREAD:
|
|
83
87
|
validateSelections(optimisticResponse, selection.fragment.selections, context);
|
|
84
88
|
return;
|
|
@@ -88,6 +92,9 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
88
92
|
case FLIGHT_FIELD:
|
|
89
93
|
return validateField(optimisticResponse, selection, context);
|
|
90
94
|
|
|
95
|
+
case ACTOR_CHANGE:
|
|
96
|
+
return validateField(optimisticResponse, selection.linkedField, context);
|
|
97
|
+
|
|
91
98
|
case INLINE_FRAGMENT:
|
|
92
99
|
var type = selection.type;
|
|
93
100
|
var isConcreteType = selection.abstractKey == null;
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
var RelayObservable = require('./RelayObservable');
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
17
16
|
*/
|
|
17
|
+
|
|
18
|
+
|
|
18
19
|
function convertFetch(fn) {
|
|
19
20
|
return function fetch(request, variables, cacheConfig, uploadables, logRequestInfo) {
|
|
20
21
|
var result = fn(request, variables, cacheConfig, uploadables, logRequestInfo); // Note: We allow FetchFunction to directly return Error to indicate
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require("fbjs/lib/invariant");
|
|
14
|
-
|
|
15
13
|
var _require = require('./ConvertToExecuteFunction'),
|
|
16
14
|
convertFetch = _require.convertFetch;
|
|
17
15
|
|
|
16
|
+
var invariant = require('invariant');
|
|
18
17
|
/**
|
|
19
18
|
* Creates an implementation of the `Network` interface defined in
|
|
20
19
|
* `RelayNetworkTypes` given `fetch` and `subscribe` functions.
|
|
21
20
|
*/
|
|
21
|
+
|
|
22
|
+
|
|
22
23
|
function create(fetchFn, subscribe) {
|
|
23
24
|
// Convert to functions that returns RelayObservable.
|
|
24
25
|
var observeFetch = convertFetch(fetchFn);
|
|
@@ -14,10 +14,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var invariant = require("fbjs/lib/invariant");
|
|
18
|
-
|
|
19
17
|
var stableCopy = require('../util/stableCopy');
|
|
20
18
|
|
|
19
|
+
var invariant = require('invariant');
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* A cache for storing query responses, featuring:
|
|
23
23
|
* - `get` with TTL
|
|
@@ -53,11 +53,28 @@ var RelayQueryResponseCache = /*#__PURE__*/function () {
|
|
|
53
53
|
|
|
54
54
|
var response = this._responses.get(cacheKey);
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
if (response == null) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (Array.isArray(response.payload)) {
|
|
61
|
+
return response.payload.map(function (payload) {
|
|
62
|
+
return (// $FlowFixMe[incompatible-cast]
|
|
63
|
+
(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, payload), {}, {
|
|
64
|
+
extensions: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, payload.extensions), {}, {
|
|
65
|
+
cacheTimestamp: response.fetchTime
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
} // $FlowFixMe[incompatible-cast]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload), {}, {
|
|
57
74
|
extensions: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload.extensions), {}, {
|
|
58
75
|
cacheTimestamp: response.fetchTime
|
|
59
76
|
})
|
|
60
|
-
})
|
|
77
|
+
});
|
|
61
78
|
};
|
|
62
79
|
|
|
63
80
|
_proto.set = function set(queryID, variables, payload) {
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
// flowlint ambiguous-object-type:error
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var generateID = require('../util/generateID');
|
|
14
|
+
/**
|
|
15
|
+
* Wraps the network with logging to ensure that network requests are
|
|
16
|
+
* always logged. Relying on each network callsite to be wrapped is
|
|
17
|
+
* untenable and will eventually lead to holes in the logging.
|
|
18
|
+
* NOTE: This function takes an environment instance, because Relay
|
|
19
|
+
* devtools will mutate the `env.__log` method, and the devtools rely
|
|
20
|
+
* on it to receive network events.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function wrapNetworkWithLogObserver(env, network) {
|
|
25
|
+
return {
|
|
26
|
+
execute: function execute(params, variables, cacheConfig, uploadables) {
|
|
27
|
+
var networkRequestId = generateID();
|
|
28
|
+
var logObserver = {
|
|
29
|
+
start: function start(subscription) {
|
|
30
|
+
env.__log({
|
|
31
|
+
name: 'network.start',
|
|
32
|
+
networkRequestId: networkRequestId,
|
|
33
|
+
params: params,
|
|
34
|
+
variables: variables,
|
|
35
|
+
cacheConfig: cacheConfig
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
next: function next(response) {
|
|
39
|
+
env.__log({
|
|
40
|
+
name: 'network.next',
|
|
41
|
+
networkRequestId: networkRequestId,
|
|
42
|
+
response: response
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
error: function error(_error) {
|
|
46
|
+
env.__log({
|
|
47
|
+
name: 'network.error',
|
|
48
|
+
networkRequestId: networkRequestId,
|
|
49
|
+
error: _error
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
complete: function complete() {
|
|
53
|
+
env.__log({
|
|
54
|
+
name: 'network.complete',
|
|
55
|
+
networkRequestId: networkRequestId
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
unsubscribe: function unsubscribe() {
|
|
59
|
+
env.__log({
|
|
60
|
+
name: 'network.unsubscribe',
|
|
61
|
+
networkRequestId: networkRequestId
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var logRequestInfo = function logRequestInfo(info) {
|
|
67
|
+
env.__log({
|
|
68
|
+
name: 'network.info',
|
|
69
|
+
networkRequestId: networkRequestId,
|
|
70
|
+
info: info
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return network.execute(params, variables, cacheConfig, uploadables, logRequestInfo)["do"](logObserver);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = wrapNetworkWithLogObserver;
|
package/lib/query/GraphQLTag.js
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
var RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
14
14
|
|
|
15
|
-
var invariant = require(
|
|
15
|
+
var invariant = require('invariant');
|
|
16
|
+
|
|
17
|
+
var warning = require("fbjs/lib/warning"); // The type of a graphql`...` tagged template expression.
|
|
16
18
|
|
|
17
|
-
var warning = require("fbjs/lib/warning");
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Runtime function to correspond to the `graphql` tagged template function.
|
package/lib/query/fetchQuery.js
CHANGED
|
@@ -17,18 +17,17 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
17
17
|
|
|
18
18
|
var RelayObservable = require('../network/RelayObservable');
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var invariant = require("fbjs/lib/invariant");
|
|
20
|
+
var _require = require('../store/RelayModernOperationDescriptor'),
|
|
21
|
+
createOperationDescriptor = _require.createOperationDescriptor;
|
|
23
22
|
|
|
24
23
|
var reportMissingRequiredFields = require('../util/reportMissingRequiredFields');
|
|
25
24
|
|
|
26
|
-
var
|
|
27
|
-
createOperationDescriptor = _require.createOperationDescriptor;
|
|
25
|
+
var fetchQueryInternal = require('./fetchQueryInternal');
|
|
28
26
|
|
|
29
27
|
var _require2 = require('./GraphQLTag'),
|
|
30
28
|
getRequest = _require2.getRequest;
|
|
31
29
|
|
|
30
|
+
var invariant = require('invariant');
|
|
32
31
|
/**
|
|
33
32
|
* Fetches the given query and variables on the provided environment,
|
|
34
33
|
* and de-dupes identical in-flight requests.
|
|
@@ -106,6 +105,8 @@ var _require2 = require('./GraphQLTag'),
|
|
|
106
105
|
* ```
|
|
107
106
|
* NOTE: When using .toPromise(), the request cannot be cancelled.
|
|
108
107
|
*/
|
|
108
|
+
|
|
109
|
+
|
|
109
110
|
function fetchQuery(environment, query, variables, options) {
|
|
110
111
|
var _options$fetchPolicy;
|
|
111
112
|
|
|
@@ -14,7 +14,7 @@ var Observable = require('../network/RelayObservable');
|
|
|
14
14
|
|
|
15
15
|
var RelayReplaySubject = require('../util/RelayReplaySubject');
|
|
16
16
|
|
|
17
|
-
var invariant = require(
|
|
17
|
+
var invariant = require('invariant');
|
|
18
18
|
|
|
19
19
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
20
20
|
var requestCachesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
|
@@ -15,12 +15,13 @@ var _require = require('../store/RelayModernOperationDescriptor'),
|
|
|
15
15
|
|
|
16
16
|
var _require2 = require('./GraphQLTag'),
|
|
17
17
|
getRequest = _require2.getRequest;
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* A helper function to fetch the results of a query. Note that results for
|
|
21
20
|
* fragment spreads are masked: fields must be explicitly listed in the query in
|
|
22
21
|
* order to be accessible in the result object.
|
|
23
22
|
*/
|
|
23
|
+
|
|
24
|
+
|
|
24
25
|
function fetchQuery_DEPRECATED(environment, taggedNode, variables, cacheConfig) {
|
|
25
26
|
var query = getRequest(taggedNode);
|
|
26
27
|
|
package/lib/store/ClientID.js
CHANGED
|
@@ -10,10 +10,16 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
14
|
+
|
|
15
|
+
var _require = require('../util/StringInterner'),
|
|
16
|
+
intern = _require.intern;
|
|
17
|
+
|
|
13
18
|
var PREFIX = 'client:';
|
|
14
19
|
|
|
15
20
|
function generateClientID(id, storageKey, index) {
|
|
16
|
-
var
|
|
21
|
+
var internedId = RelayFeatureFlags.STRING_INTERN_LEVEL <= 0 ? id : intern(id, RelayFeatureFlags.MAX_DATA_ID_LENGTH);
|
|
22
|
+
var key = internedId + ':' + storageKey;
|
|
17
23
|
|
|
18
24
|
if (index != null) {
|
|
19
25
|
key += ':' + index;
|