@apollo/client 3.9.0-alpha.2 → 3.9.0-alpha.3

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 (138) hide show
  1. package/apollo-client.cjs +126 -77
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +46 -11
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +46 -11
  7. package/cache/core/types/common.d.ts +2 -2
  8. package/cache/core/types/common.d.ts.map +1 -1
  9. package/cache/core/types/common.js.map +1 -1
  10. package/cache/inmemory/entityStore.d.ts.map +1 -1
  11. package/cache/inmemory/entityStore.js +35 -0
  12. package/cache/inmemory/entityStore.js.map +1 -1
  13. package/cache/inmemory/key-extractor.js +1 -1
  14. package/cache/inmemory/policies.js +4 -4
  15. package/cache/inmemory/readFromStore.js +2 -2
  16. package/cache/inmemory/writeToStore.js +4 -4
  17. package/core/ApolloClient.d.ts +2 -0
  18. package/core/ApolloClient.d.ts.map +1 -1
  19. package/core/ApolloClient.js +12 -4
  20. package/core/ApolloClient.js.map +1 -1
  21. package/core/LocalState.js +2 -2
  22. package/core/ObservableQuery.js +5 -5
  23. package/core/QueryManager.d.ts +4 -2
  24. package/core/QueryManager.d.ts.map +1 -1
  25. package/core/QueryManager.js +13 -12
  26. package/core/QueryManager.js.map +1 -1
  27. package/core/core.cjs +32 -23
  28. package/core/core.cjs.map +1 -1
  29. package/core/core.cjs.native.js +32 -23
  30. package/dev/dev.cjs +98 -83
  31. package/dev/dev.cjs.map +1 -1
  32. package/dev/dev.cjs.native.js +98 -83
  33. package/dev/loadErrorMessageHandler.js +1 -1
  34. package/dev/loadErrorMessageHandler.js.map +1 -1
  35. package/invariantErrorCodes.js +96 -81
  36. package/link/core/ApolloLink.js +2 -2
  37. package/link/core/core.cjs +2 -2
  38. package/link/core/core.cjs.map +1 -1
  39. package/link/core/core.cjs.native.js +2 -2
  40. package/link/http/checkFetcher.js +1 -1
  41. package/link/http/createHttpLink.js +1 -1
  42. package/link/http/http.cjs +3 -3
  43. package/link/http/http.cjs.map +1 -1
  44. package/link/http/http.cjs.native.js +3 -3
  45. package/link/http/serializeFetchParameter.js +1 -1
  46. package/link/persisted-queries/index.js +2 -2
  47. package/link/persisted-queries/persisted-queries.cjs +2 -2
  48. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  49. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  50. package/link/utils/toPromise.js +1 -1
  51. package/link/utils/utils.cjs +2 -2
  52. package/link/utils/utils.cjs.map +1 -1
  53. package/link/utils/utils.cjs.native.js +2 -2
  54. package/link/utils/validateOperation.js +1 -1
  55. package/package.json +26 -25
  56. package/react/cache/QueryReference.d.ts.map +1 -1
  57. package/react/cache/QueryReference.js +7 -2
  58. package/react/cache/QueryReference.js.map +1 -1
  59. package/react/context/ApolloConsumer.js +1 -1
  60. package/react/context/ApolloContext.js +1 -1
  61. package/react/context/ApolloProvider.js +1 -1
  62. package/react/context/context.cjs +3 -3
  63. package/react/context/context.cjs.map +1 -1
  64. package/react/context/context.cjs.native.js +3 -3
  65. package/react/hoc/hoc-utils.js +1 -1
  66. package/react/hoc/hoc.cjs +2 -2
  67. package/react/hoc/hoc.cjs.map +1 -1
  68. package/react/hoc/hoc.cjs.native.js +2 -2
  69. package/react/hoc/withApollo.js +1 -1
  70. package/react/hooks/hooks.cjs +15 -10
  71. package/react/hooks/hooks.cjs.map +1 -1
  72. package/react/hooks/hooks.cjs.native.js +15 -10
  73. package/react/hooks/index.d.ts +1 -0
  74. package/react/hooks/index.d.ts.map +1 -1
  75. package/react/hooks/index.js.map +1 -1
  76. package/react/hooks/useApolloClient.js +1 -1
  77. package/react/hooks/useQuery.js +1 -1
  78. package/react/hooks/useReadQuery.d.ts +7 -4
  79. package/react/hooks/useReadQuery.d.ts.map +1 -1
  80. package/react/hooks/useReadQuery.js +1 -1
  81. package/react/hooks/useReadQuery.js.map +1 -1
  82. package/react/hooks/useSubscription.js +2 -2
  83. package/react/hooks/useSuspenseQuery.js +2 -2
  84. package/react/hooks/useSyncExternalStore.js +1 -1
  85. package/react/parser/index.js +5 -5
  86. package/react/parser/parser.cjs +5 -5
  87. package/react/parser/parser.cjs.map +1 -1
  88. package/react/parser/parser.cjs.native.js +5 -5
  89. package/testing/core/core.cjs +2 -2
  90. package/testing/core/core.cjs.map +1 -1
  91. package/testing/core/core.cjs.native.js +2 -2
  92. package/testing/core/mocking/mockLink.js +2 -2
  93. package/testing/react/MockedProvider.d.ts +1 -0
  94. package/testing/react/MockedProvider.d.ts.map +1 -1
  95. package/testing/react/MockedProvider.js +2 -1
  96. package/testing/react/MockedProvider.js.map +1 -1
  97. package/testing/testing.cjs +2 -1
  98. package/testing/testing.cjs.map +1 -1
  99. package/testing/testing.cjs.native.js +2 -1
  100. package/utilities/globals/globals.cjs +1 -1
  101. package/utilities/globals/globals.cjs.map +1 -1
  102. package/utilities/globals/globals.cjs.native.js +1 -1
  103. package/utilities/graphql/DocumentTransform.js +1 -1
  104. package/utilities/graphql/directives.js +4 -4
  105. package/utilities/graphql/fragments.js +3 -3
  106. package/utilities/graphql/getFromAST.js +8 -8
  107. package/utilities/graphql/storeUtils.d.ts +5 -0
  108. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  109. package/utilities/graphql/storeUtils.js +1 -1
  110. package/utilities/graphql/storeUtils.js.map +1 -1
  111. package/utilities/graphql/transform.js +2 -2
  112. package/utilities/index.d.ts +1 -1
  113. package/utilities/index.d.ts.map +1 -1
  114. package/utilities/index.js.map +1 -1
  115. package/utilities/subscriptions/relay/index.d.ts +6 -0
  116. package/utilities/subscriptions/relay/index.d.ts.map +1 -0
  117. package/utilities/subscriptions/relay/index.js +43 -0
  118. package/utilities/subscriptions/relay/index.js.map +1 -0
  119. package/utilities/subscriptions/relay/package.json +8 -0
  120. package/utilities/subscriptions/relay/relay.cjs +368 -0
  121. package/utilities/subscriptions/relay/relay.cjs.map +1 -0
  122. package/utilities/subscriptions/relay/relay.cjs.native.js +368 -0
  123. package/utilities/subscriptions/shared.d.ts +9 -0
  124. package/utilities/subscriptions/shared.d.ts.map +1 -0
  125. package/utilities/subscriptions/shared.js +7 -0
  126. package/utilities/subscriptions/shared.js.map +1 -0
  127. package/utilities/subscriptions/urql/index.d.ts +7 -0
  128. package/utilities/subscriptions/urql/index.d.ts.map +1 -0
  129. package/utilities/subscriptions/urql/index.js +40 -0
  130. package/utilities/subscriptions/urql/index.js.map +1 -0
  131. package/utilities/subscriptions/urql/package.json +8 -0
  132. package/utilities/subscriptions/urql/urql.cjs +364 -0
  133. package/utilities/subscriptions/urql/urql.cjs.map +1 -0
  134. package/utilities/subscriptions/urql/urql.cjs.native.js +364 -0
  135. package/utilities/utilities.cjs +19 -19
  136. package/utilities/utilities.cjs.map +1 -1
  137. package/utilities/utilities.cjs.native.js +19 -19
  138. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
 
