@apollo/client 3.12.0-rc.0 → 3.12.0-rc.2
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/.changeset/brown-readers-smash.md +5 -0
- package/.changeset/gorgeous-zebras-confess.md +5 -0
- package/.changeset/itchy-penguins-worry.md +5 -0
- package/.changeset/long-zoos-ring.md +5 -0
- package/.changeset/mean-bottles-travel.md +5 -0
- package/.changeset/nice-countries-share.md +5 -0
- package/.changeset/pre.json +10 -1
- package/.changeset/slimy-points-end.md +5 -0
- package/.changeset/small-bears-confess.md +5 -0
- package/.changeset/wicked-pans-appear.md +5 -0
- package/CHANGELOG.md +28 -0
- package/apollo-client.cjs +128 -138
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +98 -119
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +98 -119
- package/core/core.cjs +103 -127
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +103 -127
- package/core/masking.js +112 -136
- package/core/masking.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/masking/internal/types.d.ts +2 -2
- package/masking/internal/types.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/hooks.cjs +25 -11
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +25 -11
- package/react/hooks/useFragment.d.ts +1 -1
- package/react/hooks/useFragment.js +33 -19
- package/react/hooks/useFragment.js.map +1 -1
- package/react/internal/internal.cjs +1 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
package/cache/cache.cjs
CHANGED
|
@@ -126,6 +126,8 @@ function directiveIsNonreactive(dir) {
|
|
|
126
126
|
return dir.name.value === "nonreactive";
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
var MapImpl = utilities.canUseWeakMap ? WeakMap : Map;
|
|
130
|
+
var SetImpl = utilities.canUseWeakSet ? WeakSet : Set;
|
|
129
131
|
var disableWarningsSlot = new optimism.Slot();
|
|
130
132
|
function maskFragment(data, document, cache, fragmentName) {
|
|
131
133
|
if (!cache.fragmentMatches) {
|
|
@@ -149,158 +151,135 @@ function maskFragment(data, document, cache, fragmentName) {
|
|
|
149
151
|
if (equal.equal(data, {})) {
|
|
150
152
|
return data;
|
|
151
153
|
}
|
|
152
|
-
|
|
154
|
+
return maskDefinition(data, fragment.selectionSet, {
|
|
153
155
|
operationType: "fragment",
|
|
154
156
|
operationName: fragment.name.value,
|
|
155
157
|
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(document)),
|
|
156
158
|
cache: cache,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
mutableTargets: new MapImpl(),
|
|
160
|
+
knownChanged: new SetImpl(),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function maskDefinition(data, selectionSet, context) {
|
|
164
|
+
return disableWarningsSlot.withValue(true, function () {
|
|
165
|
+
var masked = maskSelectionSet(data, selectionSet, context, false);
|
|
166
|
+
if (Object.isFrozen(data)) {
|
|
167
|
+
utilities.maybeDeepFreeze(masked);
|
|
168
|
+
}
|
|
169
|
+
return masked;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function getMutableTarget(data, mutableTargets) {
|
|
173
|
+
if (mutableTargets.has(data)) {
|
|
174
|
+
return mutableTargets.get(data);
|
|
161
175
|
}
|
|
162
|
-
|
|
176
|
+
var mutableTarget = Array.isArray(data) ? [] : Object.create(null);
|
|
177
|
+
mutableTargets.set(data, mutableTarget);
|
|
178
|
+
return mutableTarget;
|
|
163
179
|
}
|
|
164
|
-
function maskSelectionSet(data, selectionSet, context, path) {
|
|
180
|
+
function maskSelectionSet(data, selectionSet, context, migration, path) {
|
|
181
|
+
var _a;
|
|
182
|
+
var knownChanged = context.knownChanged;
|
|
165
183
|
if (Array.isArray(data)) {
|
|
166
|
-
var
|
|
167
|
-
var
|
|
184
|
+
var target = getMutableTarget(data, context.mutableTargets);
|
|
185
|
+
for (var _i = 0, _b = Array.from(data.entries()); _i < _b.length; _i++) {
|
|
186
|
+
var _c = _b[_i], index = _c[0], item = _c[1];
|
|
168
187
|
if (item === null) {
|
|
169
|
-
|
|
188
|
+
target[index] = null;
|
|
189
|
+
continue;
|
|
170
190
|
}
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
175
|
-
return [changed_1 ? masked : data, changed_1];
|
|
176
|
-
}
|
|
177
|
-
var result = selectionSet.selections.reduce(function (_a, selection) {
|
|
178
|
-
var memo = _a[0], changed = _a[1];
|
|
179
|
-
switch (selection.kind) {
|
|
180
|
-
case graphql.Kind.FIELD: {
|
|
181
|
-
var keyName = utilities.resultKeyNameFromField(selection);
|
|
182
|
-
var childSelectionSet = selection.selectionSet;
|
|
183
|
-
memo[keyName] = data[keyName];
|
|
184
|
-
if (memo[keyName] === void 0) {
|
|
185
|
-
delete memo[keyName];
|
|
186
|
-
}
|
|
187
|
-
if (keyName in memo && childSelectionSet && data[keyName] !== null) {
|
|
188
|
-
var _b = maskSelectionSet(data[keyName], childSelectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0), masked = _b[0], childChanged = _b[1];
|
|
189
|
-
if (childChanged ||
|
|
190
|
-
Object.keys(masked).length !== Object.keys(data[keyName]).length) {
|
|
191
|
-
memo[keyName] = masked;
|
|
192
|
-
changed = true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return [memo, changed];
|
|
196
|
-
}
|
|
197
|
-
case graphql.Kind.INLINE_FRAGMENT: {
|
|
198
|
-
if (selection.typeCondition &&
|
|
199
|
-
!context.cache.fragmentMatches(selection, data.__typename)) {
|
|
200
|
-
return [memo, changed];
|
|
201
|
-
}
|
|
202
|
-
var _c = maskSelectionSet(data, selection.selectionSet, context, path), fragmentData = _c[0], childChanged = _c[1];
|
|
203
|
-
return [
|
|
204
|
-
tslib.__assign(tslib.__assign({}, memo), fragmentData),
|
|
205
|
-
changed || childChanged,
|
|
206
|
-
];
|
|
207
|
-
}
|
|
208
|
-
case graphql.Kind.FRAGMENT_SPREAD: {
|
|
209
|
-
var fragmentName = selection.name.value;
|
|
210
|
-
var fragment = context.fragmentMap[fragmentName] ||
|
|
211
|
-
(context.fragmentMap[fragmentName] =
|
|
212
|
-
context.cache.lookupFragment(fragmentName));
|
|
213
|
-
globals.invariant(fragment, 41, fragmentName);
|
|
214
|
-
var mode = utilities.getFragmentMaskMode(selection);
|
|
215
|
-
if (mode === "mask") {
|
|
216
|
-
return [memo, true];
|
|
217
|
-
}
|
|
218
|
-
if (globalThis.__DEV__ !== false) {
|
|
219
|
-
if (mode === "migrate") {
|
|
220
|
-
return [
|
|
221
|
-
addFieldAccessorWarnings(memo, data, fragment.selectionSet, path || "", context),
|
|
222
|
-
true,
|
|
223
|
-
];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
var _d = maskSelectionSet(data, fragment.selectionSet, context, path), fragmentData = _d[0], changed_2 = _d[1];
|
|
227
|
-
return [tslib.__assign(tslib.__assign({}, memo), fragmentData), changed_2];
|
|
191
|
+
var masked = maskSelectionSet(item, selectionSet, context, migration, globalThis.__DEV__ !== false ? "".concat(path || "", "[").concat(index, "]") : void 0);
|
|
192
|
+
if (knownChanged.has(masked)) {
|
|
193
|
+
knownChanged.add(target);
|
|
228
194
|
}
|
|
195
|
+
target[index] = masked;
|
|
229
196
|
}
|
|
230
|
-
|
|
231
|
-
if (data && "__typename" in data && !("__typename" in result[0])) {
|
|
232
|
-
result[0].__typename = data.__typename;
|
|
197
|
+
return knownChanged.has(target) ? target : data;
|
|
233
198
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
value = addFieldAccessorWarnings(memo[keyName] || Object.create(null), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
|
|
253
|
-
}
|
|
254
|
-
if (globalThis.__DEV__ !== false) {
|
|
255
|
-
addAccessorWarning(memo, value, keyName, path, context);
|
|
256
|
-
}
|
|
257
|
-
if (!(globalThis.__DEV__ !== false)) {
|
|
258
|
-
memo[keyName] = data[keyName];
|
|
199
|
+
var memo = getMutableTarget(data, context.mutableTargets);
|
|
200
|
+
for (var _d = 0, _e = selectionSet.selections; _d < _e.length; _d++) {
|
|
201
|
+
var selection = _e[_d];
|
|
202
|
+
var value = void 0;
|
|
203
|
+
if (migration) {
|
|
204
|
+
knownChanged.add(memo);
|
|
205
|
+
}
|
|
206
|
+
if (selection.kind === graphql.Kind.FIELD) {
|
|
207
|
+
var keyName = utilities.resultKeyNameFromField(selection);
|
|
208
|
+
var childSelectionSet = selection.selectionSet;
|
|
209
|
+
value = memo[keyName] || data[keyName];
|
|
210
|
+
if (value === void 0) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (childSelectionSet && value !== null) {
|
|
214
|
+
var masked = maskSelectionSet(data[keyName], childSelectionSet, context, migration, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0);
|
|
215
|
+
if (knownChanged.has(masked)) {
|
|
216
|
+
value = masked;
|
|
259
217
|
}
|
|
260
|
-
return memo;
|
|
261
218
|
}
|
|
262
|
-
|
|
263
|
-
|
|
219
|
+
if (!(globalThis.__DEV__ !== false)) {
|
|
220
|
+
memo[keyName] = value;
|
|
264
221
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
222
|
+
if (globalThis.__DEV__ !== false) {
|
|
223
|
+
if (migration &&
|
|
224
|
+
keyName !== "__typename" &&
|
|
225
|
+
!((_a = Object.getOwnPropertyDescriptor(memo, keyName)) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
226
|
+
Object.defineProperty(memo, keyName, getAccessorWarningDescriptor(keyName, value, path || "", context.operationName, context.operationType));
|
|
270
227
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
228
|
+
else {
|
|
229
|
+
delete memo[keyName];
|
|
230
|
+
memo[keyName] = value;
|
|
274
231
|
}
|
|
275
|
-
return addFieldAccessorWarnings(memo, data, fragment.selectionSet, path, context);
|
|
276
232
|
}
|
|
277
233
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
234
|
+
if (selection.kind === graphql.Kind.INLINE_FRAGMENT &&
|
|
235
|
+
(!selection.typeCondition ||
|
|
236
|
+
context.cache.fragmentMatches(selection, data.__typename))) {
|
|
237
|
+
value = maskSelectionSet(data, selection.selectionSet, context, migration, path);
|
|
238
|
+
}
|
|
239
|
+
if (selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
240
|
+
var fragmentName = selection.name.value;
|
|
241
|
+
var fragment = context.fragmentMap[fragmentName] ||
|
|
242
|
+
(context.fragmentMap[fragmentName] =
|
|
243
|
+
context.cache.lookupFragment(fragmentName));
|
|
244
|
+
globals.invariant(fragment, 41, fragmentName);
|
|
245
|
+
var mode = utilities.getFragmentMaskMode(selection);
|
|
246
|
+
if (mode !== "mask") {
|
|
247
|
+
value = maskSelectionSet(data, fragment.selectionSet, context, mode === "migrate", path);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (knownChanged.has(value)) {
|
|
251
|
+
knownChanged.add(memo);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if ("__typename" in data && !("__typename" in memo)) {
|
|
255
|
+
memo.__typename = data.__typename;
|
|
283
256
|
}
|
|
257
|
+
if (Object.keys(memo).length !== Object.keys(data).length) {
|
|
258
|
+
knownChanged.add(memo);
|
|
259
|
+
}
|
|
260
|
+
return knownChanged.has(memo) ? memo : data;
|
|
261
|
+
}
|
|
262
|
+
function getAccessorWarningDescriptor(fieldName, value, path, operationName, operationType) {
|
|
284
263
|
var getValue = function () {
|
|
285
264
|
if (disableWarningsSlot.getValue()) {
|
|
286
265
|
return value;
|
|
287
266
|
}
|
|
288
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(42,
|
|
289
|
-
"".concat(
|
|
290
|
-
: "anonymous ".concat(
|
|
267
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(42, operationName ?
|
|
268
|
+
"".concat(operationType, " '").concat(operationName, "'")
|
|
269
|
+
: "anonymous ".concat(operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
|
|
291
270
|
getValue = function () { return value; };
|
|
292
271
|
return value;
|
|
293
272
|
};
|
|
294
|
-
|
|
273
|
+
return {
|
|
295
274
|
get: function () {
|
|
296
275
|
return getValue();
|
|
297
276
|
},
|
|
298
|
-
set: function (
|
|
299
|
-
getValue = function () { return
|
|
277
|
+
set: function (newValue) {
|
|
278
|
+
getValue = function () { return newValue; };
|
|
300
279
|
},
|
|
301
280
|
enumerable: true,
|
|
302
281
|
configurable: true,
|
|
303
|
-
}
|
|
282
|
+
};
|
|
304
283
|
}
|
|
305
284
|
var issuedWarning = false;
|
|
306
285
|
function warnOnImproperCacheImplementation() {
|