@apollo/client 3.11.9 → 3.11.11-rc.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.
Files changed (191) hide show
  1. package/.changeset/early-bobcats-eat.md +5 -0
  2. package/.changeset/flat-beans-knock.md +15 -0
  3. package/.changeset/kind-toys-tie.md +5 -0
  4. package/.changeset/nasty-camels-pay.md +36 -0
  5. package/.changeset/nervous-owls-hear.md +5 -0
  6. package/.changeset/pre.json +14 -0
  7. package/CHANGELOG.md +65 -0
  8. package/apollo-client.cjs +503 -120
  9. package/apollo-client.cjs.map +1 -1
  10. package/apollo-client.min.cjs +1 -1
  11. package/cache/cache.cjs +237 -31
  12. package/cache/cache.cjs.map +1 -1
  13. package/cache/cache.cjs.native.js +237 -31
  14. package/cache/core/cache.d.ts +13 -10
  15. package/cache/core/cache.js +32 -14
  16. package/cache/core/cache.js.map +1 -1
  17. package/cache/core/types/Cache.d.ts +2 -1
  18. package/cache/core/types/Cache.js.map +1 -1
  19. package/cache/core/types/DataProxy.d.ts +4 -3
  20. package/cache/core/types/DataProxy.js.map +1 -1
  21. package/cache/inmemory/entityStore.js +3 -3
  22. package/cache/inmemory/inMemoryCache.d.ts +3 -1
  23. package/cache/inmemory/inMemoryCache.js +7 -0
  24. package/cache/inmemory/inMemoryCache.js.map +1 -1
  25. package/cache/inmemory/key-extractor.js +1 -1
  26. package/cache/inmemory/policies.js +16 -13
  27. package/cache/inmemory/policies.js.map +1 -1
  28. package/cache/inmemory/readFromStore.js +2 -2
  29. package/cache/inmemory/writeToStore.js +4 -4
  30. package/core/ApolloClient.d.ts +14 -6
  31. package/core/ApolloClient.js +20 -8
  32. package/core/ApolloClient.js.map +1 -1
  33. package/core/LocalState.js +2 -2
  34. package/core/ObservableQuery.d.ts +17 -14
  35. package/core/ObservableQuery.js +31 -16
  36. package/core/ObservableQuery.js.map +1 -1
  37. package/core/QueryInfo.js.map +1 -1
  38. package/core/QueryManager.d.ts +22 -4
  39. package/core/QueryManager.js +63 -14
  40. package/core/QueryManager.js.map +1 -1
  41. package/core/core.cjs +324 -39
  42. package/core/core.cjs.map +1 -1
  43. package/core/core.cjs.native.js +324 -39
  44. package/core/index.d.ts +1 -0
  45. package/core/index.js.map +1 -1
  46. package/core/masking.d.ts +10 -0
  47. package/core/masking.js +230 -0
  48. package/core/masking.js.map +1 -0
  49. package/core/types.d.ts +3 -2
  50. package/core/types.js.map +1 -1
  51. package/core/watchQueryOptions.d.ts +8 -6
  52. package/core/watchQueryOptions.js.map +1 -1
  53. package/dev/dev.cjs +136 -88
  54. package/dev/dev.cjs.map +1 -1
  55. package/dev/dev.cjs.native.js +136 -88
  56. package/invariantErrorCodes.js +146 -87
  57. package/link/core/ApolloLink.js +2 -2
  58. package/link/core/core.cjs +2 -2
  59. package/link/core/core.cjs.map +1 -1
  60. package/link/core/core.cjs.native.js +2 -2
  61. package/link/http/checkFetcher.js +1 -1
  62. package/link/http/createHttpLink.js +1 -1
  63. package/link/http/http.cjs +3 -3
  64. package/link/http/http.cjs.map +1 -1
  65. package/link/http/http.cjs.native.js +3 -3
  66. package/link/http/serializeFetchParameter.js +1 -1
  67. package/link/persisted-queries/index.js +2 -2
  68. package/link/persisted-queries/index.js.map +1 -1
  69. package/link/persisted-queries/persisted-queries.cjs +2 -2
  70. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  71. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  72. package/link/utils/toPromise.js +1 -1
  73. package/link/utils/utils.cjs +2 -2
  74. package/link/utils/utils.cjs.map +1 -1
  75. package/link/utils/utils.cjs.native.js +2 -2
  76. package/link/utils/validateOperation.js +1 -1
  77. package/masking/index.d.ts +2 -0
  78. package/masking/index.js +2 -0
  79. package/masking/index.js.map +1 -0
  80. package/masking/internal/types.d.ts +15 -0
  81. package/masking/internal/types.js +2 -0
  82. package/masking/internal/types.js.map +1 -0
  83. package/masking/masking.cjs +3 -0
  84. package/masking/masking.cjs.map +1 -0
  85. package/masking/masking.cjs.native.js +3 -0
  86. package/masking/masking.d.cts +1 -0
  87. package/masking/package.json +8 -0
  88. package/masking/types.d.ts +44 -0
  89. package/masking/types.js +2 -0
  90. package/masking/types.js.map +1 -0
  91. package/package.json +2 -2
  92. package/react/context/ApolloConsumer.js +1 -1
  93. package/react/context/ApolloContext.js +1 -1
  94. package/react/context/ApolloProvider.js +1 -1
  95. package/react/context/context.cjs +3 -3
  96. package/react/context/context.cjs.map +1 -1
  97. package/react/context/context.cjs.native.js +3 -3
  98. package/react/hoc/hoc-utils.js +1 -1
  99. package/react/hoc/hoc.cjs +2 -2
  100. package/react/hoc/hoc.cjs.map +1 -1
  101. package/react/hoc/hoc.cjs.native.js +2 -2
  102. package/react/hoc/withApollo.js +1 -1
  103. package/react/hooks/hooks.cjs +24 -16
  104. package/react/hooks/hooks.cjs.map +1 -1
  105. package/react/hooks/hooks.cjs.native.js +24 -16
  106. package/react/hooks/useApolloClient.js +1 -1
  107. package/react/hooks/useFragment.d.ts +4 -3
  108. package/react/hooks/useFragment.js +12 -5
  109. package/react/hooks/useFragment.js.map +1 -1
  110. package/react/hooks/useLazyQuery.js +1 -1
  111. package/react/hooks/useLazyQuery.js.map +1 -1
  112. package/react/hooks/useLoadableQuery.js +2 -2
  113. package/react/hooks/useQuery.d.ts +4 -3
  114. package/react/hooks/useQuery.js +2 -1
  115. package/react/hooks/useQuery.js.map +1 -1
  116. package/react/hooks/useReadQuery.d.ts +2 -1
  117. package/react/hooks/useReadQuery.js.map +1 -1
  118. package/react/hooks/useSubscription.d.ts +2 -1
  119. package/react/hooks/useSubscription.js +3 -3
  120. package/react/hooks/useSubscription.js.map +1 -1
  121. package/react/hooks/useSuspenseQuery.d.ts +6 -5
  122. package/react/hooks/useSuspenseQuery.js +2 -2
  123. package/react/hooks/useSuspenseQuery.js.map +1 -1
  124. package/react/hooks/useSyncExternalStore.js +1 -1
  125. package/react/internal/cache/QueryReference.d.ts +5 -4
  126. package/react/internal/cache/QueryReference.js +1 -1
  127. package/react/internal/cache/QueryReference.js.map +1 -1
  128. package/react/internal/internal.cjs +2 -2
  129. package/react/internal/internal.cjs.map +1 -1
  130. package/react/internal/internal.cjs.native.js +2 -2
  131. package/react/parser/index.js +5 -5
  132. package/react/parser/parser.cjs +5 -5
  133. package/react/parser/parser.cjs.map +1 -1
  134. package/react/parser/parser.cjs.native.js +5 -5
  135. package/react/types/types.d.ts +18 -42
  136. package/react/types/types.js.map +1 -1
  137. package/testing/core/core.cjs +3 -3
  138. package/testing/core/core.cjs.map +1 -1
  139. package/testing/core/core.cjs.native.js +3 -3
  140. package/testing/core/mocking/mockLink.d.ts +3 -2
  141. package/testing/core/mocking/mockLink.js +3 -3
  142. package/testing/core/mocking/mockLink.js.map +1 -1
  143. package/testing/core/mocking/mockQueryManager.d.ts +1 -0
  144. package/testing/core/mocking/mockQueryManager.js +1 -1
  145. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  146. package/testing/internal/disposables/index.d.ts +1 -0
  147. package/testing/internal/disposables/index.js +1 -0
  148. package/testing/internal/disposables/index.js.map +1 -1
  149. package/testing/internal/disposables/withProdMode.d.ts +4 -0
  150. package/testing/internal/disposables/withProdMode.js +10 -0
  151. package/testing/internal/disposables/withProdMode.js.map +1 -0
  152. package/testing/internal/scenarios/index.d.ts +28 -0
  153. package/testing/internal/scenarios/index.js +18 -2
  154. package/testing/internal/scenarios/index.js.map +1 -1
  155. package/utilities/common/maybeDeepFreeze.d.ts +1 -0
  156. package/utilities/common/maybeDeepFreeze.js +1 -1
  157. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  158. package/utilities/globals/globals.cjs +1 -1
  159. package/utilities/globals/globals.cjs.map +1 -1
  160. package/utilities/globals/globals.cjs.native.js +1 -1
  161. package/utilities/graphql/DocumentTransform.js +1 -1
  162. package/utilities/graphql/directives.d.ts +3 -1
  163. package/utilities/graphql/directives.js +39 -5
  164. package/utilities/graphql/directives.js.map +1 -1
  165. package/utilities/graphql/fragments.d.ts +1 -0
  166. package/utilities/graphql/fragments.js +18 -3
  167. package/utilities/graphql/fragments.js.map +1 -1
  168. package/utilities/graphql/getFromAST.js +8 -8
  169. package/utilities/graphql/storeUtils.js +1 -1
  170. package/utilities/graphql/transform.d.ts +1 -0
  171. package/utilities/graphql/transform.js +21 -2
  172. package/utilities/graphql/transform.js.map +1 -1
  173. package/utilities/index.d.ts +8 -4
  174. package/utilities/index.js +5 -4
  175. package/utilities/index.js.map +1 -1
  176. package/utilities/promises/preventUnhandledRejection.d.ts +2 -0
  177. package/utilities/promises/preventUnhandledRejection.js +5 -0
  178. package/utilities/promises/preventUnhandledRejection.js.map +1 -0
  179. package/utilities/types/NoInfer.d.ts +27 -0
  180. package/utilities/types/NoInfer.js +2 -0
  181. package/utilities/types/NoInfer.js.map +1 -0
  182. package/utilities/types/Prettify.d.ts +4 -0
  183. package/utilities/types/Prettify.js +2 -0
  184. package/utilities/types/Prettify.js.map +1 -0
  185. package/utilities/types/UnionToIntersection.d.ts +2 -0
  186. package/utilities/types/UnionToIntersection.js +2 -0
  187. package/utilities/types/UnionToIntersection.js.map +1 -0
  188. package/utilities/utilities.cjs +92 -19
  189. package/utilities/utilities.cjs.map +1 -1
  190. package/utilities/utilities.cjs.native.js +92 -19
  191. package/version.js +1 -1
