relay-runtime 0.0.0-main-f0fc1eea → 0.0.0-main-c454f22f
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/index.js +1 -1
- package/index.js.flow +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +7 -0
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +7 -0
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/store/RelayModernSelector.js +7 -2
- package/lib/store/RelayReader.js +118 -24
- package/lib/store/RelayStoreSubscriptions.js +2 -0
- package/lib/store/RelayStoreUtils.js +1 -0
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +2 -0
- package/mutations/RelayRecordSourceProxy.js.flow +12 -1
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +12 -1
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/package.json +1 -1
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/RelayModernSelector.js.flow +13 -2
- package/store/RelayReader.js.flow +139 -14
- package/store/RelayStoreSubscriptions.js.flow +2 -0
- package/store/RelayStoreTypes.js.flow +22 -1
- package/store/RelayStoreUtils.js.flow +1 -0
- package/util/ReaderNode.js.flow +8 -0
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +5 -1
package/index.js
CHANGED
package/index.js.flow
CHANGED
|
@@ -179,8 +179,8 @@ export type {
|
|
|
179
179
|
NormalizationSplitOperation,
|
|
180
180
|
NormalizationStream,
|
|
181
181
|
NormalizationTypeDiscriminator,
|
|
182
|
+
NormalizationOperation,
|
|
182
183
|
} from './util/NormalizationNode';
|
|
183
|
-
export type {NormalizationOperation} from './util/NormalizationNode';
|
|
184
184
|
export type {
|
|
185
185
|
ReaderArgument,
|
|
186
186
|
ReaderArgumentDefinition,
|
|
@@ -20,6 +20,9 @@ var _require2 = require('../store/RelayStoreUtils'),
|
|
|
20
20
|
ROOT_ID = _require2.ROOT_ID,
|
|
21
21
|
ROOT_TYPE = _require2.ROOT_TYPE;
|
|
22
22
|
|
|
23
|
+
var _require3 = require('./readUpdatableQuery_EXPERIMENTAL'),
|
|
24
|
+
_readUpdatableQuery_EXPERIMENTAL = _require3.readUpdatableQuery_EXPERIMENTAL;
|
|
25
|
+
|
|
23
26
|
var RelayRecordProxy = require('./RelayRecordProxy');
|
|
24
27
|
|
|
25
28
|
var invariant = require('invariant');
|
|
@@ -132,6 +135,10 @@ var RelayRecordSourceProxy = /*#__PURE__*/function () {
|
|
|
132
135
|
return this._idsMarkedForInvalidation;
|
|
133
136
|
};
|
|
134
137
|
|
|
138
|
+
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
139
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
140
|
+
};
|
|
141
|
+
|
|
135
142
|
return RelayRecordSourceProxy;
|
|
136
143
|
}();
|
|
137
144
|
|
|
@@ -14,6 +14,9 @@ var _require = require('../store/RelayStoreUtils'),
|
|
|
14
14
|
ROOT_TYPE = _require.ROOT_TYPE,
|
|
15
15
|
getStorageKey = _require.getStorageKey;
|
|
16
16
|
|
|
17
|
+
var _require2 = require('./readUpdatableQuery_EXPERIMENTAL'),
|
|
18
|
+
_readUpdatableQuery_EXPERIMENTAL = _require2.readUpdatableQuery_EXPERIMENTAL;
|
|
19
|
+
|
|
17
20
|
var invariant = require('invariant');
|
|
18
21
|
/**
|
|
19
22
|
* @internal
|
|
@@ -92,6 +95,10 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
|
92
95
|
this.__recordSource.invalidateStore();
|
|
93
96
|
};
|
|
94
97
|
|
|
98
|
+
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
99
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
100
|
+
};
|
|
101
|
+
|
|
95
102
|
return RelayRecordSourceSelectorProxy;
|
|
96
103
|
}();
|
|
97
104
|
|
|
@@ -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,6 +14,7 @@ var _require = require('./RelayConcreteVariables'),
|
|
|
14
14
|
getFragmentVariables = _require.getFragmentVariables;
|
|
15
15
|
|
|
16
16
|
var _require2 = require('./RelayStoreUtils'),
|
|
17
|
+
CLIENT_EDGE_TRAVERSAL_PATH = _require2.CLIENT_EDGE_TRAVERSAL_PATH,
|
|
17
18
|
FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
|
|
18
19
|
FRAGMENTS_KEY = _require2.FRAGMENTS_KEY,
|
|
19
20
|
ID_KEY = _require2.ID_KEY,
|
|
@@ -61,12 +62,14 @@ function getSingularSelector(fragment, item) {
|
|
|
61
62
|
var fragments = item[FRAGMENTS_KEY];
|
|
62
63
|
var mixedOwner = item[FRAGMENT_OWNER_KEY];
|
|
63
64
|
var isWithinUnmatchedTypeRefinement = item[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] === true;
|
|
65
|
+
var mixedClientEdgeTraversalPath = item[CLIENT_EDGE_TRAVERSAL_PATH];
|
|
64
66
|
|
|
65
|
-
if (typeof dataID === 'string' && typeof fragments === 'object' && fragments !== null && typeof fragments[fragment.name] === 'object' && fragments[fragment.name] !== null && typeof mixedOwner === 'object' && mixedOwner !== null) {
|
|
67
|
+
if (typeof dataID === 'string' && typeof fragments === 'object' && fragments !== null && typeof fragments[fragment.name] === 'object' && fragments[fragment.name] !== null && typeof mixedOwner === 'object' && mixedOwner !== null && (mixedClientEdgeTraversalPath == null || Array.isArray(mixedClientEdgeTraversalPath))) {
|
|
66
68
|
var owner = mixedOwner;
|
|
69
|
+
var clientEdgeTraversalPath = mixedClientEdgeTraversalPath;
|
|
67
70
|
var argumentVariables = fragments[fragment.name];
|
|
68
71
|
var fragmentVariables = getFragmentVariables(fragment, owner.variables, argumentVariables);
|
|
69
|
-
return createReaderSelector(fragment, dataID, fragmentVariables, owner, isWithinUnmatchedTypeRefinement);
|
|
72
|
+
return createReaderSelector(fragment, dataID, fragmentVariables, owner, isWithinUnmatchedTypeRefinement, clientEdgeTraversalPath);
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -296,10 +299,12 @@ function areEqualSelectors(thisSelector, thatSelector) {
|
|
|
296
299
|
|
|
297
300
|
function createReaderSelector(fragment, dataID, variables, request) {
|
|
298
301
|
var isWithinUnmatchedTypeRefinement = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
302
|
+
var clientEdgeTraversalPath = arguments.length > 5 ? arguments[5] : undefined;
|
|
299
303
|
return {
|
|
300
304
|
kind: 'SingularReaderSelector',
|
|
301
305
|
dataID: dataID,
|
|
302
306
|
isWithinUnmatchedTypeRefinement: isWithinUnmatchedTypeRefinement,
|
|
307
|
+
clientEdgeTraversalPath: clientEdgeTraversalPath !== null && clientEdgeTraversalPath !== void 0 ? clientEdgeTraversalPath : null,
|
|
303
308
|
node: fragment,
|
|
304
309
|
variables: variables,
|
|
305
310
|
owner: request
|
package/lib/store/RelayReader.js
CHANGED
|
@@ -14,8 +14,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
16
|
|
|
17
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
+
|
|
17
19
|
var _require = require('../util/RelayConcreteNode'),
|
|
18
20
|
ACTOR_CHANGE = _require.ACTOR_CHANGE,
|
|
21
|
+
CLIENT_EDGE = _require.CLIENT_EDGE,
|
|
19
22
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
20
23
|
CONDITION = _require.CONDITION,
|
|
21
24
|
DEFER = _require.DEFER,
|
|
@@ -40,6 +43,7 @@ var _require2 = require('./RelayStoreReactFlightUtils'),
|
|
|
40
43
|
getReactFlightClientResponse = _require2.getReactFlightClientResponse;
|
|
41
44
|
|
|
42
45
|
var _require3 = require('./RelayStoreUtils'),
|
|
46
|
+
CLIENT_EDGE_TRAVERSAL_PATH = _require3.CLIENT_EDGE_TRAVERSAL_PATH,
|
|
43
47
|
FRAGMENT_OWNER_KEY = _require3.FRAGMENT_OWNER_KEY,
|
|
44
48
|
FRAGMENT_PROP_NAME_KEY = _require3.FRAGMENT_PROP_NAME_KEY,
|
|
45
49
|
FRAGMENTS_KEY = _require3.FRAGMENTS_KEY,
|
|
@@ -73,6 +77,10 @@ function read(recordSource, selector, resolverCache) {
|
|
|
73
77
|
|
|
74
78
|
var RelayReader = /*#__PURE__*/function () {
|
|
75
79
|
function RelayReader(recordSource, selector, resolverCache) {
|
|
80
|
+
var _selector$clientEdgeT;
|
|
81
|
+
|
|
82
|
+
this._clientEdgeTraversalPath = RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_selector$clientEdgeT = selector.clientEdgeTraversalPath) === null || _selector$clientEdgeT === void 0 ? void 0 : _selector$clientEdgeT.length) ? (0, _toConsumableArray2["default"])(selector.clientEdgeTraversalPath) : [];
|
|
83
|
+
this._missingClientEdges = [];
|
|
76
84
|
this._isMissingData = false;
|
|
77
85
|
this._isWithinUnmatchedTypeRefinement = false;
|
|
78
86
|
this._missingRequiredFields = null;
|
|
@@ -152,12 +160,30 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
152
160
|
return {
|
|
153
161
|
data: data,
|
|
154
162
|
isMissingData: this._isMissingData && isDataExpectedToBePresent,
|
|
163
|
+
missingClientEdges: RelayFeatureFlags.ENABLE_CLIENT_EDGES && this._missingClientEdges.length ? this._missingClientEdges : null,
|
|
155
164
|
seenRecords: this._seenRecords,
|
|
156
165
|
selector: this._selector,
|
|
157
166
|
missingRequiredFields: this._missingRequiredFields
|
|
158
167
|
};
|
|
159
168
|
};
|
|
160
169
|
|
|
170
|
+
_proto._markDataAsMissing = function _markDataAsMissing() {
|
|
171
|
+
this._isMissingData = true;
|
|
172
|
+
|
|
173
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && this._clientEdgeTraversalPath.length) {
|
|
174
|
+
var top = this._clientEdgeTraversalPath[this._clientEdgeTraversalPath.length - 1]; // Top can be null if we've traversed past a client edge into an ordinary
|
|
175
|
+
// client extension field; we never want to fetch in response to missing
|
|
176
|
+
// data off of a client extension field.
|
|
177
|
+
|
|
178
|
+
if (top !== null) {
|
|
179
|
+
this._missingClientEdges.push({
|
|
180
|
+
request: top.readerClientEdge.operation,
|
|
181
|
+
clientEdgeDestinationID: top.clientEdgeDestinationID
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
161
187
|
_proto._traverse = function _traverse(node, dataID, prevData) {
|
|
162
188
|
var record = this._recordSource.get(dataID);
|
|
163
189
|
|
|
@@ -165,7 +191,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
165
191
|
|
|
166
192
|
if (record == null) {
|
|
167
193
|
if (record === undefined) {
|
|
168
|
-
this.
|
|
194
|
+
this._markDataAsMissing();
|
|
169
195
|
}
|
|
170
196
|
|
|
171
197
|
return record;
|
|
@@ -321,7 +347,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
321
347
|
this._isMissingData = parentIsMissingData;
|
|
322
348
|
} else if (implementsInterface == null) {
|
|
323
349
|
// Don't know if the type implements the interface or not
|
|
324
|
-
this.
|
|
350
|
+
this._markDataAsMissing();
|
|
325
351
|
}
|
|
326
352
|
}
|
|
327
353
|
|
|
@@ -358,10 +384,22 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
358
384
|
case CLIENT_EXTENSION:
|
|
359
385
|
{
|
|
360
386
|
var isMissingData = this._isMissingData;
|
|
387
|
+
var alreadyMissingClientEdges = this._missingClientEdges.length;
|
|
388
|
+
|
|
389
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
|
|
390
|
+
this._clientEdgeTraversalPath.push(null);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data); // The only case where we want to suspend due to missing data off of
|
|
394
|
+
// a client extension is if we reached a client edge that we might be
|
|
395
|
+
// able to fetch:
|
|
361
396
|
|
|
362
|
-
var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data);
|
|
363
397
|
|
|
364
|
-
this._isMissingData = isMissingData;
|
|
398
|
+
this._isMissingData = isMissingData || this._missingClientEdges.length > alreadyMissingClientEdges;
|
|
399
|
+
|
|
400
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
|
|
401
|
+
this._clientEdgeTraversalPath.pop();
|
|
402
|
+
}
|
|
365
403
|
|
|
366
404
|
if (!_hasExpectedData2) {
|
|
367
405
|
return false;
|
|
@@ -395,6 +433,15 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
395
433
|
|
|
396
434
|
break;
|
|
397
435
|
|
|
436
|
+
case CLIENT_EDGE:
|
|
437
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
|
|
438
|
+
this._readClientEdge(selection, record, data);
|
|
439
|
+
} else {
|
|
440
|
+
throw new Error('Client edges are not yet supported.');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
break;
|
|
444
|
+
|
|
398
445
|
default:
|
|
399
446
|
selection;
|
|
400
447
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
@@ -434,6 +481,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
434
481
|
_proto._readResolverField = function _readResolverField(field, record, data) {
|
|
435
482
|
var _this = this;
|
|
436
483
|
|
|
484
|
+
var _field$alias;
|
|
485
|
+
|
|
437
486
|
var resolverModule = field.resolverModule,
|
|
438
487
|
fragment = field.fragment;
|
|
439
488
|
var storageKey = getStorageKey(field, this._variables);
|
|
@@ -501,14 +550,53 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
501
550
|
this._seenRecords.add(seenRecord);
|
|
502
551
|
}
|
|
503
552
|
|
|
504
|
-
|
|
505
|
-
|
|
553
|
+
var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
|
|
554
|
+
data[applicationName] = result;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
_proto._readClientEdge = function _readClientEdge(field, record, data) {
|
|
558
|
+
var _backingField$alias;
|
|
559
|
+
|
|
560
|
+
var backingField = field.backingField; // Because ReaderClientExtension doesn't have `alias` or `name` and so I don't know
|
|
561
|
+
// how to get its applicationName or storageKey yet:
|
|
562
|
+
|
|
563
|
+
!(backingField.kind !== 'ClientExtension') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Client extension client edges are not yet implemented.') : invariant(false) : void 0;
|
|
564
|
+
var applicationName = (_backingField$alias = backingField.alias) !== null && _backingField$alias !== void 0 ? _backingField$alias : backingField.name;
|
|
565
|
+
var backingFieldData = {};
|
|
566
|
+
|
|
567
|
+
this._traverseSelections([backingField], record, backingFieldData);
|
|
568
|
+
|
|
569
|
+
var destinationDataID = backingFieldData[applicationName];
|
|
570
|
+
|
|
571
|
+
if (destinationDataID == null) {
|
|
572
|
+
data[applicationName] = destinationDataID;
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
!(typeof destinationDataID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Plural client edges not are yet implemented') : invariant(false) : void 0; // FIXME support plural
|
|
577
|
+
// Not wrapping the push/pop in a try/finally because if we throw, the
|
|
578
|
+
// Reader object is not usable after that anyway.
|
|
579
|
+
|
|
580
|
+
this._clientEdgeTraversalPath.push({
|
|
581
|
+
readerClientEdge: field,
|
|
582
|
+
clientEdgeDestinationID: destinationDataID
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
var prevData = data[applicationName];
|
|
586
|
+
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
587
|
+
|
|
588
|
+
var value = this._traverse(field.linkedField, destinationDataID, // $FlowFixMe[incompatible-variance]
|
|
589
|
+
prevData);
|
|
590
|
+
|
|
591
|
+
data[applicationName] = value;
|
|
592
|
+
|
|
593
|
+
this._clientEdgeTraversalPath.pop();
|
|
506
594
|
};
|
|
507
595
|
|
|
508
596
|
_proto._readFlightField = function _readFlightField(field, record, data) {
|
|
509
|
-
var _field$
|
|
597
|
+
var _field$alias2;
|
|
510
598
|
|
|
511
|
-
var applicationName = (_field$
|
|
599
|
+
var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
|
|
512
600
|
var storageKey = getStorageKey(field, this._variables);
|
|
513
601
|
var reactFlightClientResponseRecordID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
514
602
|
|
|
@@ -516,7 +604,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
516
604
|
data[applicationName] = reactFlightClientResponseRecordID;
|
|
517
605
|
|
|
518
606
|
if (reactFlightClientResponseRecordID === undefined) {
|
|
519
|
-
this.
|
|
607
|
+
this._markDataAsMissing();
|
|
520
608
|
}
|
|
521
609
|
|
|
522
610
|
return reactFlightClientResponseRecordID;
|
|
@@ -530,7 +618,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
530
618
|
data[applicationName] = reactFlightClientResponseRecord;
|
|
531
619
|
|
|
532
620
|
if (reactFlightClientResponseRecord === undefined) {
|
|
533
|
-
this.
|
|
621
|
+
this._markDataAsMissing();
|
|
534
622
|
}
|
|
535
623
|
|
|
536
624
|
return reactFlightClientResponseRecord;
|
|
@@ -542,14 +630,14 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
542
630
|
};
|
|
543
631
|
|
|
544
632
|
_proto._readScalar = function _readScalar(field, record, data) {
|
|
545
|
-
var _field$
|
|
633
|
+
var _field$alias3;
|
|
546
634
|
|
|
547
|
-
var applicationName = (_field$
|
|
635
|
+
var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
|
|
548
636
|
var storageKey = getStorageKey(field, this._variables);
|
|
549
637
|
var value = RelayModernRecord.getValue(record, storageKey);
|
|
550
638
|
|
|
551
639
|
if (value === undefined) {
|
|
552
|
-
this.
|
|
640
|
+
this._markDataAsMissing();
|
|
553
641
|
}
|
|
554
642
|
|
|
555
643
|
data[applicationName] = value;
|
|
@@ -557,9 +645,9 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
557
645
|
};
|
|
558
646
|
|
|
559
647
|
_proto._readLink = function _readLink(field, record, data) {
|
|
560
|
-
var _field$
|
|
648
|
+
var _field$alias4;
|
|
561
649
|
|
|
562
|
-
var applicationName = (_field$
|
|
650
|
+
var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
|
|
563
651
|
var storageKey = getStorageKey(field, this._variables);
|
|
564
652
|
var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
565
653
|
|
|
@@ -567,7 +655,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
567
655
|
data[applicationName] = linkedID;
|
|
568
656
|
|
|
569
657
|
if (linkedID === undefined) {
|
|
570
|
-
this.
|
|
658
|
+
this._markDataAsMissing();
|
|
571
659
|
}
|
|
572
660
|
|
|
573
661
|
return linkedID;
|
|
@@ -583,9 +671,9 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
583
671
|
};
|
|
584
672
|
|
|
585
673
|
_proto._readActorChange = function _readActorChange(field, record, data) {
|
|
586
|
-
var _field$
|
|
674
|
+
var _field$alias5;
|
|
587
675
|
|
|
588
|
-
var applicationName = (_field$
|
|
676
|
+
var applicationName = (_field$alias5 = field.alias) !== null && _field$alias5 !== void 0 ? _field$alias5 : field.name;
|
|
589
677
|
var storageKey = getStorageKey(field, this._variables);
|
|
590
678
|
var externalRef = RelayModernRecord.getActorLinkedRecordID(record, storageKey);
|
|
591
679
|
|
|
@@ -593,7 +681,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
593
681
|
data[applicationName] = externalRef;
|
|
594
682
|
|
|
595
683
|
if (externalRef === undefined) {
|
|
596
|
-
this.
|
|
684
|
+
this._markDataAsMissing();
|
|
597
685
|
}
|
|
598
686
|
|
|
599
687
|
return data[applicationName];
|
|
@@ -617,9 +705,9 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
617
705
|
_proto._readPluralLink = function _readPluralLink(field, record, data) {
|
|
618
706
|
var _this2 = this;
|
|
619
707
|
|
|
620
|
-
var _field$
|
|
708
|
+
var _field$alias6;
|
|
621
709
|
|
|
622
|
-
var applicationName = (_field$
|
|
710
|
+
var applicationName = (_field$alias6 = field.alias) !== null && _field$alias6 !== void 0 ? _field$alias6 : field.name;
|
|
623
711
|
var storageKey = getStorageKey(field, this._variables);
|
|
624
712
|
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
625
713
|
|
|
@@ -627,7 +715,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
627
715
|
data[applicationName] = linkedIDs;
|
|
628
716
|
|
|
629
717
|
if (linkedIDs === undefined) {
|
|
630
|
-
this.
|
|
718
|
+
this._markDataAsMissing();
|
|
631
719
|
}
|
|
632
720
|
|
|
633
721
|
return linkedIDs;
|
|
@@ -639,7 +727,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
639
727
|
linkedIDs.forEach(function (linkedID, nextIndex) {
|
|
640
728
|
if (linkedID == null) {
|
|
641
729
|
if (linkedID === undefined) {
|
|
642
|
-
_this2.
|
|
730
|
+
_this2._markDataAsMissing();
|
|
643
731
|
} // $FlowFixMe[cannot-write]
|
|
644
732
|
|
|
645
733
|
|
|
@@ -670,7 +758,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
670
758
|
|
|
671
759
|
if (component == null) {
|
|
672
760
|
if (component === undefined) {
|
|
673
|
-
this.
|
|
761
|
+
this._markDataAsMissing();
|
|
674
762
|
}
|
|
675
763
|
|
|
676
764
|
return;
|
|
@@ -708,6 +796,12 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
708
796
|
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
|
|
709
797
|
data[FRAGMENT_OWNER_KEY] = this._owner;
|
|
710
798
|
data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
|
|
799
|
+
|
|
800
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
|
|
801
|
+
if (this._clientEdgeTraversalPath.length > 0 && this._clientEdgeTraversalPath[this._clientEdgeTraversalPath.length - 1] !== null) {
|
|
802
|
+
data[CLIENT_EDGE_TRAVERSAL_PATH] = (0, _toConsumableArray2["default"])(this._clientEdgeTraversalPath);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
711
805
|
};
|
|
712
806
|
|
|
713
807
|
_proto._createInlineDataOrResolverFragmentPointer = function _createInlineDataOrResolverFragmentPointer(fragmentSpreadOrFragment, record, data) {
|
|
@@ -93,6 +93,7 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
|
|
|
93
93
|
subscription.snapshot = {
|
|
94
94
|
data: subscription.snapshot.data,
|
|
95
95
|
isMissingData: backup.isMissingData,
|
|
96
|
+
missingClientEdges: backup.missingClientEdges,
|
|
96
97
|
seenRecords: backup.seenRecords,
|
|
97
98
|
selector: backup.selector,
|
|
98
99
|
missingRequiredFields: backup.missingRequiredFields
|
|
@@ -142,6 +143,7 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
|
|
|
142
143
|
nextSnapshot = {
|
|
143
144
|
data: nextData,
|
|
144
145
|
isMissingData: nextSnapshot.isMissingData,
|
|
146
|
+
missingClientEdges: nextSnapshot.missingClientEdges,
|
|
145
147
|
seenRecords: nextSnapshot.seenRecords,
|
|
146
148
|
selector: nextSnapshot.selector,
|
|
147
149
|
missingRequiredFields: nextSnapshot.missingRequiredFields
|
|
@@ -193,6 +193,7 @@ function getModuleOperationKey(documentName) {
|
|
|
193
193
|
|
|
194
194
|
var RelayStoreUtils = {
|
|
195
195
|
ACTOR_IDENTIFIER_KEY: '__actorIdentifier',
|
|
196
|
+
CLIENT_EDGE_TRAVERSAL_PATH: '__clientEdgeTraversalPath',
|
|
196
197
|
FRAGMENTS_KEY: '__fragments',
|
|
197
198
|
FRAGMENT_OWNER_KEY: '__fragmentOwner',
|
|
198
199
|
FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
|