@apollo/client 3.12.0-rc.2 → 3.12.0-rc.4

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.
Files changed (86) hide show
  1. package/.changeset/clean-turkeys-kick.md +5 -0
  2. package/.changeset/happy-months-happen.md +5 -0
  3. package/.changeset/perfect-jobs-flow.md +5 -0
  4. package/.changeset/pre.json +3 -0
  5. package/CHANGELOG.md +14 -0
  6. package/apollo-client.cjs +74 -72
  7. package/apollo-client.cjs.map +1 -1
  8. package/apollo-client.min.cjs +1 -1
  9. package/cache/cache.cjs +4 -166
  10. package/cache/cache.cjs.map +1 -1
  11. package/cache/cache.cjs.native.js +4 -166
  12. package/cache/core/cache.js +1 -1
  13. package/cache/core/cache.js.map +1 -1
  14. package/cache/inmemory/policies.js +1 -1
  15. package/cache/inmemory/policies.js.map +1 -1
  16. package/core/QueryManager.js +1 -1
  17. package/core/QueryManager.js.map +1 -1
  18. package/core/core.cjs +4 -189
  19. package/core/core.cjs.map +1 -1
  20. package/core/core.cjs.native.js +4 -189
  21. package/dev/dev.cjs +37 -37
  22. package/dev/dev.cjs.map +1 -1
  23. package/dev/dev.cjs.native.js +37 -37
  24. package/invariantErrorCodes.js +42 -42
  25. package/link/core/ApolloLink.js +2 -2
  26. package/link/core/core.cjs +2 -2
  27. package/link/core/core.cjs.map +1 -1
  28. package/link/core/core.cjs.native.js +2 -2
  29. package/link/http/checkFetcher.js +1 -1
  30. package/link/http/createHttpLink.js +1 -1
  31. package/link/http/http.cjs +3 -3
  32. package/link/http/http.cjs.map +1 -1
  33. package/link/http/http.cjs.native.js +3 -3
  34. package/link/http/serializeFetchParameter.js +1 -1
  35. package/link/persisted-queries/index.js +2 -2
  36. package/link/persisted-queries/persisted-queries.cjs +2 -2
  37. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  38. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  39. package/link/utils/toPromise.js +1 -1
  40. package/link/utils/utils.cjs +2 -2
  41. package/link/utils/utils.cjs.map +1 -1
  42. package/link/utils/utils.cjs.native.js +2 -2
  43. package/link/utils/validateOperation.js +1 -1
  44. package/masking/__benches__/types.bench.d.ts +2 -0
  45. package/masking/__benches__/types.bench.js +131 -0
  46. package/masking/__benches__/types.bench.js.map +1 -0
  47. package/masking/index.d.ts +3 -0
  48. package/masking/index.js +3 -1
  49. package/masking/index.js.map +1 -1
  50. package/masking/internal/types.d.ts +115 -9
  51. package/masking/internal/types.js.map +1 -1
  52. package/masking/maskDefinition.d.ts +14 -0
  53. package/{core/masking.js → masking/maskDefinition.js} +11 -83
  54. package/masking/maskDefinition.js.map +1 -0
  55. package/masking/maskFragment.d.ts +4 -0
  56. package/masking/maskFragment.js +43 -0
  57. package/masking/maskFragment.js.map +1 -0
  58. package/masking/maskOperation.d.ts +4 -0
  59. package/masking/maskOperation.js +29 -0
  60. package/masking/maskOperation.js.map +1 -0
  61. package/masking/masking.cjs +202 -0
  62. package/masking/masking.cjs.map +1 -1
  63. package/masking/masking.cjs.native.js +202 -0
  64. package/masking/types.d.ts +4 -4
  65. package/masking/types.js.map +1 -1
  66. package/masking/utils.d.ts +11 -0
  67. package/masking/utils.js +17 -0
  68. package/masking/utils.js.map +1 -0
  69. package/package.json +3 -1
  70. package/react/hoc/hoc.cjs.map +1 -1
  71. package/react/hoc/mutation-hoc.js +3 -2
  72. package/react/hoc/mutation-hoc.js.map +1 -1
  73. package/react/internal/internal.cjs +1 -1
  74. package/react/internal/internal.cjs.map +1 -1
  75. package/react/internal/internal.cjs.native.js +1 -1
  76. package/react/types/types.d.ts +5 -1
  77. package/react/types/types.documentation.d.ts +7 -1
  78. package/react/types/types.documentation.js.map +1 -1
  79. package/testing/internal/scenarios/index.d.ts +1 -0
  80. package/testing/internal/scenarios/index.js.map +1 -1
  81. package/utilities/globals/globals.cjs +1 -1
  82. package/utilities/globals/globals.cjs.map +1 -1
  83. package/utilities/globals/globals.cjs.native.js +1 -1
  84. package/version.js +1 -1
  85. package/core/masking.d.ts +0 -10
  86. package/core/masking.js.map +0 -1