@@ -22,7 +22,7 @@ function shouldInclude(_a, variables) {
22
22
  if (ifArgument.value.kind === "Variable") {
23
23
  evaledValue =
24
24
  variables && variables[ifArgument.value.name.value];
25
- globals.invariant(evaledValue !== void 0, 70, directive.name.value);
25
+ globals.invariant(evaledValue !== void 0, 78, directive.name.value);
26
26
  }
27
27
  else {
28
28
  evaledValue = ifArgument.value.value;
@@ -72,17 +72,50 @@ function getInclusionDirectives(directives) {
72
72
  return;
73
73
  var directiveArguments = directive.arguments;
74
74
  var directiveName = directive.name.value;
75
- globals.invariant(directiveArguments && directiveArguments.length === 1, 71, directiveName);
75
+ globals.invariant(directiveArguments && directiveArguments.length === 1, 79, directiveName);
76
76
  var ifArgument = directiveArguments[0];
77
- globals.invariant(ifArgument.name && ifArgument.name.value === "if", 72, directiveName);
77
+ globals.invariant(ifArgument.name && ifArgument.name.value === "if", 80, directiveName);
78
78
  var ifValue = ifArgument.value;
79
79
  globals.invariant(ifValue &&
80
- (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 73, directiveName);
80
+ (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 81, directiveName);
81
81
  result.push({ directive: directive, ifArgument: ifArgument });
82
82
  });
83
83
  }
84
84
  return result;
85
85
  }
