@apollo/client 3.12.0-alpha.0 → 3.12.0-rc.1

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 (148) hide show
  1. package/.changeset/brown-readers-smash.md +5 -0
  2. package/.changeset/cold-apes-bow.md +5 -0
  3. package/.changeset/early-bobcats-eat.md +5 -0
  4. package/.changeset/flat-beans-knock.md +15 -0
  5. package/.changeset/gorgeous-zebras-confess.md +5 -0
  6. package/.changeset/kind-toys-tie.md +5 -0
  7. package/.changeset/long-zoos-ring.md +5 -0
  8. package/.changeset/nervous-owls-hear.md +5 -0
  9. package/.changeset/nice-countries-share.md +5 -0
  10. package/.changeset/pre.json +13 -2
  11. package/.changeset/slimy-points-end.md +5 -0
  12. package/.changeset/small-bears-confess.md +5 -0
  13. package/CHANGELOG.md +52 -0
  14. package/apollo-client.cjs +187 -93
  15. package/apollo-client.cjs.map +1 -1
  16. package/apollo-client.min.cjs +1 -1
  17. package/cache/cache.cjs +59 -25
  18. package/cache/cache.cjs.map +1 -1
  19. package/cache/cache.cjs.native.js +59 -25
  20. package/cache/inmemory/policies.js +12 -9
  21. package/cache/inmemory/policies.js.map +1 -1
  22. package/config/jest/setup.js +5 -0
  23. package/config/jest/setup.js.map +1 -1
  24. package/core/ApolloClient.js +7 -3
  25. package/core/ApolloClient.js.map +1 -1
  26. package/core/ObservableQuery.js +2 -0
  27. package/core/ObservableQuery.js.map +1 -1
  28. package/core/QueryManager.d.ts +4 -1
  29. package/core/QueryManager.js +26 -2
  30. package/core/QueryManager.js.map +1 -1
  31. package/core/core.cjs +86 -25
  32. package/core/core.cjs.map +1 -1
  33. package/core/core.cjs.native.js +86 -25
  34. package/core/masking.d.ts +6 -0
  35. package/core/masking.js +62 -20
  36. package/core/masking.js.map +1 -1
  37. package/dev/dev.cjs +66 -62
  38. package/dev/dev.cjs.map +1 -1
  39. package/dev/dev.cjs.native.js +66 -62
  40. package/invariantErrorCodes.js +66 -61
  41. package/link/core/ApolloLink.js +2 -2
  42. package/link/core/core.cjs +2 -2
  43. package/link/core/core.cjs.map +1 -1
  44. package/link/core/core.cjs.native.js +2 -2
  45. package/link/http/checkFetcher.js +1 -1
  46. package/link/http/createHttpLink.js +1 -1
  47. package/link/http/http.cjs +3 -3
  48. package/link/http/http.cjs.map +1 -1
  49. package/link/http/http.cjs.native.js +3 -3
  50. package/link/http/serializeFetchParameter.js +1 -1
  51. package/link/persisted-queries/index.js +2 -2
  52. package/link/persisted-queries/index.js.map +1 -1
  53. package/link/persisted-queries/persisted-queries.cjs +2 -2
  54. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  55. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  56. package/link/utils/toPromise.js +1 -1
  57. package/link/utils/utils.cjs +2 -2
  58. package/link/utils/utils.cjs.map +1 -1
  59. package/link/utils/utils.cjs.native.js +2 -2
  60. package/link/utils/validateOperation.js +1 -1
  61. package/masking/internal/types.d.ts +2 -2
  62. package/masking/internal/types.js.map +1 -1
  63. package/masking/types.d.ts +2 -2
  64. package/masking/types.js.map +1 -1
  65. package/package.json +4 -3
  66. package/react/context/ApolloConsumer.js +1 -1
  67. package/react/context/ApolloContext.js +1 -1
  68. package/react/context/ApolloProvider.js +1 -1
  69. package/react/context/context.cjs +3 -3
  70. package/react/context/context.cjs.map +1 -1
  71. package/react/context/context.cjs.native.js +3 -3
  72. package/react/hoc/hoc-utils.js +1 -1
  73. package/react/hoc/hoc.cjs +2 -2
  74. package/react/hoc/hoc.cjs.map +1 -1
  75. package/react/hoc/hoc.cjs.native.js +2 -2
  76. package/react/hoc/withApollo.js +1 -1
  77. package/react/hooks/hooks.cjs +34 -20
  78. package/react/hooks/hooks.cjs.map +1 -1
  79. package/react/hooks/hooks.cjs.native.js +34 -20
  80. package/react/hooks/useApolloClient.js +1 -1
  81. package/react/hooks/useFragment.d.ts +1 -1
  82. package/react/hooks/useFragment.js +33 -19
  83. package/react/hooks/useFragment.js.map +1 -1
  84. package/react/hooks/useLoadableQuery.js +2 -2
  85. package/react/hooks/useSubscription.js +3 -3
  86. package/react/hooks/useSuspenseQuery.js +2 -2
  87. package/react/hooks/useSyncExternalStore.js +1 -1
  88. package/react/internal/cache/QueryReference.js +2 -2
  89. package/react/internal/cache/QueryReference.js.map +1 -1
  90. package/react/internal/internal.cjs +3 -3
  91. package/react/internal/internal.cjs.map +1 -1
  92. package/react/internal/internal.cjs.native.js +3 -3
  93. package/react/parser/index.js +5 -5
  94. package/react/parser/parser.cjs +5 -5
  95. package/react/parser/parser.cjs.map +1 -1
  96. package/react/parser/parser.cjs.native.js +5 -5
  97. package/testing/core/core.cjs +2 -2
  98. package/testing/core/core.cjs.map +1 -1
  99. package/testing/core/core.cjs.native.js +2 -2
  100. package/testing/core/mocking/mockLink.js +2 -2
  101. package/testing/internal/ObservableStream.d.ts +11 -15
  102. package/testing/internal/ObservableStream.js +18 -62
  103. package/testing/internal/ObservableStream.js.map +1 -1
  104. package/testing/internal/index.d.ts +1 -2
  105. package/testing/internal/index.js +1 -2
  106. package/testing/internal/index.js.map +1 -1
  107. package/testing/internal/renderHelpers.d.ts +13 -2
  108. package/testing/internal/renderHelpers.js +20 -12
  109. package/testing/internal/renderHelpers.js.map +1 -1
  110. package/testing/matchers/index.js +0 -3
  111. package/testing/matchers/index.js.map +1 -1
  112. package/utilities/globals/globals.cjs +1 -1
  113. package/utilities/globals/globals.cjs.map +1 -1
  114. package/utilities/globals/globals.cjs.native.js +1 -1
  115. package/utilities/graphql/DocumentTransform.js +1 -1
  116. package/utilities/graphql/directives.js +7 -7
  117. package/utilities/graphql/fragments.d.ts +1 -0
  118. package/utilities/graphql/fragments.js +18 -3
  119. package/utilities/graphql/fragments.js.map +1 -1
  120. package/utilities/graphql/getFromAST.js +8 -8
  121. package/utilities/graphql/storeUtils.js +1 -1
  122. package/utilities/graphql/transform.js +8 -2
  123. package/utilities/graphql/transform.js.map +1 -1
  124. package/utilities/index.d.ts +1 -1
  125. package/utilities/index.js +1 -1
  126. package/utilities/index.js.map +1 -1
  127. package/utilities/utilities.cjs +41 -22
  128. package/utilities/utilities.cjs.map +1 -1
  129. package/utilities/utilities.cjs.native.js +41 -22
  130. package/version.js +1 -1
  131. package/testing/internal/profile/Render.d.ts +0 -69
  132. package/testing/internal/profile/Render.js +0 -144
  133. package/testing/internal/profile/Render.js.map +0 -1
  134. package/testing/internal/profile/context.d.ts +0 -10
  135. package/testing/internal/profile/context.js +0 -14
  136. package/testing/internal/profile/context.js.map +0 -1
  137. package/testing/internal/profile/index.d.ts +0 -4
  138. package/testing/internal/profile/index.js +0 -2
  139. package/testing/internal/profile/index.js.map +0 -1
  140. package/testing/internal/profile/profile.d.ts +0 -109
  141. package/testing/internal/profile/profile.js +0 -304
  142. package/testing/internal/profile/profile.js.map +0 -1
  143. package/testing/internal/profile/traces.d.ts +0 -7
  144. package/testing/internal/profile/traces.js +0 -30
  145. package/testing/internal/profile/traces.js.map +0 -1
  146. package/testing/matchers/ProfiledComponent.d.ts +0 -8
  147. package/testing/matchers/ProfiledComponent.js +0 -110
  148. package/testing/matchers/ProfiledComponent.js.map +0 -1