package/cache/cache.cjs CHANGED
@@ -8,8 +8,9 @@ var optimism = require('optimism');
8
8
  var utilities = require('../utilities');
9
9
  var caches = require('@wry/caches');
10
10
  var equal = require('@wry/equality');
11
- var graphql = require('graphql');
11
+ var masking = require('../masking');
12
12
  var trie = require('@wry/trie');
13
+ var graphql = require('graphql');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
15
16
 
@@ -126,169 +127,6 @@ function directiveIsNonreactive(dir) {
126
127
  return dir.name.value === "nonreactive";
127
128
  }
128
129
 
129
- var MapImpl = utilities.canUseWeakMap ? WeakMap : Map;
130
- var SetImpl = utilities.canUseWeakSet ? WeakSet : Set;
131
- var disableWarningsSlot = new optimism.Slot();
132
- function maskFragment(data, document, cache, fragmentName) {
133
- if (!cache.fragmentMatches) {
134
- if (globalThis.__DEV__ !== false) {
135
- warnOnImproperCacheImplementation();
136
- }
137
- return data;
138
- }
139
- var fragments = document.definitions.filter(function (node) {
140
- return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
141
- });
142
- if (typeof fragmentName === "undefined") {
143
- globals.invariant(fragments.length === 1, 39, fragments.length);
144
- fragmentName = fragments[0].name.value;
145
- }
146
- var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
147
- globals.invariant(!!fragment, 40, fragmentName);
148
- if (data == null) {
149
- return data;
150
- }
151
- if (equal.equal(data, {})) {
152
- return data;
153
- }
154
- return maskDefinition(data, fragment.selectionSet, {
155
- operationType: "fragment",
156
- operationName: fragment.name.value,
157
- fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(document)),
158
- cache: cache,
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);
175
- }
176
- var mutableTarget = Array.isArray(data) ? [] : Object.create(null);
177
- mutableTargets.set(data, mutableTarget);
178
- return mutableTarget;
179
- }
180
- function maskSelectionSet(data, selectionSet, context, migration, path) {
181
- var _a;
182
- var knownChanged = context.knownChanged;
183
- if (Array.isArray(data)) {
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];
187
- if (item === null) {
188
- target[index] = null;
189
- continue;
190
- }
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);
194
- }
195
- target[index] = masked;
196
- }
197
- return knownChanged.has(target) ? target : data;
198
- }
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;
217
- }
218
- }
219
- if (!(globalThis.__DEV__ !== false)) {
220
- memo[keyName] = value;
221
- }
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));
227
- }
228
- else {
229
- delete memo[keyName];
230
- memo[keyName] = value;
231
- }
232
- }
233
- }
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;
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) {
263
- var getValue = function () {
264
- if (disableWarningsSlot.getValue()) {
265
- return value;
266
- }
267
- globalThis.__DEV__ !== false && globals.invariant.warn(42, operationName ?
268
- "".concat(operationType, " '").concat(operationName, "'")
269
- : "anonymous ".concat(operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
270
- getValue = function () { return value; };
271
- return value;
272
- };
273
- return {
274
- get: function () {
275
- return getValue();
276
- },
277
- set: function (newValue) {
278
- getValue = function () { return newValue; };
279
- },
280
- enumerable: true,
281
- configurable: true,
282
- };
283
- }
284
- var issuedWarning = false;
285
- function warnOnImproperCacheImplementation() {
286
- if (!issuedWarning) {
287
- issuedWarning = true;
288
- globalThis.__DEV__ !== false && globals.invariant.warn(43);
289
- }
290
- }
291
-
292
130
  var ApolloCache = (function () {
293
131
  function ApolloCache() {
294
132
  this.assumeImmutableResults = false;
@@ -351,7 +189,7 @@ var ApolloCache = (function () {
351
189
  return new utilities.Observable(function (observer) {
352
190
  return _this.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
353
191
  var data = dataMasking ?
354
- maskFragment(diff.result, fragment, _this, fragmentName)
192
+ masking.maskFragment(diff.result, fragment, _this, fragmentName)
355
193
  : diff.result;
356
194
  if (
357
195
  latestDiff &&
@@ -1635,7 +1473,7 @@ var Policies = (function () {
1635
1473
  var id;
1636
1474
  var policy = typename && this.getTypePolicy(typename);
1637
1475
  var keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;
1638
- disableWarningsSlot.withValue(true, function () {
1476
+ masking.disableWarningsSlot.withValue(true, function () {
1639
1477
  while (keyFn) {
1640
1478
  var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
1641
1479
  if (utilities.isArray(specifierOrId)) {