86
+ function getFragmentMaskMode(fragment) {
87
+ var _a, _b;
88
+ var directive = (_a = fragment.directives) === null || _a === void 0 ? void 0 : _a.find(function (_a) {
89
+ var name = _a.name;
90
+ return name.value === "unmask";
91
+ });
92
+ if (!directive) {
93
+ return "mask";
94
+ }
95
+ var modeArg = (_b = directive.arguments) === null || _b === void 0 ? void 0 : _b.find(function (_a) {
96
+ var name = _a.name;
97
+ return name.value === "mode";
98
+ });
99
+ if (globalThis.__DEV__ !== false) {
100
+ if (modeArg) {
101
+ if (modeArg.value.kind === graphql.Kind.VARIABLE) {
102
+ globalThis.__DEV__ !== false && globals.invariant.warn(82);
103
+ }
104
+ else if (modeArg.value.kind !== graphql.Kind.STRING) {
105
+ globalThis.__DEV__ !== false && globals.invariant.warn(83);
106
+ }
107
+ else if (modeArg.value.value !== "migrate") {
108
+ globalThis.__DEV__ !== false && globals.invariant.warn(84, modeArg.value.value);
109
+ }
110
+ }
111
+ }
112
+ if (modeArg &&
113
+ "value" in modeArg.value &&
114
+ modeArg.value.value === "migrate") {
115
+ return "migrate";
116
+ }
117
+ return "unmask";
118
+ }
86
119
 