34
- var version = "3.9.0-alpha.2";
34
+ var version = "3.9.0-alpha.3";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -138,7 +138,7 @@ function shouldInclude(_a, variables) {
138
138
  if (ifArgument.value.kind === "Variable") {
139
139
  evaledValue =
140
140
  variables && variables[ifArgument.value.name.value];
141
- invariant(evaledValue !== void 0, 65, directive.name.value);
141
+ invariant(evaledValue !== void 0, 67, directive.name.value);
142
142
  }
143
143
  else {
144
144
  evaledValue = ifArgument.value.value;
@@ -173,12 +173,12 @@ function getInclusionDirectives(directives) {
173
173
  return;
174
174
  var directiveArguments = directive.arguments;
175
175
  var directiveName = directive.name.value;
176
- invariant(directiveArguments && directiveArguments.length === 1, 66, directiveName);
176
+ invariant(directiveArguments && directiveArguments.length === 1, 68, directiveName);
177
177
  var ifArgument = directiveArguments[0];
178
- invariant(ifArgument.name && ifArgument.name.value === "if", 67, directiveName);
178
+ invariant(ifArgument.name && ifArgument.name.value === "if", 69, directiveName);
179
179
  var ifValue = ifArgument.value;
180
180
  invariant(ifValue &&
181
- (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 68, directiveName);
181
+ (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 70, directiveName);
182
182
  result.push({ directive: directive, ifArgument: ifArgument });
183
183
  });
184
184
  }
@@ -204,7 +204,7 @@ function getFragmentQueryDocument(document, fragmentName) {
204
204
  document.definitions.forEach(function (definition) {
205
205
  if (definition.kind === "OperationDefinition") {
206
206
  throw newInvariantError(
207
- 69,
207
+ 71,
208
208
  definition.operation,
209
209
  definition.name ? " named '".concat(definition.name.value, "'") : ""
210
210
  );
@@ -214,7 +214,7 @@ function getFragmentQueryDocument(document, fragmentName) {
214
214
  }
215
215
  });
216
216
  if (typeof actualFragmentName === "undefined") {
217
- invariant(fragments.length === 1, 70, fragments.length);
217
+ invariant(fragments.length === 1, 72, fragments.length);
218
218
  actualFragmentName = fragments[0].name.value;
219
219
  }
220
220
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -255,7 +255,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
255
255
  return fragmentMap(fragmentName);
256
256
  }
257
257
  var fragment = fragmentMap && fragmentMap[fragmentName];
258
- invariant(fragment, 71, fragmentName);
258
+ invariant(fragment, 73, fragmentName);
259
259
  return fragment || null;
260
260
  }
261
261
  default:
@@ -370,7 +370,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
370
370
  argObj[name.value] = null;
371
371
  }
