relay-runtime 1.7.0-rc.1 → 2.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/index.js +1 -1
- package/lib/ConvertToExecuteFunction.js +12 -75
- package/lib/DataChecker.js +400 -0
- package/lib/NormalizationNode.js +14 -0
- package/lib/ReaderNode.js +10 -0
- package/lib/RelayCombinedEnvironmentTypes.js +10 -0
- package/lib/RelayConcreteNode.js +12 -29
- package/lib/RelayConcreteVariables.js +17 -11
- package/lib/RelayConnectionHandler.js +98 -42
- package/lib/RelayConnectionInterface.js +5 -13
- package/lib/RelayCore.js +17 -14
- package/lib/RelayDeclarativeMutationConfig.js +69 -34
- package/lib/RelayDefaultHandleKey.js +1 -2
- package/lib/RelayDefaultHandlerProvider.js +6 -5
- package/lib/RelayError.js +6 -9
- package/lib/RelayInMemoryRecordSource.js +20 -22
- package/lib/RelayModernEnvironment.js +140 -229
- package/lib/RelayModernFragmentSpecResolver.js +110 -102
- package/lib/RelayModernGraphQLTag.js +53 -15
- package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernRecord.js +97 -38
- package/lib/RelayModernSelector.js +89 -33
- package/lib/RelayModernStore.js +301 -0
- package/lib/RelayNetwork.js +16 -28
- package/lib/RelayNetworkLogger.js +2 -3
- package/lib/RelayNetworkLoggerTransaction.js +32 -30
- package/lib/RelayNetworkTypes.js +1 -2
- package/lib/RelayObservable.js +127 -155
- package/lib/RelayProfiler.js +35 -22
- package/lib/RelayPublishQueue.js +144 -96
- package/lib/RelayQueryResponseCache.js +37 -21
- package/lib/RelayReader.js +194 -61
- package/lib/RelayRecordProxy.js +50 -31
- package/lib/RelayRecordSourceMutator.js +92 -51
- package/lib/RelayRecordSourceProxy.js +43 -35
- package/lib/RelayRecordSourceSelectorProxy.js +22 -21
- package/lib/RelayRecordState.js +1 -3
- package/lib/RelayReferenceMarker.js +110 -37
- package/lib/RelayResponseNormalizer.js +248 -82
- package/lib/RelayRuntimeTypes.js +1 -3
- package/lib/RelayStoreTypes.js +1 -2
- package/lib/RelayStoreUtils.js +37 -19
- package/lib/RelayViewerHandler.js +14 -10
- package/lib/applyRelayModernOptimisticMutation.js +8 -8
- package/lib/cloneRelayHandleSourceField.js +8 -9
- package/lib/commitLocalUpdate.js +1 -2
- package/lib/commitRelayModernMutation.js +21 -14
- package/lib/createRelayNetworkLogger.js +11 -9
- package/lib/deepFreeze.js +2 -3
- package/lib/fetchRelayModernQuery.js +10 -12
- package/lib/generateRelayClientID.js +4 -2
- package/lib/getRelayHandleKey.js +5 -6
- package/lib/hasOverlappingIDs.js +3 -2
- package/lib/index.js +59 -62
- package/lib/isPromise.js +1 -2
- package/lib/isRelayModernEnvironment.js +1 -3
- package/lib/isScalarAndEqual.js +1 -3
- package/lib/normalizePayload.js +17 -15
- package/lib/normalizeRelayPayload.js +9 -9
- package/lib/recycleNodesInto.js +25 -9
- package/lib/requestRelaySubscription.js +25 -58
- package/lib/simpleClone.js +2 -3
- package/lib/stableCopy.js +5 -3
- package/lib/validateMutation.js +146 -0
- package/package.json +3 -3
- package/relay-runtime.js +4 -0
- package/relay-runtime.min.js +9 -0
- package/lib/RelayDataLoader.js +0 -302
- package/lib/RelayMarkSweepStore.js +0 -242
- package/lib/deferrableFragmentKey.js +0 -20
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/index.js
CHANGED
|
@@ -1,109 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
16
|
-
|
|
17
|
-
function filterDataFromStream(observable) {
|
|
18
|
-
return require('./RelayObservable').create(function (sink) {
|
|
19
|
-
return observable.subscribe({
|
|
20
|
-
next: function next(value) {
|
|
21
|
-
if (value.kind === 'data') {
|
|
22
|
-
sink.next(value);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
error: sink.error,
|
|
27
|
-
complete: sink.complete
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
12
|
/**
|
|
33
13
|
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
34
14
|
*/
|
|
35
15
|
function convertFetch(fn) {
|
|
36
16
|
return function fetch(request, variables, cacheConfig, uploadables) {
|
|
37
|
-
var result = fn(request, variables, cacheConfig, uploadables);
|
|
38
|
-
// Note: We allow FetchFunction to directly return Error to indicate
|
|
17
|
+
var result = fn(request, variables, cacheConfig, uploadables); // Note: We allow FetchFunction to directly return Error to indicate
|
|
39
18
|
// a failure to fetch. To avoid handling this special case throughout the
|
|
40
19
|
// Relay codebase, it is explicitly handled here.
|
|
20
|
+
|
|
41
21
|
if (result instanceof Error) {
|
|
42
|
-
return
|
|
22
|
+
return require("./RelayObservable").create(function (sink) {
|
|
43
23
|
return sink.error(result);
|
|
44
|
-
})
|
|
24
|
+
});
|
|
45
25
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
return filterDataFromStream(withEvents);
|
|
26
|
+
|
|
27
|
+
return require("./RelayObservable").from(result);
|
|
50
28
|
};
|
|
51
29
|
}
|
|
52
|
-
|
|
53
30
|
/**
|
|
54
31
|
* Converts a SubscribeFunction into an ExecuteFunction for use by RelayNetwork.
|
|
55
32
|
*/
|
|
56
|
-
function convertSubscribe(fn) {
|
|
57
|
-
return function subscribe(operation, variables, cacheConfig) {
|
|
58
|
-
var withEvents = require('./RelayObservable').fromLegacy(function (observer) {
|
|
59
|
-
return fn(operation, variables, cacheConfig, observer);
|
|
60
|
-
}).map(function (value) {
|
|
61
|
-
return convertToStreamPayload(operation, variables, value);
|
|
62
|
-
});
|
|
63
|
-
return filterDataFromStream(withEvents);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
33
|
|
|
67
|
-
|
|
34
|
+
|
|
35
|
+
function convertSubscribe(fn) {
|
|
68
36
|
return function subscribe(operation, variables, cacheConfig) {
|
|
69
|
-
return require(
|
|
37
|
+
return require("./RelayObservable").fromLegacy(function (observer) {
|
|
70
38
|
return fn(operation, variables, cacheConfig, observer);
|
|
71
|
-
}).map(function (value) {
|
|
72
|
-
return convertToStreamPayload(operation, variables, value);
|
|
73
39
|
});
|
|
74
40
|
};
|
|
75
41
|
}
|
|
76
42
|
|
|
77
|
-
/**
|
|
78
|
-
* Given a value which might be a plain GraphQLResponse, coerce to always return
|
|
79
|
-
* an ExecutePayload. A GraphQLResponse may be returned directly from older or
|
|
80
|
-
* simpler Relay Network implementations.
|
|
81
|
-
*/
|
|
82
|
-
function convertToStreamPayload(request, variables, value) {
|
|
83
|
-
if (!value.data && !value.errors && value.response) {
|
|
84
|
-
if (!value.operation) {
|
|
85
|
-
process.env.NODE_ENV !== 'production' ? require('fbjs/lib/warning')(false, 'ConvertToExecuteFunction: execute payload contains response but ' + 'is missing operation.') : void 0;
|
|
86
|
-
return createExecutePayload(request, variables, value.response);
|
|
87
|
-
}
|
|
88
|
-
// assume value is data if value.response defined, but no kind field given
|
|
89
|
-
return (0, _extends3['default'])({}, value, { kind: 'data' });
|
|
90
|
-
} else if (!value.data && !value.errors && value.kind === 'event') {
|
|
91
|
-
return value;
|
|
92
|
-
} else {
|
|
93
|
-
// in this case we have a GraphQLResponse
|
|
94
|
-
return createExecutePayload(request, variables, value);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function createExecutePayload(request, variables, response) {
|
|
99
|
-
if (request.kind === require('./RelayConcreteNode').BATCH_REQUEST) {
|
|
100
|
-
throw new Error('ConvertToExecuteFunction: Batch request must return ExecutePayload.');
|
|
101
|
-
}
|
|
102
|
-
return { kind: 'data', operation: request.operation, variables: variables, response: response };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
43
|
module.exports = {
|
|
106
44
|
convertFetch: convertFetch,
|
|
107
|
-
convertSubscribe: convertSubscribe
|
|
108
|
-
convertSubscribeWithEvents: convertSubscribeWithEvents
|
|
45
|
+
convertSubscribe: convertSubscribe
|
|
109
46
|
};
|
|
@@ -0,0 +1,400 @@
|
|
|
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
|
+
* strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Synchronously check whether the records required to fulfill the given
|
|
15
|
+
* `selector` are present in `source`.
|
|
16
|
+
*
|
|
17
|
+
* If a field is missing, it uses the provided handlers to attempt to substitute
|
|
18
|
+
* data. The `target` will store all records that are modified because of a
|
|
19
|
+
* successful substitution.
|
|
20
|
+
*
|
|
21
|
+
* If all records are present, returns `true`, otherwise `false`.
|
|
22
|
+
*/
|
|
23
|
+
function check(source, target, selector, handlers, operationLoader) {
|
|
24
|
+
var dataID = selector.dataID,
|
|
25
|
+
node = selector.node,
|
|
26
|
+
variables = selector.variables;
|
|
27
|
+
var checker = new DataChecker(source, target, variables, handlers, operationLoader);
|
|
28
|
+
return checker.check(node, dataID);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var DataChecker =
|
|
36
|
+
/*#__PURE__*/
|
|
37
|
+
function () {
|
|
38
|
+
function DataChecker(source, target, variables, handlers, operationLoader) {
|
|
39
|
+
var _operationLoader;
|
|
40
|
+
|
|
41
|
+
this._operationLoader = (_operationLoader = operationLoader) !== null && _operationLoader !== void 0 ? _operationLoader : null;
|
|
42
|
+
this._handlers = handlers;
|
|
43
|
+
this._mutator = new (require("./RelayRecordSourceMutator"))(source, target);
|
|
44
|
+
this._recordWasMissing = false;
|
|
45
|
+
this._source = source;
|
|
46
|
+
this._variables = variables;
|
|
47
|
+
this._recordSourceProxy = new (require("./RelayRecordSourceProxy"))(this._mutator);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var _proto = DataChecker.prototype;
|
|
51
|
+
|
|
52
|
+
_proto.check = function check(node, dataID) {
|
|
53
|
+
this._traverse(node, dataID);
|
|
54
|
+
|
|
55
|
+
return !this._recordWasMissing;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
_proto._getVariableValue = function _getVariableValue(name) {
|
|
59
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayAsyncLoader(): Undefined variable `%s`.', name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
60
|
+
return this._variables[name];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
_proto._handleMissing = function _handleMissing() {
|
|
64
|
+
this._recordWasMissing = true;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
_proto._getDataForHandlers = function _getDataForHandlers(field, dataID) {
|
|
68
|
+
return {
|
|
69
|
+
args: field.args ? require("./RelayStoreUtils").getArgumentValues(field.args, this._variables) : {},
|
|
70
|
+
// Getting a snapshot of the record state is potentially expensive since
|
|
71
|
+
// we will need to merge the sink and source records. Since we do not create
|
|
72
|
+
// any new records in this process, it is probably reasonable to provide
|
|
73
|
+
// handlers with a copy of the source record.
|
|
74
|
+
// The only thing that the provided record will not contain is fields
|
|
75
|
+
// added by previous handlers.
|
|
76
|
+
record: this._source.get(dataID)
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
_proto._handleMissingScalarField = function _handleMissingScalarField(field, dataID) {
|
|
81
|
+
var _this$_getDataForHand = this._getDataForHandlers(field, dataID),
|
|
82
|
+
args = _this$_getDataForHand.args,
|
|
83
|
+
record = _this$_getDataForHand.record;
|
|
84
|
+
|
|
85
|
+
var _iteratorNormalCompletion = true;
|
|
86
|
+
var _didIteratorError = false;
|
|
87
|
+
var _iteratorError = undefined;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
for (var _iterator = this._handlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
91
|
+
var handler = _step.value;
|
|
92
|
+
|
|
93
|
+
if (handler.kind === 'scalar') {
|
|
94
|
+
var newValue = handler.handle(field, record, args, this._recordSourceProxy);
|
|
95
|
+
|
|
96
|
+
if (newValue !== undefined) {
|
|
97
|
+
return newValue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
_didIteratorError = true;
|
|
103
|
+
_iteratorError = err;
|
|
104
|
+
} finally {
|
|
105
|
+
try {
|
|
106
|
+
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
107
|
+
_iterator["return"]();
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
if (_didIteratorError) {
|
|
111
|
+
throw _iteratorError;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this._handleMissing();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
_proto._handleMissingLinkField = function _handleMissingLinkField(field, dataID) {
|
|
120
|
+
var _this$_getDataForHand2 = this._getDataForHandlers(field, dataID),
|
|
121
|
+
args = _this$_getDataForHand2.args,
|
|
122
|
+
record = _this$_getDataForHand2.record;
|
|
123
|
+
|
|
124
|
+
var _iteratorNormalCompletion2 = true;
|
|
125
|
+
var _didIteratorError2 = false;
|
|
126
|
+
var _iteratorError2 = undefined;
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
for (var _iterator2 = this._handlers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
130
|
+
var handler = _step2.value;
|
|
131
|
+
|
|
132
|
+
if (handler.kind === 'linked') {
|
|
133
|
+
var newValue = handler.handle(field, record, args, this._recordSourceProxy);
|
|
134
|
+
|
|
135
|
+
if (newValue != null && this._mutator.getStatus(newValue) === require("./RelayRecordState").EXISTENT) {
|
|
136
|
+
return newValue;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
_didIteratorError2 = true;
|
|
142
|
+
_iteratorError2 = err;
|
|
143
|
+
} finally {
|
|
144
|
+
try {
|
|
145
|
+
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
|
146
|
+
_iterator2["return"]();
|
|
147
|
+
}
|
|
148
|
+
} finally {
|
|
149
|
+
if (_didIteratorError2) {
|
|
150
|
+
throw _iteratorError2;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this._handleMissing();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
_proto._handleMissingPluralLinkField = function _handleMissingPluralLinkField(field, dataID) {
|
|
159
|
+
var _this = this;
|
|
160
|
+
|
|
161
|
+
var _this$_getDataForHand3 = this._getDataForHandlers(field, dataID),
|
|
162
|
+
args = _this$_getDataForHand3.args,
|
|
163
|
+
record = _this$_getDataForHand3.record;
|
|
164
|
+
|
|
165
|
+
var _iteratorNormalCompletion3 = true;
|
|
166
|
+
var _didIteratorError3 = false;
|
|
167
|
+
var _iteratorError3 = undefined;
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
for (var _iterator3 = this._handlers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
171
|
+
var handler = _step3.value;
|
|
172
|
+
|
|
173
|
+
if (handler.kind === 'pluralLinked') {
|
|
174
|
+
var newValue = handler.handle(field, record, args, this._recordSourceProxy);
|
|
175
|
+
|
|
176
|
+
if (newValue != null) {
|
|
177
|
+
return newValue.filter(function (linkedID) {
|
|
178
|
+
return linkedID != null && _this._mutator.getStatus(linkedID) === require("./RelayRecordState").EXISTENT;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch (err) {
|
|
184
|
+
_didIteratorError3 = true;
|
|
185
|
+
_iteratorError3 = err;
|
|
186
|
+
} finally {
|
|
187
|
+
try {
|
|
188
|
+
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
|
189
|
+
_iterator3["return"]();
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
if (_didIteratorError3) {
|
|
193
|
+
throw _iteratorError3;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this._handleMissing();
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
_proto._traverse = function _traverse(node, dataID) {
|
|
202
|
+
var status = this._mutator.getStatus(dataID);
|
|
203
|
+
|
|
204
|
+
if (status === require("./RelayRecordState").UNKNOWN) {
|
|
205
|
+
this._handleMissing();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (status === require("./RelayRecordState").EXISTENT) {
|
|
209
|
+
this._traverseSelections(node.selections, dataID);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
_proto._traverseSelections = function _traverseSelections(selections, dataID) {
|
|
214
|
+
var _this2 = this;
|
|
215
|
+
|
|
216
|
+
selections.forEach(function (selection) {
|
|
217
|
+
switch (selection.kind) {
|
|
218
|
+
case require("./RelayConcreteNode").SCALAR_FIELD:
|
|
219
|
+
_this2._checkScalar(selection, dataID);
|
|
220
|
+
|
|
221
|
+
break;
|
|
222
|
+
|
|
223
|
+
case require("./RelayConcreteNode").LINKED_FIELD:
|
|
224
|
+
if (selection.plural) {
|
|
225
|
+
_this2._checkPluralLink(selection, dataID);
|
|
226
|
+
} else {
|
|
227
|
+
_this2._checkLink(selection, dataID);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
break;
|
|
231
|
+
|
|
232
|
+
case require("./RelayConcreteNode").CONDITION:
|
|
233
|
+
var conditionValue = _this2._getVariableValue(selection.condition);
|
|
234
|
+
|
|
235
|
+
if (conditionValue === selection.passingValue) {
|
|
236
|
+
_this2._traverseSelections(selection.selections, dataID);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
break;
|
|
240
|
+
|
|
241
|
+
case require("./RelayConcreteNode").INLINE_FRAGMENT:
|
|
242
|
+
var typeName = _this2._mutator.getType(dataID);
|
|
243
|
+
|
|
244
|
+
if (typeName != null && typeName === selection.type) {
|
|
245
|
+
_this2._traverseSelections(selection.selections, dataID);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
break;
|
|
249
|
+
|
|
250
|
+
case require("./RelayConcreteNode").LINKED_HANDLE:
|
|
251
|
+
// Handles have no selections themselves; traverse the original field
|
|
252
|
+
// where the handle was set-up instead.
|
|
253
|
+
var handleField = require("./cloneRelayHandleSourceField")(selection, selections, _this2._variables);
|
|
254
|
+
|
|
255
|
+
if (handleField.plural) {
|
|
256
|
+
_this2._checkPluralLink(handleField, dataID);
|
|
257
|
+
} else {
|
|
258
|
+
_this2._checkLink(handleField, dataID);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
break;
|
|
262
|
+
|
|
263
|
+
case require("./RelayConcreteNode").MATCH_FIELD:
|
|
264
|
+
_this2._checkMatch(selection, dataID);
|
|
265
|
+
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
case require("./RelayConcreteNode").DEFER:
|
|
269
|
+
case require("./RelayConcreteNode").STREAM:
|
|
270
|
+
_this2._traverseSelections(selection.selections, dataID);
|
|
271
|
+
|
|
272
|
+
break;
|
|
273
|
+
|
|
274
|
+
case require("./RelayConcreteNode").SCALAR_HANDLE:
|
|
275
|
+
case require("./RelayConcreteNode").FRAGMENT_SPREAD:
|
|
276
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0; // $FlowExpectedError - we need the break; for OSS linter
|
|
277
|
+
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
default:
|
|
281
|
+
selection;
|
|
282
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
_proto._checkMatch = function _checkMatch(field, dataID) {
|
|
288
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
289
|
+
|
|
290
|
+
var linkedID = this._mutator.getLinkedRecordID(dataID, storageKey);
|
|
291
|
+
|
|
292
|
+
if (linkedID === undefined) {
|
|
293
|
+
this._handleMissing();
|
|
294
|
+
} else if (linkedID !== null) {
|
|
295
|
+
var status = this._mutator.getStatus(linkedID);
|
|
296
|
+
|
|
297
|
+
if (status === require("./RelayRecordState").UNKNOWN) {
|
|
298
|
+
this._handleMissing();
|
|
299
|
+
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (status !== require("./RelayRecordState").EXISTENT) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
var typeName = this._mutator.getType(linkedID);
|
|
308
|
+
|
|
309
|
+
var match = typeName != null ? field.matchesByType[typeName] : null;
|
|
310
|
+
|
|
311
|
+
if (match != null) {
|
|
312
|
+
var operationLoader = this._operationLoader;
|
|
313
|
+
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'DataChecker: Expected an operationLoader to be configured when using `@match`.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
314
|
+
|
|
315
|
+
var operationReference = this._mutator.getValue(linkedID, require("./RelayStoreUtils").MATCH_FRAGMENT_KEY);
|
|
316
|
+
|
|
317
|
+
if (operationReference === undefined) {
|
|
318
|
+
this._handleMissing();
|
|
319
|
+
|
|
320
|
+
return;
|
|
321
|
+
} else if (operationReference === null) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
var operation = operationLoader.get(operationReference);
|
|
326
|
+
|
|
327
|
+
if (operation != null) {
|
|
328
|
+
this._traverse(operation, linkedID);
|
|
329
|
+
} else {
|
|
330
|
+
// If the fragment is not available, we assume that the data cannot have been
|
|
331
|
+
// processed yet and must therefore be missing.
|
|
332
|
+
this._handleMissing();
|
|
333
|
+
}
|
|
334
|
+
} else {// TODO: warn: store is corrupt: the field should be null if the typename did not match
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
_proto._checkScalar = function _checkScalar(field, dataID) {
|
|
340
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
341
|
+
|
|
342
|
+
var fieldValue = this._mutator.getValue(dataID, storageKey);
|
|
343
|
+
|
|
344
|
+
if (fieldValue === undefined) {
|
|
345
|
+
fieldValue = this._handleMissingScalarField(field, dataID);
|
|
346
|
+
|
|
347
|
+
if (fieldValue !== undefined) {
|
|
348
|
+
this._mutator.setValue(dataID, storageKey, fieldValue);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
_proto._checkLink = function _checkLink(field, dataID) {
|
|
354
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
355
|
+
|
|
356
|
+
var linkedID = this._mutator.getLinkedRecordID(dataID, storageKey);
|
|
357
|
+
|
|
358
|
+
if (linkedID === undefined) {
|
|
359
|
+
linkedID = this._handleMissingLinkField(field, dataID);
|
|
360
|
+
|
|
361
|
+
if (linkedID != null) {
|
|
362
|
+
this._mutator.setLinkedRecordID(dataID, storageKey, linkedID);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (linkedID != null) {
|
|
367
|
+
this._traverse(field, linkedID);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
_proto._checkPluralLink = function _checkPluralLink(field, dataID) {
|
|
372
|
+
var _this3 = this;
|
|
373
|
+
|
|
374
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
375
|
+
|
|
376
|
+
var linkedIDs = this._mutator.getLinkedRecordIDs(dataID, storageKey);
|
|
377
|
+
|
|
378
|
+
if (linkedIDs === undefined) {
|
|
379
|
+
linkedIDs = this._handleMissingPluralLinkField(field, dataID);
|
|
380
|
+
|
|
381
|
+
if (linkedIDs != null) {
|
|
382
|
+
this._mutator.setLinkedRecordIDs(dataID, storageKey, linkedIDs);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (linkedIDs) {
|
|
387
|
+
linkedIDs.forEach(function (linkedID) {
|
|
388
|
+
if (linkedID != null) {
|
|
389
|
+
_this3._traverse(field, linkedID);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
return DataChecker;
|
|
396
|
+
}();
|
|
397
|
+
|
|
398
|
+
module.exports = {
|
|
399
|
+
check: check
|
|
400
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
/**
|
|
12
|
+
* Represents a single operation used to processing and normalize runtime
|
|
13
|
+
* request results.
|
|
14
|
+
*/
|
package/lib/RelayConcreteNode.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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.
|
|
6
6
|
*
|
|
7
|
-
* strict
|
|
7
|
+
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -16,11 +15,14 @@
|
|
|
16
15
|
* results, and a `fragment` derived from that operation to read the response
|
|
17
16
|
* data (masking data from child fragments).
|
|
18
17
|
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Contains the `text` (or persisted `id`) required for executing a common
|
|
21
|
+
* GraphQL request.
|
|
22
|
+
*/
|
|
19
23
|
var RelayConcreteNode = {
|
|
20
|
-
BATCH_REQUEST: 'BatchRequest',
|
|
21
24
|
CONDITION: 'Condition',
|
|
22
|
-
|
|
23
|
-
DEFERRABLE_OPERATION: 'DeferrableOperation',
|
|
25
|
+
DEFER: 'Defer',
|
|
24
26
|
FRAGMENT: 'Fragment',
|
|
25
27
|
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
26
28
|
INLINE_FRAGMENT: 'InlineFragment',
|
|
@@ -28,33 +30,14 @@ var RelayConcreteNode = {
|
|
|
28
30
|
LINKED_HANDLE: 'LinkedHandle',
|
|
29
31
|
LITERAL: 'Literal',
|
|
30
32
|
LOCAL_ARGUMENT: 'LocalArgument',
|
|
33
|
+
MATCH_FIELD: 'MatchField',
|
|
31
34
|
OPERATION: 'Operation',
|
|
32
|
-
ROOT_ARGUMENT: 'RootArgument',
|
|
33
35
|
REQUEST: 'Request',
|
|
36
|
+
ROOT_ARGUMENT: 'RootArgument',
|
|
34
37
|
SCALAR_FIELD: 'ScalarField',
|
|
35
38
|
SCALAR_HANDLE: 'ScalarHandle',
|
|
39
|
+
SPLIT_OPERATION: 'SplitOperation',
|
|
40
|
+
STREAM: 'Stream',
|
|
36
41
|
VARIABLE: 'Variable'
|
|
37
42
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Represents a single operation used to processing and normalize runtime
|
|
40
|
-
* request results.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Argument in the provided operation to be derived via the results of
|
|
45
|
-
* other requests in the batch.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* An experimental wrapper around many operations to request in a batched
|
|
50
|
-
* network request. The composed indivual GraphQL requests should be submitted
|
|
51
|
-
* as a single networked request, e.g. in the case of deferred nodes or
|
|
52
|
-
* for streaming connections that are represented as distinct compiled concrete
|
|
53
|
-
* operations but are still conceptually tied to one source operation.
|
|
54
|
-
*
|
|
55
|
-
* Individual requests within the batch may contain data describing their
|
|
56
|
-
* dependencies on other requests or themselves.
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
43
|
module.exports = RelayConcreteNode;
|