87
120
  var isReactNative = globals.maybe(function () { return navigator.product; }) == "ReactNative";
88
121
  var canUseWeakMap = typeof WeakMap === "function" &&
@@ -111,7 +144,7 @@ function getFragmentQueryDocument(document, fragmentName) {
111
144
  document.definitions.forEach(function (definition) {
112
145
  if (definition.kind === "OperationDefinition") {
113
146
  throw globals.newInvariantError(
114
- 74,
147
+ 85,
115
148
  definition.operation,
116
149
  definition.name ? " named '".concat(definition.name.value, "'") : ""
117
150
  );
@@ -121,7 +154,7 @@ function getFragmentQueryDocument(document, fragmentName) {
121
154
  }
122
155
  });
123
156
  if (typeof actualFragmentName === "undefined") {
124
- globals.invariant(fragments.length === 1, 75, fragments.length);
157
+ globals.invariant(fragments.length === 1, 86, fragments.length);
125
158
  actualFragmentName = fragments[0].name.value;
126
159
  }
127
160
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -162,13 +195,27 @@ function getFragmentFromSelection(selection, fragmentMap) {
162
195
  return fragmentMap(fragmentName);
163
196
  }
164
197
  var fragment = fragmentMap && fragmentMap[fragmentName];
165
- globals.invariant(fragment, 76, fragmentName);
198
+ globals.invariant(fragment, 87, fragmentName);
166
199
  return fragment || null;
167
200
  }
168
201
  default:
169
202
  return null;
170
203
  }
171
204
  }
205
+ function isFullyUnmaskedOperation(document) {
206
+ var isUnmasked = true;
207
+ graphql.visit(document, {
208
+ FragmentSpread: function (node) {
209
+ isUnmasked =
210
+ !!node.directives &&
211
+ node.directives.some(function (directive) { return directive.name.value === "unmask"; });
212
+ if (!isUnmasked) {
213
+ return graphql.BREAK;
214
+ }
215
+ },
216
+ });
217
+ return isUnmasked;
218
+ }
172
219
 
173
220
  var scheduledCleanup = new WeakSet();