package/cache/cache.cjs CHANGED
@@ -126,6 +126,7 @@ function directiveIsNonreactive(dir) {
126
126
  return dir.name.value === "nonreactive";
127
127
  }
128
128
 
129
+ var disableWarningsSlot = new optimism.Slot();
129
130
  function maskFragment(data, document, cache, fragmentName) {
130
131
  if (!cache.fragmentMatches) {
131
132
  if (globalThis.__DEV__ !== false) {
@@ -137,14 +138,17 @@ function maskFragment(data, document, cache, fragmentName) {
137
138
  return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
138
139
  });
139
140
  if (typeof fragmentName === "undefined") {
140
- globals.invariant(fragments.length === 1, 38, fragments.length);
141
+ globals.invariant(fragments.length === 1, 39, fragments.length);
141
142
  fragmentName = fragments[0].name.value;
142
143
  }
143
144
  var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
144
- globals.invariant(!!fragment, 39, fragmentName);
145
+ globals.invariant(!!fragment, 40, fragmentName);
145
146
  if (data == null) {
146
147
  return data;
147
148
  }
149
+ if (equal.equal(data, {})) {
150
+ return data;
151
+ }
148
152
  var context = {
149
153
  operationType: "fragment",
150
154
  operationName: fragment.name.value,
@@ -153,9 +157,7 @@ function maskFragment(data, document, cache, fragmentName) {
153
157
  };
154
158
  var _a = maskSelectionSet(data, fragment.selectionSet, context), masked = _a[0], changed = _a[1];
155
159
  if (Object.isFrozen(data)) {
156
- context.disableWarnings = true;
157
- utilities.maybeDeepFreeze(masked);
158
- context.disableWarnings = false;
160
+ disableWarningsSlot.withValue(true, utilities.maybeDeepFreeze, [masked]);
159
161
  }
160
162
  return changed ? masked : data;
161
163
  }
@@ -172,14 +174,22 @@ function maskSelectionSet(data, selectionSet, context, path) {
172
174
  });
173
175
  return [changed_1 ? masked : data, changed_1];
174
176
  }
