relay-runtime 1.3.0 → 1.5.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 +16 -26
- package/index.js +3 -6
- package/lib/ConvertToExecuteFunction.js +73 -0
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConcreteVariables.js +11 -6
- package/lib/RelayConnectionHandler.js +2 -4
- package/lib/RelayConnectionInterface.js +3 -5
- package/lib/RelayCore.js +4 -6
- package/lib/RelayDataLoader.js +2 -4
- package/lib/RelayDeclarativeMutationConfig.js +316 -0
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDefaultHandlerProvider.js +2 -4
- package/lib/RelayError.js +2 -6
- package/lib/RelayInMemoryRecordSource.js +2 -4
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayMarkSweepStore.js +22 -5
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayModernEnvironment.js +120 -135
- package/lib/RelayModernFragmentSpecResolver.js +81 -55
- package/lib/RelayModernGraphQLTag.js +8 -17
- package/lib/RelayModernOperationSelector.js +8 -8
- package/lib/RelayModernRecord.js +8 -8
- package/lib/RelayModernSelector.js +54 -43
- package/lib/RelayNetwork.js +9 -11
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayNetworkLogger.js +2 -4
- package/lib/RelayNetworkLoggerTransaction.js +18 -20
- package/lib/RelayNetworkTypes.js +2 -4
- package/lib/RelayObservable.js +193 -120
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayPublishQueue.js +17 -9
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayQueryResponseCache.js +3 -5
- package/lib/RelayReader.js +18 -8
- package/lib/RelayRecordProxy.js +12 -11
- package/lib/RelayRecordSourceMutator.js +9 -9
- package/lib/RelayRecordSourceProxy.js +15 -13
- package/lib/RelayRecordSourceSelectorProxy.js +2 -4
- package/lib/RelayRecordState.js +2 -4
- package/lib/RelayReferenceMarker.js +2 -4
- package/lib/RelayResponseNormalizer.js +34 -25
- package/lib/RelayRuntime.js +25 -14
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelayStoreTypes.js +2 -4
- package/lib/RelayStoreUtils.js +66 -26
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayViewerHandler.js +4 -5
- package/lib/applyRelayModernOptimisticMutation.js +9 -8
- package/lib/cloneRelayHandleSourceField.js +4 -11
- package/lib/commitLocalUpdate.js +2 -4
- package/lib/commitRelayModernMutation.js +24 -22
- package/lib/createRelayNetworkLogger.js +25 -27
- package/lib/dedent.js +2 -5
- package/lib/deepFreeze.js +3 -5
- package/lib/deferrableFragmentKey.js +21 -0
- package/lib/fetchRelayModernQuery.js +13 -21
- package/lib/generateRelayClientID.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/hasOverlappingIDs.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isPromise.js +2 -5
- package/lib/isRelayModernEnvironment.js +2 -4
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/normalizePayload.js +10 -13
- package/lib/normalizeRelayPayload.js +8 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestRelaySubscription.js +20 -34
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/package.json +4 -5
- package/relay-runtime.js +2307 -2665
- package/relay-runtime.min.js +6 -9
- package/ARCHITECTURE.md +0 -232
- package/PATENTS +0 -33
- package/lib/ConvertToObserveFunction.js +0 -39
- package/lib/RelayDebugger.js +0 -199
- package/lib/RelayRecordSourceInspector.js +0 -289
- package/lib/RelayStoreProxyDebugger.js +0 -44
- package/lib/formatStorageKey.js +0 -37
- package/lib/prettyStringify.js +0 -35
- package/lib/setRelayModernMutationConfigs.js +0 -302
- package/lib/stableJSONStringify.js +0 -45
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayModernFragmentSpecResolver
|
|
10
8
|
*
|
|
@@ -65,78 +63,96 @@ var RelayModernFragmentSpecResolver = function () {
|
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
RelayModernFragmentSpecResolver.prototype.dispose = function dispose() {
|
|
68
|
-
|
|
66
|
+
for (var _key in this._resolvers) {
|
|
67
|
+
if (this._resolvers.hasOwnProperty(_key)) {
|
|
68
|
+
disposeCallback(this._resolvers[_key]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
RelayModernFragmentSpecResolver.prototype.resolve = function resolve() {
|
|
72
|
-
var _this2 = this;
|
|
73
|
-
|
|
74
74
|
if (this._stale) {
|
|
75
75
|
// Avoid mapping the object multiple times, which could occur if data for
|
|
76
76
|
// multiple keys changes in the same event loop.
|
|
77
77
|
var prevData = this._data;
|
|
78
78
|
var nextData = void 0;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
nextData
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
nextData
|
|
79
|
+
for (var _key2 in this._resolvers) {
|
|
80
|
+
if (this._resolvers.hasOwnProperty(_key2)) {
|
|
81
|
+
var resolver = this._resolvers[_key2];
|
|
82
|
+
var prevItem = prevData[_key2];
|
|
83
|
+
if (resolver) {
|
|
84
|
+
var nextItem = resolver.resolve();
|
|
85
|
+
if (nextData || nextItem !== prevItem) {
|
|
86
|
+
nextData = nextData || (0, _extends3['default'])({}, prevData);
|
|
87
|
+
nextData[_key2] = nextItem;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
var prop = this._props[_key2];
|
|
91
|
+
var _nextItem = prop !== undefined ? prop : null;
|
|
92
|
+
if (nextData || !require('./isScalarAndEqual')(_nextItem, prevItem)) {
|
|
93
|
+
nextData = nextData || (0, _extends3['default'])({}, prevData);
|
|
94
|
+
nextData[_key2] = _nextItem;
|
|
95
|
+
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
}
|
|
98
|
+
}
|
|
96
99
|
this._data = nextData || prevData;
|
|
97
100
|
this._stale = false;
|
|
98
101
|
}
|
|
99
102
|
return this._data;
|
|
100
103
|
};
|
|
101
104
|
|
|
102
|
-
RelayModernFragmentSpecResolver.prototype.
|
|
103
|
-
var
|
|
105
|
+
RelayModernFragmentSpecResolver.prototype.isLoading = function isLoading() {
|
|
106
|
+
for (var _key3 in this._resolvers) {
|
|
107
|
+
if (this._resolvers.hasOwnProperty(_key3) && this._resolvers[_key3] && this._resolvers[_key3].isLoading()) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
104
113
|
|
|
114
|
+
RelayModernFragmentSpecResolver.prototype.setProps = function setProps(props) {
|
|
105
115
|
var selectors = getSelectorsFromObject(this._context.variables, this._fragments, props);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
resolver = new SelectorResolver(_this3._context.environment, selector, _this3._onChange);
|
|
116
|
+
for (var _key4 in selectors) {
|
|
117
|
+
if (selectors.hasOwnProperty(_key4)) {
|
|
118
|
+
var selector = selectors[_key4];
|
|
119
|
+
var resolver = this._resolvers[_key4];
|
|
120
|
+
if (selector == null) {
|
|
121
|
+
if (resolver != null) {
|
|
122
|
+
resolver.dispose();
|
|
123
|
+
}
|
|
124
|
+
resolver = null;
|
|
125
|
+
} else if (Array.isArray(selector)) {
|
|
126
|
+
if (resolver == null) {
|
|
127
|
+
resolver = new SelectorListResolver(this._context.environment, selector, this._onChange);
|
|
128
|
+
} else {
|
|
129
|
+
require('fbjs/lib/invariant')(resolver instanceof SelectorListResolver, 'RelayModernFragmentSpecResolver: Expected prop `%s` to always be an array.', _key4);
|
|
130
|
+
resolver.setSelectors(selector);
|
|
131
|
+
}
|
|
123
132
|
} else {
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
if (resolver == null) {
|
|
134
|
+
resolver = new SelectorResolver(this._context.environment, selector, this._onChange);
|
|
135
|
+
} else {
|
|
136
|
+
require('fbjs/lib/invariant')(resolver instanceof SelectorResolver, 'RelayModernFragmentSpecResolver: Expected prop `%s` to always be an object.', _key4);
|
|
137
|
+
resolver.setSelector(selector);
|
|
138
|
+
}
|
|
126
139
|
}
|
|
140
|
+
this._resolvers[_key4] = resolver;
|
|
127
141
|
}
|
|
128
|
-
|
|
129
|
-
});
|
|
142
|
+
}
|
|
130
143
|
this._props = props;
|
|
131
144
|
this._stale = true;
|
|
132
145
|
};
|
|
133
146
|
|
|
134
147
|
RelayModernFragmentSpecResolver.prototype.setVariables = function setVariables(variables) {
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
resolver.
|
|
148
|
+
for (var _key5 in this._resolvers) {
|
|
149
|
+
if (this._resolvers.hasOwnProperty(_key5)) {
|
|
150
|
+
var resolver = this._resolvers[_key5];
|
|
151
|
+
if (resolver) {
|
|
152
|
+
resolver.setVariables(variables);
|
|
153
|
+
}
|
|
138
154
|
}
|
|
139
|
-
}
|
|
155
|
+
}
|
|
140
156
|
this._stale = true;
|
|
141
157
|
};
|
|
142
158
|
|
|
@@ -191,6 +207,10 @@ var SelectorResolver = function () {
|
|
|
191
207
|
this.setSelector(selector);
|
|
192
208
|
};
|
|
193
209
|
|
|
210
|
+
SelectorResolver.prototype.isLoading = function isLoading() {
|
|
211
|
+
return this._environment.isSelectorLoading(this._selector);
|
|
212
|
+
};
|
|
213
|
+
|
|
194
214
|
return SelectorResolver;
|
|
195
215
|
}();
|
|
196
216
|
|
|
@@ -200,23 +220,23 @@ var SelectorResolver = function () {
|
|
|
200
220
|
|
|
201
221
|
|
|
202
222
|
var _initialiseProps = function _initialiseProps() {
|
|
203
|
-
var
|
|
223
|
+
var _this3 = this;
|
|
204
224
|
|
|
205
225
|
this._onChange = function (snapshot) {
|
|
206
|
-
|
|
207
|
-
|
|
226
|
+
_this3._data = snapshot.data;
|
|
227
|
+
_this3._callback();
|
|
208
228
|
};
|
|
209
229
|
};
|
|
210
230
|
|
|
211
231
|
var SelectorListResolver = function () {
|
|
212
232
|
function SelectorListResolver(environment, selectors, callback) {
|
|
213
|
-
var
|
|
233
|
+
var _this2 = this;
|
|
214
234
|
|
|
215
235
|
(0, _classCallCheck3['default'])(this, SelectorListResolver);
|
|
216
236
|
|
|
217
237
|
this._onChange = function (data) {
|
|
218
|
-
|
|
219
|
-
|
|
238
|
+
_this2._stale = true;
|
|
239
|
+
_this2._callback();
|
|
220
240
|
};
|
|
221
241
|
|
|
222
242
|
this._callback = callback;
|
|
@@ -277,6 +297,12 @@ var SelectorListResolver = function () {
|
|
|
277
297
|
this._stale = true;
|
|
278
298
|
};
|
|
279
299
|
|
|
300
|
+
SelectorListResolver.prototype.isLoading = function isLoading() {
|
|
301
|
+
return this._resolvers.some(function (resolver) {
|
|
302
|
+
return resolver.isLoading();
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
|
|
280
306
|
return SelectorListResolver;
|
|
281
307
|
}();
|
|
282
308
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayModernGraphQLTag
|
|
10
8
|
*
|
|
@@ -24,13 +22,6 @@ function graphql(strings) {
|
|
|
24
22
|
require('fbjs/lib/invariant')(false, 'graphql: Unexpected invocation at runtime. Either the Babel transform ' + 'was not set up, or it failed to identify this call site. Make sure it ' + 'is being used verbatim as `graphql`.');
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
/**
|
|
28
|
-
* Variant of the `graphql` tag that enables experimental features.
|
|
29
|
-
*/
|
|
30
|
-
graphql.experimental = function (strings) {
|
|
31
|
-
require('fbjs/lib/invariant')(false, 'graphql.experimental: Unexpected invocation at runtime. Either the ' + 'Babel transform was not set up, or it failed to identify this call ' + 'site. Make sure it is being used verbatim as `graphql`.');
|
|
32
|
-
};
|
|
33
|
-
|
|
34
25
|
function getNode(taggedNode) {
|
|
35
26
|
var fn = typeof taggedNode === 'function' ? taggedNode : taggedNode.modern;
|
|
36
27
|
// Support for classic raw nodes (used in test mock)
|
|
@@ -42,18 +33,18 @@ function getNode(taggedNode) {
|
|
|
42
33
|
|
|
43
34
|
function getFragment(taggedNode) {
|
|
44
35
|
var fragment = getNode(taggedNode);
|
|
45
|
-
require('fbjs/lib/invariant')(typeof fragment === 'object' && fragment !== null && fragment.kind === '
|
|
36
|
+
require('fbjs/lib/invariant')(typeof fragment === 'object' && fragment !== null && fragment.kind === require('./RelayConcreteNode').FRAGMENT, 'RelayModernGraphQLTag: Expected a fragment, got `%s`.', JSON.stringify(fragment));
|
|
46
37
|
return fragment;
|
|
47
38
|
}
|
|
48
39
|
|
|
49
|
-
function
|
|
50
|
-
var
|
|
51
|
-
require('fbjs/lib/invariant')(typeof
|
|
52
|
-
return
|
|
40
|
+
function getRequest(taggedNode) {
|
|
41
|
+
var request = getNode(taggedNode);
|
|
42
|
+
require('fbjs/lib/invariant')(typeof request === 'object' && request !== null && (request.kind === require('./RelayConcreteNode').REQUEST || request.kind === require('./RelayConcreteNode').BATCH_REQUEST), 'RelayModernGraphQLTag: Expected an request, got `%s`.', JSON.stringify(request));
|
|
43
|
+
return request;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
46
|
module.exports = {
|
|
56
47
|
getFragment: getFragment,
|
|
57
|
-
|
|
48
|
+
getRequest: getRequest,
|
|
58
49
|
graphql: graphql
|
|
59
50
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayModernOperationSelector
|
|
10
8
|
*
|
|
@@ -25,19 +23,21 @@ var _require2 = require('./RelayStoreUtils'),
|
|
|
25
23
|
* are filtered to exclude variables that do not match defined arguments on the
|
|
26
24
|
* operation, and default values are populated for null values.
|
|
27
25
|
*/
|
|
28
|
-
function createOperationSelector(
|
|
26
|
+
function createOperationSelector(request, variables, operationFromBatch) {
|
|
27
|
+
var operation = operationFromBatch || (request.kind === require('./RelayConcreteNode').BATCH_REQUEST ? request.requests[0].operation : request.operation);
|
|
28
|
+
|
|
29
29
|
var operationVariables = getOperationVariables(operation, variables);
|
|
30
30
|
var dataID = ROOT_ID;
|
|
31
31
|
return {
|
|
32
32
|
fragment: {
|
|
33
33
|
dataID: dataID,
|
|
34
|
-
node:
|
|
34
|
+
node: request.fragment,
|
|
35
35
|
variables: operationVariables
|
|
36
36
|
},
|
|
37
|
-
node:
|
|
37
|
+
node: request,
|
|
38
38
|
root: {
|
|
39
39
|
dataID: dataID,
|
|
40
|
-
node: operation
|
|
40
|
+
node: operation,
|
|
41
41
|
variables: operationVariables
|
|
42
42
|
},
|
|
43
43
|
variables: operationVariables
|
package/lib/RelayModernRecord.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayModernRecord
|
|
10
8
|
*
|
|
@@ -88,11 +86,13 @@ function clone(record) {
|
|
|
88
86
|
* copied on write.
|
|
89
87
|
*/
|
|
90
88
|
function copyFields(source, sink) {
|
|
91
|
-
|
|
92
|
-
if (key
|
|
93
|
-
|
|
89
|
+
for (var key in source) {
|
|
90
|
+
if (source.hasOwnProperty(key)) {
|
|
91
|
+
if (key !== ID_KEY && key !== TYPENAME_KEY) {
|
|
92
|
+
sink[key] = source[key];
|
|
93
|
+
}
|
|
94
94
|
}
|
|
95
|
-
}
|
|
95
|
+
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayModernSelector
|
|
10
8
|
*
|
|
@@ -98,18 +96,21 @@ function getSelectorList(operationVariables, fragment, items) {
|
|
|
98
96
|
*/
|
|
99
97
|
function getSelectorsFromObject(operationVariables, fragments, object) {
|
|
100
98
|
var selectors = {};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
for (var _key in fragments) {
|
|
100
|
+
if (fragments.hasOwnProperty(_key)) {
|
|
101
|
+
var fragment = fragments[_key];
|
|
102
|
+
var item = object[_key];
|
|
103
|
+
if (item == null) {
|
|
104
|
+
selectors[_key] = item;
|
|
105
|
+
} else if (fragment.metadata && fragment.metadata.plural === true) {
|
|
106
|
+
require('fbjs/lib/invariant')(Array.isArray(item), 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key, JSON.stringify(item), fragment.name);
|
|
107
|
+
selectors[_key] = getSelectorList(operationVariables, fragment, item);
|
|
108
|
+
} else {
|
|
109
|
+
require('fbjs/lib/invariant')(!Array.isArray(item), 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key, JSON.stringify(item), fragment.name);
|
|
110
|
+
selectors[_key] = getSelector(operationVariables, fragment, item);
|
|
111
|
+
}
|
|
111
112
|
}
|
|
112
|
-
}
|
|
113
|
+
}
|
|
113
114
|
return selectors;
|
|
114
115
|
}
|
|
115
116
|
|
|
@@ -124,18 +125,21 @@ function getSelectorsFromObject(operationVariables, fragments, object) {
|
|
|
124
125
|
*/
|
|
125
126
|
function getDataIDsFromObject(fragments, object) {
|
|
126
127
|
var ids = {};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
for (var _key2 in fragments) {
|
|
129
|
+
if (fragments.hasOwnProperty(_key2)) {
|
|
130
|
+
var fragment = fragments[_key2];
|
|
131
|
+
var item = object[_key2];
|
|
132
|
+
if (item == null) {
|
|
133
|
+
ids[_key2] = item;
|
|
134
|
+
} else if (fragment.metadata && fragment.metadata.plural === true) {
|
|
135
|
+
require('fbjs/lib/invariant')(Array.isArray(item), 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key2, JSON.stringify(item), fragment.name);
|
|
136
|
+
ids[_key2] = getDataIDs(fragment, item);
|
|
137
|
+
} else {
|
|
138
|
+
require('fbjs/lib/invariant')(!Array.isArray(item), 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key2, JSON.stringify(item), fragment.name);
|
|
139
|
+
ids[_key2] = getDataID(fragment, item);
|
|
140
|
+
}
|
|
137
141
|
}
|
|
138
|
-
}
|
|
142
|
+
}
|
|
139
143
|
return ids;
|
|
140
144
|
}
|
|
141
145
|
|
|
@@ -179,28 +183,35 @@ function getDataID(fragment, item) {
|
|
|
179
183
|
*/
|
|
180
184
|
function getVariablesFromObject(operationVariables, fragments, object) {
|
|
181
185
|
var variables = {};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
|
|
186
|
+
for (var _key3 in fragments) {
|
|
187
|
+
if (fragments.hasOwnProperty(_key3)) {
|
|
188
|
+
var _ret = function () {
|
|
189
|
+
var fragment = fragments[_key3];
|
|
190
|
+
var item = object[_key3];
|
|
191
|
+
if (item == null) {
|
|
192
|
+
return 'continue';
|
|
193
|
+
} else if (fragment.metadata && fragment.metadata.plural === true) {
|
|
194
|
+
require('fbjs/lib/invariant')(Array.isArray(item), 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key3, JSON.stringify(item), fragment.name);
|
|
195
|
+
item.forEach(function (value) {
|
|
196
|
+
if (value != null) {
|
|
197
|
+
var itemVariables = getVariables(operationVariables, fragment, value);
|
|
198
|
+
if (itemVariables) {
|
|
199
|
+
Object.assign(variables, itemVariables);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
require('fbjs/lib/invariant')(!Array.isArray(item), 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key3, JSON.stringify(item), fragment.name);
|
|
205
|
+
var itemVariables = getVariables(operationVariables, fragment, item);
|
|
191
206
|
if (itemVariables) {
|
|
192
207
|
Object.assign(variables, itemVariables);
|
|
193
208
|
}
|
|
194
209
|
}
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var itemVariables = getVariables(operationVariables, fragment, item);
|
|
199
|
-
if (itemVariables) {
|
|
200
|
-
Object.assign(variables, itemVariables);
|
|
201
|
-
}
|
|
210
|
+
}();
|
|
211
|
+
|
|
212
|
+
if (_ret === 'continue') continue;
|
|
202
213
|
}
|
|
203
|
-
}
|
|
214
|
+
}
|
|
204
215
|
return variables;
|
|
205
216
|
}
|
|
206
217
|
|
package/lib/RelayNetwork.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayNetwork
|
|
10
8
|
*
|
|
@@ -13,7 +11,7 @@
|
|
|
13
11
|
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
|
-
var _require = require('./
|
|
14
|
+
var _require = require('./ConvertToExecuteFunction'),
|
|
17
15
|
convertFetch = _require.convertFetch,
|
|
18
16
|
convertSubscribe = _require.convertSubscribe;
|
|
19
17
|
|
|
@@ -26,24 +24,24 @@ function create(fetchFn, subscribeFn) {
|
|
|
26
24
|
var observeFetch = convertFetch(fetchFn);
|
|
27
25
|
var observeSubscribe = subscribeFn ? convertSubscribe(subscribeFn) : undefined;
|
|
28
26
|
|
|
29
|
-
function
|
|
30
|
-
if (
|
|
27
|
+
function execute(request, variables, cacheConfig, uploadables) {
|
|
28
|
+
if (request.operationKind === 'subscription') {
|
|
31
29
|
require('fbjs/lib/invariant')(observeSubscribe, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.');
|
|
32
30
|
|
|
33
31
|
require('fbjs/lib/invariant')(!uploadables, 'RelayNetwork: Cannot provide uploadables while subscribing.');
|
|
34
|
-
return observeSubscribe(
|
|
32
|
+
return observeSubscribe(request, variables, cacheConfig);
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
var pollInterval = cacheConfig.poll;
|
|
38
36
|
if (pollInterval != null) {
|
|
39
37
|
require('fbjs/lib/invariant')(!uploadables, 'RelayNetwork: Cannot provide uploadables while polling.');
|
|
40
|
-
return observeFetch(
|
|
38
|
+
return observeFetch(request, variables, { force: true }).poll(pollInterval);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
return observeFetch(
|
|
41
|
+
return observeFetch(request, variables, cacheConfig, uploadables);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
return {
|
|
44
|
+
return { execute: execute };
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
module.exports = { create: create };
|
package/lib/RelayNetworkDebug.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
* @providesModule RelayNetworkDebug
|
|
10
7
|
*
|
|
11
8
|
* @format
|
|
12
9
|
*/
|
|
@@ -76,7 +73,6 @@ function createDebuggableFromRequest(type, request, graphiqlPrinter) {
|
|
|
76
73
|
type: type,
|
|
77
74
|
promise: request.getPromise(),
|
|
78
75
|
logResult: function logResult(error, response) {
|
|
79
|
-
/* eslint-disable no-console-disallow */
|
|
80
76
|
var requestSize = formatSize(require('fbjs/lib/xhrSimpleDataSerializer')({
|
|
81
77
|
q: request.getQueryString(),
|
|
82
78
|
query_params: request.getVariables()
|
|
@@ -98,12 +94,13 @@ function createDebuggableFromRequest(type, request, graphiqlPrinter) {
|
|
|
98
94
|
console.groupEnd();
|
|
99
95
|
|
|
100
96
|
if (Object.keys(requestVariables).length > 0) {
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
101
98
|
console.log('Request Variables\n', request.getVariables());
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
error && console.error(error);
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
105
103
|
response && console.log(response);
|
|
106
|
-
/* eslint-enable no-console-disallow */
|
|
107
104
|
}
|
|
108
105
|
};
|
|
109
106
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayNetworkLogger
|
|
10
8
|
*
|