174
221
  function schedule(cache) {
@@ -321,7 +368,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
321
368
  argObj[name.value] = null;
322
369
  }
323
370
  else {
324
- throw globals.newInvariantError(85, name.value, value.kind);
371
+ throw globals.newInvariantError(96, name.value, value.kind);
325
372
  }
326
373
  }
327
374
  function storeKeyNameFromField(field, variables) {
@@ -455,16 +502,16 @@ function isInlineFragment(selection) {
455
502
  }
456
503
 
457
504
  function checkDocument(doc) {
458
- globals.invariant(doc && doc.kind === "Document", 77);
505
+ globals.invariant(doc && doc.kind === "Document", 88);
459
506
  var operations = doc.definitions
460
507
  .filter(function (d) { return d.kind !== "FragmentDefinition"; })
461
508
  .map(function (definition) {
462
509
  if (definition.kind !== "OperationDefinition") {
463
- throw globals.newInvariantError(78, definition.kind);
510
+ throw globals.newInvariantError(89, definition.kind);
464
511
  }
465
512
  return definition;
466
513
  });
467
- globals.invariant(operations.length <= 1, 79, operations.length);
514
+ globals.invariant(operations.length <= 1, 90, operations.length);
468
515
  return doc;
469
516
  }
470
517
  function getOperationDefinition(doc) {
@@ -487,14 +534,14 @@ function getFragmentDefinitions(doc) {
487
534
  }
488
535
  function getQueryDefinition(doc) {
489
536
  var queryDef = getOperationDefinition(doc);
490
- globals.invariant(queryDef && queryDef.operation === "query", 80);
537
+ globals.invariant(queryDef && queryDef.operation === "query", 91);
491
538
  return queryDef;
492
539
  }
493
540
  function getFragmentDefinition(doc) {
494
- globals.invariant(doc.kind === "Document", 81);
495
- globals.invariant(doc.definitions.length <= 1, 82);
541
+ globals.invariant(doc.kind === "Document", 92);
542
+ globals.invariant(doc.definitions.length <= 1, 93);
496
543
  var fragmentDef = doc.definitions[0];
497
- globals.invariant(fragmentDef.kind === "FragmentDefinition", 83);
544
+ globals.invariant(fragmentDef.kind === "FragmentDefinition", 94);
498
545
  return fragmentDef;
499
546
  }
500
547
  function getMainDefinition(queryDoc) {
@@ -517,7 +564,7 @@ function getMainDefinition(queryDoc) {
517
564
  if (fragmentDefinition) {
518
565
  return fragmentDefinition;
519
566
  }
520
- throw globals.newInvariantError(84);
567
+ throw globals.newInvariantError(95);
521
568
  }
522
569
  function getDefaultValues(definition) {
523
570
  var defaultValues = Object.create(null);
@@ -568,7 +615,7 @@ var DocumentTransform = (function () {
568
615
  makeCacheKey: function (document) {
569
616
  var cacheKeys = _this.getCacheKey(document);
570
617
  if (cacheKeys) {
571
- globals.invariant(Array.isArray(cacheKeys), 69);
618
+ globals.invariant(Array.isArray(cacheKeys), 77);
572
619
  return stableCacheKeys_1.lookupArray(cacheKeys);
573
620
  }
574
621
  },
@@ -698,7 +745,7 @@ function removeDirectivesFromDocument(directives, doc) {
698
745
  return getInUseByFragmentName(ancestor.name.value);
699
746
  }
700
747
  }
701
- globalThis.__DEV__ !== false && globals.invariant.error(86);
748
+ globalThis.__DEV__ !== false && globals.invariant.error(97);
702
749
  return null;
703
750
  };
704
751
  var operationCount = 0;
@@ -888,7 +935,7 @@ var connectionRemoveConfig = {
888
935
  if (willRemove) {
889
936
  if (!directive.arguments ||
890
937
  !directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
891
- globalThis.__DEV__ !== false && globals.invariant.warn(87);
938
+ globalThis.__DEV__ !== false && globals.invariant.warn(98);
892
939
  }
893
940
  }
894
941
  return willRemove;
@@ -984,6 +1031,23 @@ function removeClientSetsFromDocument(document) {
984
1031
  ], document);
985
1032
  return modifiedDoc;
986
1033
  }
1034
+ function addNonReactiveToNamedFragments(document) {
1035
+ checkDocument(document);
1036
+ return graphql.visit(document, {
1037
+ FragmentSpread: function (node) {
1038
+ var _a;
1039
+ if ((_a = node.directives) === null || _a === void 0 ? void 0 : _a.some(function (directive) { return directive.name.value === "unmask"; })) {
1040
+ return;
1041
+ }
1042
+ return tslib.__assign(tslib.__assign({}, node), { directives: tslib.__spreadArray(tslib.__spreadArray([], (node.directives || []), true), [
1043
+ {
1044
+ kind: graphql.Kind.DIRECTIVE,
1045
+ name: { kind: graphql.Kind.NAME, value: "nonreactive" },
1046
+ },
1047
+ ], false) });
1048
+ },
1049
+ });
1050
+ }
987
1051
 
988
1052
  function isOperation(document, operation) {
989
1053
  var _a;
@@ -1266,6 +1330,11 @@ function wrapPromiseWithState(promise) {
1266
1330
  return promise;
1267
1331
  }
1268
1332
 
1333
+ function preventUnhandledRejection(promise) {
1334
+ promise.catch(function () { });
1335
+ return promise;
1336
+ }
1337
+
1269
1338
  var toString = Object.prototype.toString;
1270
1339
  function cloneDeep(value) {
1271
1340
  return cloneDeepHelper(value);
@@ -1654,6 +1723,7 @@ exports.AutoCleanedWeakCache = AutoCleanedWeakCache;
1654
1723
  exports.Concast = Concast;
1655
1724
  exports.DeepMerger = DeepMerger;
1656
1725
  exports.DocumentTransform = DocumentTransform;
1726
+ exports.addNonReactiveToNamedFragments = addNonReactiveToNamedFragments;
1657
1727
  exports.addTypenameToDocument = addTypenameToDocument;
1658
1728
  exports.argumentsObjectFromField = argumentsObjectFromField;
1659
1729
  exports.asyncMap = asyncMap;
@@ -1679,6 +1749,7 @@ exports.getDirectiveNames = getDirectiveNames;
1679
1749
  exports.getFragmentDefinition = getFragmentDefinition;
1680
1750
  exports.getFragmentDefinitions = getFragmentDefinitions;
1681
1751
  exports.getFragmentFromSelection = getFragmentFromSelection;
1752
+ exports.getFragmentMaskMode = getFragmentMaskMode;
1682
1753
  exports.getFragmentQueryDocument = getFragmentQueryDocument;
1683
1754
  exports.getGraphQLErrorsFromResult = getGraphQLErrorsFromResult;
1684
1755
  exports.getInclusionDirectives = getInclusionDirectives;
@@ -1700,6 +1771,7 @@ exports.isExecutionPatchIncrementalResult = isExecutionPatchIncrementalResult;
1700
1771
  exports.isExecutionPatchInitialResult = isExecutionPatchInitialResult;
1701
1772
  exports.isExecutionPatchResult = isExecutionPatchResult;
1702
1773
  exports.isField = isField;
1774
+ exports.isFullyUnmaskedOperation = isFullyUnmaskedOperation;
1703
1775
  exports.isInlineFragment = isInlineFragment;
1704
1776
  exports.isMutationOperation = isMutationOperation;
1705
1777
  exports.isNonEmptyArray = isNonEmptyArray;
@@ -1719,6 +1791,7 @@ exports.mergeIncrementalData = mergeIncrementalData;
1719
1791
  exports.mergeOptions = mergeOptions;
1720
1792
  exports.offsetLimitPagination = offsetLimitPagination;
1721
1793
  exports.omitDeep = omitDeep;
1794
+ exports.preventUnhandledRejection = preventUnhandledRejection;
1722
1795
  exports.print = print;
1723
1796
  exports.relayStylePagination = relayStylePagination;
1724
1797
  exports.removeArgumentsFromDocument = removeArgumentsFromDocument;