175
- var result = selectionSet.selections.reduce(function (_a, selection) {
177
+ var result = selectionSet.selections
178
+ .concat()
179
+ .sort(sortFragmentsLast)
180
+ .reduce(function (_a, selection) {
176
181
  var memo = _a[0], changed = _a[1];
177
182
  switch (selection.kind) {
178
183
  case graphql.Kind.FIELD: {
179
184
  var keyName = utilities.resultKeyNameFromField(selection);
180
185
  var childSelectionSet = selection.selectionSet;
181
186
  memo[keyName] = data[keyName];
182
- if (childSelectionSet && data[keyName] !== null) {
187
+ if (memo[keyName] === void 0) {
188
+ delete memo[keyName];
189
+ }
190
+ if (keyName in memo &&
191
+ childSelectionSet &&
192
+ data[keyName] !== null) {
183
193
  var _b = maskSelectionSet(data[keyName], childSelectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0), masked = _b[0], childChanged = _b[1];
184
194
  if (childChanged ||
185
195
  Object.keys(masked).length !== Object.keys(data[keyName]).length) {
@@ -205,7 +215,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
205
215
  var fragment = context.fragmentMap[fragmentName] ||
206
216
  (context.fragmentMap[fragmentName] =
207
217
  context.cache.lookupFragment(fragmentName));
208
- globals.invariant(fragment, 40, fragmentName);
218
+ globals.invariant(fragment, 41, fragmentName);
209
219
  var mode = utilities.getFragmentMaskMode(selection);
210
220
  if (mode === "mask") {
211
221
  return [memo, true];
@@ -223,7 +233,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
223
233
  }
224
234
  }
225
235
  }, [Object.create(null), false]);
226
- if ("__typename" in data && !("__typename" in result[0])) {
236
+ if (data && "__typename" in data && !("__typename" in result[0])) {
227
237
  result[0].__typename = data.__typename;
228
238
  }
229
239
  return result;
@@ -234,20 +244,29 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
234
244
  return addFieldAccessorWarnings(memo[index] || Object.create(null), item, selectionSetNode, "".concat(path, "[").concat(index, "]"), context);
235
245
  });
236
246
  }
237
- return selectionSetNode.selections.reduce(function (memo, selection) {
247
+ return selectionSetNode.selections
248
+ .concat()
249
+ .sort(sortFragmentsLast)
250
+ .reduce(function (memo, selection) {
238
251
  switch (selection.kind) {
239
252
  case graphql.Kind.FIELD: {
240
253
  var keyName = utilities.resultKeyNameFromField(selection);
241
254
  var childSelectionSet = selection.selectionSet;
242
- if (keyName in memo) {
255
+ if (keyName in memo && !childSelectionSet) {
243
256
  return memo;
244
257
  }
245
258
  var value = data[keyName];
246
259
  if (childSelectionSet) {
247
- value = addFieldAccessorWarnings(memo[keyName] || Object.create(null), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
260
+ value = addFieldAccessorWarnings(memo[keyName] ||
261
+ (Array.isArray(data[keyName]) ? [] : Object.create(null)), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
248
262
  }
249
263
  if (globalThis.__DEV__ !== false) {
250
- addAccessorWarning(memo, value, keyName, path, context);
264
+ if (keyName in memo) {
265
+ memo[keyName] = value;
266
+ }
267
+ else {
268
+ addAccessorWarning(memo, value, keyName, path, context);
269
+ }
251
270
  }
252
271
  if (!(globalThis.__DEV__ !== false)) {
253
272
  memo[keyName] = data[keyName];
@@ -255,6 +274,10 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
255
274
  return memo;
256
275
  }
257
276
  case graphql.Kind.INLINE_FRAGMENT: {
277
+ if (selection.typeCondition &&
278
+ !context.cache.fragmentMatches(selection, data.__typename)) {
279
+ return memo;
280
+ }
258
281
  return addFieldAccessorWarnings(memo, data, selection.selectionSet, path, context);
259
282
  }
260
283
  case graphql.Kind.FRAGMENT_SPREAD: {
@@ -273,11 +296,14 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
273
296
  }, memo);
274
297
  }
275
298
  function addAccessorWarning(data, value, fieldName, path, context) {
299
+ if (value === void 0) {
300
+ return;
301
+ }
276
302
  var getValue = function () {
277
- if (context.disableWarnings) {
303
+ if (disableWarningsSlot.getValue()) {
278
304
  return value;
279
305
  }
280
- globalThis.__DEV__ !== false && globals.invariant.warn(41, context.operationName ?
306
+ globalThis.__DEV__ !== false && globals.invariant.warn(42, context.operationName ?
281
307
  "".concat(context.operationType, " '").concat(context.operationName, "'")
282
308
  : "anonymous ".concat(context.operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
283
309
  getValue = function () { return value; };
@@ -298,9 +324,15 @@ var issuedWarning = false;
298
324
  function warnOnImproperCacheImplementation() {
299
325
  if (!issuedWarning) {
300
326
  issuedWarning = true;
301
- globalThis.__DEV__ !== false && globals.invariant.warn(42);
327
+ globalThis.__DEV__ !== false && globals.invariant.warn(43);
302
328
  }
303
329
  }
330
+ function sortFragmentsLast(a, b) {
331
+ if (a.kind === b.kind) {
332
+ return 0;
333
+ }
334
+ return a.kind === graphql.Kind.FRAGMENT_SPREAD ? 1 : -1;
335
+ }
304
336
 
305
337
  var ApolloCache = (function () {
306
338
  function ApolloCache() {
@@ -1648,16 +1680,18 @@ var Policies = (function () {
1648
1680
  var id;
1649
1681
  var policy = typename && this.getTypePolicy(typename);
1650
1682
  var keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;
1651
- while (keyFn) {
1652
- var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
1653
- if (utilities.isArray(specifierOrId)) {
1654
- keyFn = keyFieldsFnFromSpecifier(specifierOrId);
1655
- }
1656
- else {
1657
- id = specifierOrId;
1658
- break;
1683
+ disableWarningsSlot.withValue(true, function () {
1684
+ while (keyFn) {
1685
+ var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
1686
+ if (utilities.isArray(specifierOrId)) {
1687
+ keyFn = keyFieldsFnFromSpecifier(specifierOrId);
1688
+ }
1689
+ else {
1690
+ id = specifierOrId;
1691
+ break;
1692
+ }
1659
1693
  }
1660
- }
1694
+ });
1661
1695
  id = id ? String(id) : void 0;
1662
1696
  return context.keyObject ? [id, context.keyObject] : [id];
1663
1697
  };