372
372
  else {
373
- throw newInvariantError(80, name.value, value.kind);
373
+ throw newInvariantError(82, name.value, value.kind);
374
374
  }
375
375
  }
376
376
  function storeKeyNameFromField(field, variables) {
@@ -504,16 +504,16 @@ function isInlineFragment(selection) {
504
504
  }
505
505
 
506
506
  function checkDocument(doc) {
507
- invariant(doc && doc.kind === "Document", 72);
507
+ invariant(doc && doc.kind === "Document", 74);
508
508
  var operations = doc.definitions
509
509
  .filter(function (d) { return d.kind !== "FragmentDefinition"; })
510
510
  .map(function (definition) {
511
511
  if (definition.kind !== "OperationDefinition") {
512
- throw newInvariantError(73, definition.kind);
512
+ throw newInvariantError(75, definition.kind);
513
513
  }
514
514
  return definition;
515
515
  });
516
- invariant(operations.length <= 1, 74, operations.length);
516
+ invariant(operations.length <= 1, 76, operations.length);
517
517
  return doc;
518
518
  }
519
519
  function getOperationDefinition(doc) {
@@ -536,14 +536,14 @@ function getFragmentDefinitions(doc) {
536
536
  }
537
537
  function getQueryDefinition(doc) {
538
538
  var queryDef = getOperationDefinition(doc);
539
- invariant(queryDef && queryDef.operation === "query", 75);
539
+ invariant(queryDef && queryDef.operation === "query", 77);
540
540
  return queryDef;
541
541
  }
542
542
  function getFragmentDefinition(doc) {
543
- invariant(doc.kind === "Document", 76);
544
- invariant(doc.definitions.length <= 1, 77);
543
+ invariant(doc.kind === "Document", 78);
544
+ invariant(doc.definitions.length <= 1, 79);
545
545
  var fragmentDef = doc.definitions[0];
546
- invariant(fragmentDef.kind === "FragmentDefinition", 78);
546
+ invariant(fragmentDef.kind === "FragmentDefinition", 80);
547
547
  return fragmentDef;
548
548
  }
549
549
  function getMainDefinition(queryDoc) {
@@ -566,7 +566,7 @@ function getMainDefinition(queryDoc) {
566
566
  if (fragmentDefinition) {
567
567
  return fragmentDefinition;
568
568
  }
569
- throw newInvariantError(79);
569
+ throw newInvariantError(81);
570
570
  }
571
571
  function getDefaultValues(definition) {
572
572
  var defaultValues = Object.create(null);
@@ -638,7 +638,7 @@ var DocumentTransform = (function () {
638
638
  return;
639
639
  var cacheKeys = this.getCacheKey(document);
640
640
  if (cacheKeys) {
641
- invariant(Array.isArray(cacheKeys), 64);
641
+ invariant(Array.isArray(cacheKeys), 66);
642
642
  return this.stableCacheKeys.lookupArray(cacheKeys);
643
643
  }
644
644
  };
@@ -734,7 +734,7 @@ function removeDirectivesFromDocument(directives, doc) {
734
734
  return getInUseByFragmentName(ancestor.name.value);
735
735
  }
736
736
  }
737
- globalThis.__DEV__ !== false && invariant.error(81);
737
+ globalThis.__DEV__ !== false && invariant.error(83);
738
738
  return null;
739
739
  };
740
740
  var operationCount = 0;
@@ -1387,7 +1387,7 @@ function toPromise(observable) {
1387
1387
  observable.subscribe({
1388
1388
  next: function (data) {
1389
1389
  if (completed) {
1390
- globalThis.__DEV__ !== false && invariant.warn(40);
1390
+ globalThis.__DEV__ !== false && invariant.warn(42);
1391
1391
  }
1392
1392
  else {
1393
1393
  completed = true;
@@ -1430,7 +1430,7 @@ function validateOperation(operation) {
1430
1430
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1431
1431
  var key = _a[_i];
1432
1432
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1433
- throw newInvariantError(41, key);
1433
+ throw newInvariantError(43, key);
1434
1434
  }
1435
1435
  }
1436
1436
  return operation;
@@ -1537,7 +1537,7 @@ var ApolloLink = (function () {
1537
1537
  ApolloLink.concat = function (first, second) {
1538
1538
  var firstLink = toLink(first);
1539
1539
  if (isTerminating(firstLink)) {
1540
- globalThis.__DEV__ !== false && invariant.warn(33, firstLink);
1540
+ globalThis.__DEV__ !== false && invariant.warn(35, firstLink);
1541
1541
  return firstLink;
1542
1542
  }
1543
1543
  var nextLink = toLink(second);
@@ -1561,7 +1561,7 @@ var ApolloLink = (function () {
1561
1561
  return ApolloLink.concat(this, next);
1562
1562
  };
1563
1563
  ApolloLink.prototype.request = function (operation, forward) {
1564
- throw newInvariantError(34);
1564
+ throw newInvariantError(36);
1565
1565
  };
1566
1566
  ApolloLink.prototype.onError = function (error, observer) {
1567
1567
  if (observer && observer.error) {
@@ -1938,7 +1938,7 @@ var serializeFetchParameter = function (p, label) {
1938
1938
  serialized = JSON.stringify(p);
1939
1939
  }
1940
1940
  catch (e) {
1941
- var parseError = newInvariantError(37, label, e.message);
1941
+ var parseError = newInvariantError(39, label, e.message);
1942
1942
  parseError.parseError = e;
1943
1943
  throw parseError;
1944
1944
  }
@@ -2024,7 +2024,7 @@ function removeDuplicateHeaders(headers, preserveHeaderCase) {
2024
2024
 
2025
2025
  var checkFetcher = function (fetcher) {
2026
2026
  if (!fetcher && typeof fetch === "undefined") {
2027
- throw newInvariantError(35);
2027
+ throw newInvariantError(37);
2028
2028
  }
2029
2029
  };
2030
2030
 
@@ -2157,7 +2157,7 @@ var createHttpLink = function (linkOptions) {
2157
2157
  options.headers = options.headers || {};
2158
2158
  var acceptHeader = "multipart/mixed;";
2159
2159
  if (isSubscription && hasDefer) {
2160
- globalThis.__DEV__ !== false && invariant.warn(36);
2160
+ globalThis.__DEV__ !== false && invariant.warn(38);
2161
2161
  }
2162
2162
  if (isSubscription) {
2163
2163
  acceptHeader +=
@@ -2584,6 +2584,41 @@ var EntityStore = (function () {
2584
2584
  changedFields_1[storeFieldName] = newValue;
2585
2585
  needToMerge_1 = true;
2586
2586
  fieldValue = newValue;
2587
+ if (globalThis.__DEV__ !== false) {
2588
+ var checkReference = function (ref) {
2589
+ if (_this.lookup(ref.__ref) === undefined) {
2590
+ globalThis.__DEV__ !== false && invariant.warn(2, ref);
2591
+ return true;
2592
+ }
2593
+ };
2594
+ if (isReference(newValue)) {
2595
+ checkReference(newValue);
2596
+ }
2597
+ else if (Array.isArray(newValue)) {
2598
+ var seenReference = false;
2599
+ var someNonReference = void 0;
2600
+ for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
2601
+ var value = newValue_1[_i];
2602
+ if (isReference(value)) {
2603
+ seenReference = true;
2604
+ if (checkReference(value))
2605
+ break;
2606
+ }
2607
+ else {
2608
+ if (typeof value === "object" && !!value) {
2609
+ var id = _this.policies.identify(value)[0];
2610
+ if (id) {
2611
+ someNonReference = value;
2612
+ }
2613
+ }
2614
+ }
2615
+ if (seenReference && someNonReference !== undefined) {
2616
+ globalThis.__DEV__ !== false && invariant.warn(3, someNonReference);
2617
+ break;
2618
+ }
2619
+ }
2620
+ }
2621
+ }
2587
2622
  }
2588
2623
  }
2589
2624
  }
@@ -3153,7 +3188,7 @@ var StoreReader = (function () {
3153
3188
  else {
3154
3189
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
3155
3190
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
3156
- throw newInvariantError(7, selection.name.value);
3191
+ throw newInvariantError(9, selection.name.value);
3157
3192
  }
3158
3193
  if (fragment && policies.fragmentMatches(fragment, typename)) {
3159
3194
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
@@ -3237,7 +3272,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
3237
3272
  if (isNonNullObject(value)) {
3238
3273
  invariant(
3239
3274
  !isReference(value),
3240
- 8,
3275
+ 10,
3241
3276
  getTypenameFromStoreObject(store, value),
3242
3277
  field.name.value
3243
3278
  );
@@ -3329,7 +3364,7 @@ function keyFieldsFnFromSpecifier(specifier) {
3329
3364
  hasOwn.call(object, schemaKeyPath[0])) {
3330
3365
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
3331
3366
  }
3332
- invariant(extracted !== void 0, 2, schemaKeyPath.join("."), object);
3367
+ invariant(extracted !== void 0, 4, schemaKeyPath.join("."), object);
3333
3368
  return extracted;
3334
3369
  }));
3335
3370
  return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
@@ -3583,7 +3618,7 @@ var Policies = (function () {
3583
3618
  var rootId = "ROOT_" + which.toUpperCase();
3584
3619
  var old = this.rootTypenamesById[rootId];
3585
3620
  if (typename !== old) {
3586
- invariant(!old || old === which, 3, which);
3621
+ invariant(!old || old === which, 5, which);
3587
3622
  if (old)
3588
3623
  delete this.rootIdsByTypename[old];
3589
3624
  this.rootIdsByTypename[typename] = rootId;
@@ -3680,7 +3715,7 @@ var Policies = (function () {
3680
3715
  if (supertypeSet.has(supertype)) {
3681
3716
  if (!typenameSupertypeSet.has(supertype)) {
3682
3717
  if (checkingFuzzySubtypes) {
3683
- globalThis.__DEV__ !== false && invariant.warn(4, typename, supertype);
3718
+ globalThis.__DEV__ !== false && invariant.warn(6, typename, supertype);
3684
3719
  }
3685
3720
  typenameSupertypeSet.add(supertype);
3686
3721
  }
@@ -3842,7 +3877,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3842
3877
  }
3843
3878
  }
3844
3879
  if (globalThis.__DEV__ !== false && options.from === void 0) {
3845
- globalThis.__DEV__ !== false && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
3880
+ globalThis.__DEV__ !== false && invariant.warn(7, stringifyForDisplay(Array.from(readFieldArgs)));
3846
3881
  }
3847
3882
  if (void 0 === options.variables) {
3848
3883
  options.variables = variables;
@@ -3852,7 +3887,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3852
3887
  function makeMergeObjectsFunction(store) {
3853
3888
  return function mergeObjects(existing, incoming) {
3854
3889
  if (isArray(existing) || isArray(incoming)) {
3855
- throw newInvariantError(6);
3890
+ throw newInvariantError(8);
3856
3891
  }
3857
3892
  if (isNonNullObject(existing) && isNonNullObject(incoming)) {
3858
3893
  var eType = store.getFieldValue(existing, "__typename");
@@ -3912,7 +3947,7 @@ var StoreWriter = (function () {
3912
3947
  context: context,
3913
3948
  });
3914
3949
  if (!isReference(ref)) {
3915
- throw newInvariantError(9, result);
3950
+ throw newInvariantError(11, result);
3916
3951
  }
3917
3952
  context.incomingById.forEach(function (_a, dataId) {
3918
3953
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -4017,7 +4052,7 @@ var StoreWriter = (function () {
4017
4052
  !context.deferred &&
4018
4053
  !addTypenameToDocument.added(field) &&
4019
4054
  !policies.getReadFunction(typename, field.name.value)) {
4020
- globalThis.__DEV__ !== false && invariant.error(10, resultKeyNameFromField(field), result);
4055
+ globalThis.__DEV__ !== false && invariant.error(12, resultKeyNameFromField(field), result);
4021
4056
  }
4022
4057
  });
4023
4058
  try {
@@ -4122,7 +4157,7 @@ var StoreWriter = (function () {
4122
4157
  else {
4123
4158
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
4124
4159
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
4125
- throw newInvariantError(11, selection.name.value);
4160
+ throw newInvariantError(13, selection.name.value);
4126
4161
  }
4127
4162
  if (fragment &&
4128
4163
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -4264,7 +4299,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
4264
4299
  }
4265
4300
  });
4266
4301
  }
4267
- globalThis.__DEV__ !== false && invariant.warn(12, fieldName, parentType, childTypenames.length
4302
+ globalThis.__DEV__ !== false && invariant.warn(14, fieldName, parentType, childTypenames.length
4268
4303
  ? "either ensure all objects of type " +
4269
4304
  childTypenames.join(" and ") +
4270
4305
  " have an ID or a custom merge function, or "
@@ -4825,7 +4860,7 @@ var ObservableQuery = (function (_super) {
4825
4860
  var vars = queryDef.variableDefinitions;
4826
4861
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4827
4862
  globalThis.__DEV__ !== false && invariant.warn(
4828
- 18,
4863
+ 20,
4829
4864
  variables,
4830
4865
  ((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || queryDef
4831
4866
  );
@@ -4923,7 +4958,7 @@ var ObservableQuery = (function (_super) {
4923
4958
  options.onError(err);
4924
4959
  return;
4925
4960
  }
4926
- globalThis.__DEV__ !== false && invariant.error(19, err);
4961
+ globalThis.__DEV__ !== false && invariant.error(21, err);
4927
4962
  },
4928
4963
  });
4929
4964
  this.subscriptions.add(subscription);
@@ -5022,7 +5057,7 @@ var ObservableQuery = (function (_super) {
5022
5057
  if (pollingInfo && pollingInfo.interval === pollInterval) {
5023
5058
  return;
5024
5059
  }
5025
- invariant(pollInterval, 20);
5060
+ invariant(pollInterval, 22);
5026
5061
  var info = pollingInfo || (this.pollingInfo = {});
5027
5062
  info.interval = pollInterval;
5028
5063
  var maybeFetch = function () {
@@ -5187,11 +5222,11 @@ function reobserveCacheFirst(obsQuery) {
5187
5222
  return obsQuery.reobserve();
5188
5223
  }
5189
5224
  function defaultSubscriptionObserverErrorCallback(error) {
5190
- globalThis.__DEV__ !== false && invariant.error(21, error.message, error.stack);
5225
+ globalThis.__DEV__ !== false && invariant.error(23, error.message, error.stack);
5191
5226
  }
5192
5227
  function logMissingFieldErrors(missing) {
5193
5228
  if (globalThis.__DEV__ !== false && missing) {
5194
- globalThis.__DEV__ !== false && invariant.debug(22, missing);
5229
+ globalThis.__DEV__ !== false && invariant.debug(24, missing);
5195
5230
  }
5196
5231
  }
5197
5232
  function skipCacheDataFor(fetchPolicy) {
@@ -5376,7 +5411,7 @@ var LocalState = (function () {
5376
5411
  }
5377
5412
  else {
5378
5413
  fragment = fragmentMap[selection.name.value];
5379
- invariant(fragment, 16, selection.name.value);
5414
+ invariant(fragment, 18, selection.name.value);
5380
5415
  }
5381
5416
  if (fragment && fragment.typeCondition) {
5382
5417
  typeCondition = fragment.typeCondition.name.value;
@@ -5489,7 +5524,7 @@ var LocalState = (function () {
5489
5524
  },
5490
5525
  FragmentSpread: function (spread, _, __, ___, ancestors) {
5491
5526
  var fragment = fragmentMap[spread.name.value];
5492
- invariant(fragment, 17, spread.name.value);
5527
+ invariant(fragment, 19, spread.name.value);
5493
5528
  var fragmentSelections = collectByDefinition(fragment);
5494
5529
  if (fragmentSelections.size > 0) {
5495
5530
  ancestors.forEach(function (node) {
@@ -5787,7 +5822,7 @@ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
5787
5822
  var QueryManager = (function () {
5788
5823
  function QueryManager(_a) {
5789
5824
  var _this = this;
5790
- var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e;
5825
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e, defaultContext = _a.defaultContext;
5791
5826
  this.clientAwareness = {};
5792
5827
  this.queries = new Map();
5793
5828
  this.fetchCancelFns = new Map();
@@ -5810,6 +5845,7 @@ var QueryManager = (function () {
5810
5845
  .concat(documentTransform)
5811
5846
  .concat(defaultDocumentTransform)
5812
5847
  : defaultDocumentTransform;
5848
+ this.defaultContext = defaultContext || Object.create(null);
5813
5849
  if ((this.onBroadcast = onBroadcast)) {
5814
5850
  this.mutationStore = Object.create(null);
5815
5851
  }
@@ -5819,7 +5855,7 @@ var QueryManager = (function () {
5819
5855
  this.queries.forEach(function (_info, queryId) {
5820
5856
  _this.stopQueryNoBroadcast(queryId);
5821
5857
  });
5822
- this.cancelPendingFetches(newInvariantError(23));
5858
+ this.cancelPendingFetches(newInvariantError(25));
5823
5859
  };
5824
5860
  QueryManager.prototype.cancelPendingFetches = function (error) {
5825
5861
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -5833,8 +5869,8 @@ var QueryManager = (function () {
5833
5869
  return tslib.__generator(this, function (_h) {
5834
5870
  switch (_h.label) {
5835
5871
  case 0:
5836
- invariant(mutation, 24);
5837
- invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 25);
5872
+ invariant(mutation, 26);
5873
+ invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
5838
5874
  mutationId = this.generateMutationId();
5839
5875
  mutation = this.cache.transformForLink(this.transform(mutation));
5840
5876
  hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
@@ -6155,10 +6191,10 @@ var QueryManager = (function () {
6155
6191
  QueryManager.prototype.query = function (options, queryId) {
6156
6192
  var _this = this;
6157
6193
  if (queryId === void 0) { queryId = this.generateQueryId(); }
6158
- invariant(options.query, 26);
6159
- invariant(options.query.kind === "Document", 27);
6160
- invariant(!options.returnPartialData, 28);
6161
- invariant(!options.pollInterval, 29);
6194
+ invariant(options.query, 28);
6195
+ invariant(options.query.kind === "Document", 29);
6196
+ invariant(!options.returnPartialData, 30);
6197
+ invariant(!options.pollInterval, 31);
6162
6198
  return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
6163
6199
  };
6164
6200
  QueryManager.prototype.generateQueryId = function () {
@@ -6183,7 +6219,7 @@ var QueryManager = (function () {
6183
6219
  if (options === void 0) { options = {
6184
6220
  discardWatches: true,
6185
6221
  }; }
6186
- this.cancelPendingFetches(newInvariantError(30));
6222
+ this.cancelPendingFetches(newInvariantError(32));
6187
6223
  this.queries.forEach(function (queryInfo) {
6188
6224
  if (queryInfo.observableQuery) {
6189
6225
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -6259,7 +6295,7 @@ var QueryManager = (function () {
6259
6295
  if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
6260
6296
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
6261
6297
  if (!included) {
6262
- globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 31 : 32, nameOrDoc);
6298
+ globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
6263
6299
  }
6264
6300
  });
6265
6301
  }
@@ -6415,7 +6451,7 @@ var QueryManager = (function () {
6415
6451
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
6416
6452
  var requestId = (queryInfo.lastRequestId = this.generateRequestId());
6417
6453
  var linkDocument = this.cache.transformForLink(options.query);
6418
- return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
6454
+ return asyncMap(this.getObservableFromLink(linkDocument, compact(this.defaultContext, options.context), options.variables), function (result) {
6419
6455
  var graphQLErrors = getGraphQLErrorsFromResult(result);
6420
6456
  var hasErrors = graphQLErrors.length > 0;
6421
6457
  if (requestId >= queryInfo.lastRequestId) {
@@ -6696,11 +6732,11 @@ var ApolloClient = (function () {
6696
6732
  this.resetStoreCallbacks = [];
6697
6733
  this.clearStoreCallbacks = [];
6698
6734
  if (!options.cache) {
6699
- throw newInvariantError(13);
6735
+ throw newInvariantError(15);
6700
6736
  }
6701
6737
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === "object" &&
6702
6738
  !window.__APOLLO_CLIENT__ &&
6703
- globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6739
+ globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6704
6740
  var link = options.link;
6705
6741
  if (!link) {
6706
6742
  link = uri
@@ -6732,6 +6768,7 @@ var ApolloClient = (function () {
6732
6768
  cache: this.cache,
6733
6769
  link: this.link,
6734
6770
  defaultOptions: this.defaultOptions,
6771
+ defaultContext: defaultContext,
6735
6772
  documentTransform: documentTransform,
6736
6773
  queryDeduplication: queryDeduplication,
6737
6774
  ssrMode: ssrMode,
@@ -6821,7 +6858,7 @@ var ApolloClient = (function () {
6821
6858
  if (this.defaultOptions.query) {
6822
6859
  options = mergeOptions(this.defaultOptions.query, options);
6823
6860
  }
6824
- invariant(options.fetchPolicy !== "cache-and-network", 14);
6861
+ invariant(options.fetchPolicy !== "cache-and-network", 16);
6825
6862
  if (this.disableNetworkFetches && options.fetchPolicy === "network-only") {
6826
6863
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "cache-first" });
6827
6864
  }
@@ -6914,7 +6951,7 @@ var ApolloClient = (function () {
6914
6951
  result.queries = queries;
6915
6952
  result.results = results;
6916
6953
  result.catch(function (error) {
6917
- globalThis.__DEV__ !== false && invariant.debug(15, error);
6954
+ globalThis.__DEV__ !== false && invariant.debug(17, error);
6918
6955
  });
6919
6956
  return result;
6920
6957
  };
@@ -6943,6 +6980,13 @@ var ApolloClient = (function () {
6943
6980
  ApolloClient.prototype.setLink = function (newLink) {
6944
6981
  this.link = this.queryManager.link = newLink;
6945
6982
  };
6983
+ Object.defineProperty(ApolloClient.prototype, "defaultContext", {
6984
+ get: function () {
6985
+ return this.queryManager.defaultContext;
6986
+ },
6987
+ enumerable: false,
6988
+ configurable: true
6989
+ });
6946
6990
  return ApolloClient;
6947
6991
  }());
6948
6992
 
@@ -6950,7 +6994,7 @@ var contextKey = canUseSymbol
6950
6994
  ? Symbol.for("__APOLLO_CONTEXT__")
6951
6995
  : "__APOLLO_CONTEXT__";
6952
6996
  function getApolloContext() {
6953
- invariant("createContext" in React__namespace, 43);
6997
+ invariant("createContext" in React__namespace, 45);
6954
6998
  var context = React__namespace.createContext[contextKey];
6955
6999
  if (!context) {
6956
7000
  Object.defineProperty(React__namespace.createContext, contextKey, {
@@ -6968,7 +7012,7 @@ var resetApolloContext = getApolloContext;
6968
7012
  var ApolloConsumer = function (props) {
6969
7013
  var ApolloContext = getApolloContext();
6970
7014
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6971
- invariant(context && context.client, 42);
7015
+ invariant(context && context.client, 44);
6972
7016
  return props.children(context.client);
6973
7017
  }));
6974
7018
  };
@@ -6980,14 +7024,14 @@ var ApolloProvider = function (_a) {
6980
7024
  var context = React__namespace.useMemo(function () {
6981
7025
  return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client });
6982
7026
  }, [parentContext, client]);
6983
- invariant(context.client, 44);
7027
+ invariant(context.client, 46);
6984
7028
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6985
7029
  };
6986
7030
 
6987
7031
  function useApolloClient(override) {
6988
7032
  var context = React__namespace.useContext(getApolloContext());
6989
7033
  var client = override || context.client;
6990
- invariant(!!client, 47);
7034
+ invariant(!!client, 49);
6991
7035
  return client;
6992
7036
  }
6993
7037
 
@@ -7001,7 +7045,7 @@ var useSyncExternalStore = realHook$1 ||
7001
7045
  !didWarnUncachedGetSnapshot &&
7002
7046
  value !== getSnapshot()) {
7003
7047
  didWarnUncachedGetSnapshot = true;
7004
- globalThis.__DEV__ !== false && invariant.error(56);
7048
+ globalThis.__DEV__ !== false && invariant.error(58);
7005
7049
  }
7006
7050
  var _a = React__namespace.useState({
7007
7051
  inst: { value: value, getSnapshot: getSnapshot },
@@ -7066,7 +7110,7 @@ function parser(document) {
7066
7110
  if (cached)
7067
7111
  return cached;
7068
7112
  var variables, type, name;
7069
- invariant(!!document && !!document.kind, 57, document);
7113
+ invariant(!!document && !!document.kind, 59, document);
7070
7114
  var fragments = [];
7071
7115
  var queries = [];
7072
7116
  var mutations = [];
@@ -7094,10 +7138,10 @@ function parser(document) {
7094
7138
  invariant(!fragments.length ||
7095
7139
  queries.length ||
7096
7140
  mutations.length ||
7097
- subscriptions.length, 58);
7141
+ subscriptions.length, 60);
7098
7142
  invariant(
7099
7143
  queries.length + mutations.length + subscriptions.length <= 1,
7100
- 59,
7144
+ 61,
7101
7145
  document,
7102
7146
  queries.length,
7103
7147
  subscriptions.length,
@@ -7111,7 +7155,7 @@ function parser(document) {
7111
7155
  : mutations.length
7112
7156
  ? mutations
7113
7157
  : subscriptions;
7114
- invariant(definitions.length === 1, 60, document, definitions.length);
7158
+ invariant(definitions.length === 1, 62, document, definitions.length);
7115
7159
  var definition = definitions[0];
7116
7160
  variables = definition.variableDefinitions || [];
7117
7161
  if (definition.name && definition.name.kind === "Name") {
@@ -7130,7 +7174,7 @@ function verifyDocumentType(document, type) {
7130
7174
  var usedOperationName = operationName(operation.type);
7131
7175
  invariant(
7132
7176
  operation.type === type,
7133
- 61,
7177
+ 63,
7134
7178
  requiredOperationName,
7135
7179
  requiredOperationName,
7136
7180
  usedOperationName
@@ -7180,7 +7224,7 @@ var InternalState = (function () {
7180
7224
  }
7181
7225
  }
7182
7226
  InternalState.prototype.forceUpdateState = function () {
7183
- globalThis.__DEV__ !== false && invariant.warn(48);
7227
+ globalThis.__DEV__ !== false && invariant.warn(50);
7184
7228
  };
7185
7229
  InternalState.prototype.executeQuery = function (options) {
7186
7230
  var _this = this;
@@ -7601,10 +7645,10 @@ function useSubscription(subscription, options) {
7601
7645
  if (!hasIssuedDeprecationWarningRef.current) {
7602
7646
  hasIssuedDeprecationWarningRef.current = true;
7603
7647
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
7604
- globalThis.__DEV__ !== false && invariant.warn(options.onData ? 50 : 51);
7648
+ globalThis.__DEV__ !== false && invariant.warn(options.onData ? 52 : 53);
7605
7649
  }
7606
7650
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
7607
- globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 52 : 53);
7651
+ globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 54 : 55);
7608
7652
  }
7609
7653
  }
7610
7654
  var _b = React__namespace.useState(function () {
@@ -7821,7 +7865,6 @@ var OBSERVED_CHANGED_OPTIONS = [
7821
7865
  var InternalQueryReference = (function () {
7822
7866
  function InternalQueryReference(observable, options) {
7823
7867
  var _this = this;
7824
- var _a;
7825
7868
  this.listeners = new Set();
7826
7869
  this.status = "loading";
7827
7870
  this.references = 0;
@@ -7855,7 +7898,13 @@ var InternalQueryReference = (function () {
7855
7898
  next: this.handleNext,
7856
7899
  error: this.handleError,
7857
7900
  });
7858
- this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
7901
+ var startDisposeTimer = function () {
7902
+ var _a;
7903
+ if (!_this.references) {
7904
+ _this.autoDisposeTimeoutId = setTimeout(_this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
7905
+ }
7906
+ };
7907
+ this.promise.then(startDisposeTimer, startDisposeTimer);
7859
7908
  }
7860
7909
  Object.defineProperty(InternalQueryReference.prototype, "watchQueryOptions", {
7861
7910
  get: function () {
@@ -8110,11 +8159,11 @@ function validateFetchPolicy(fetchPolicy) {
8110
8159
  "no-cache",
8111
8160
  "cache-and-network",
8112
8161
  ];
8113
- invariant(supportedFetchPolicies.includes(fetchPolicy), 54, fetchPolicy);
8162
+ invariant(supportedFetchPolicies.includes(fetchPolicy), 56, fetchPolicy);
8114
8163
  }
8115
8164
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
8116
8165
  if (fetchPolicy === "no-cache" && returnPartialData) {
8117
- globalThis.__DEV__ !== false && invariant.warn(55);
8166
+ globalThis.__DEV__ !== false && invariant.warn(57);
8118
8167
  }
8119
8168
  }
8120
8169
  function toApolloError(result) {
@@ -8189,7 +8238,7 @@ function useBackgroundQuery(query, options) {
8189
8238
 
8190
8239
  function useReadQuery(queryRef) {
8191
8240
  var internalQueryRef = unwrapQueryRef(queryRef);
8192
- invariant(internalQueryRef.promiseCache, 49);
8241
+ invariant(internalQueryRef.promiseCache, 51);
8193
8242
  var promiseCache = internalQueryRef.promiseCache, key = internalQueryRef.key;
8194
8243
  if (!promiseCache.has(key)) {
8195
8244
  promiseCache.set(key, internalQueryRef.promise);