@apollo/client 3.9.0-alpha.1 → 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 (180) hide show
  1. package/apollo-client.cjs +221 -180
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +52 -40
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +52 -40
  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/index.d.ts +1 -2
  11. package/cache/index.d.ts.map +1 -1
  12. package/cache/index.js +1 -2
  13. package/cache/index.js.map +1 -1
  14. package/cache/inmemory/entityStore.d.ts.map +1 -1
  15. package/cache/inmemory/entityStore.js +35 -0
  16. package/cache/inmemory/entityStore.js.map +1 -1
  17. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  18. package/cache/inmemory/inMemoryCache.js +1 -2
  19. package/cache/inmemory/inMemoryCache.js.map +1 -1
  20. package/cache/inmemory/key-extractor.js +1 -1
  21. package/cache/inmemory/object-canon.d.ts +0 -5
  22. package/cache/inmemory/object-canon.d.ts.map +1 -1
  23. package/cache/inmemory/object-canon.js +0 -22
  24. package/cache/inmemory/object-canon.js.map +1 -1
  25. package/cache/inmemory/policies.d.ts.map +1 -1
  26. package/cache/inmemory/policies.js +4 -6
  27. package/cache/inmemory/policies.js.map +1 -1
  28. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  29. package/cache/inmemory/readFromStore.js +4 -4
  30. package/cache/inmemory/readFromStore.js.map +1 -1
  31. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  32. package/cache/inmemory/writeToStore.js +5 -6
  33. package/cache/inmemory/writeToStore.js.map +1 -1
  34. package/core/ApolloClient.d.ts +2 -0
  35. package/core/ApolloClient.d.ts.map +1 -1
  36. package/core/ApolloClient.js +12 -4
  37. package/core/ApolloClient.js.map +1 -1
  38. package/core/LocalState.js +2 -2
  39. package/core/ObservableQuery.d.ts.map +1 -1
  40. package/core/ObservableQuery.js +10 -11
  41. package/core/ObservableQuery.js.map +1 -1
  42. package/core/QueryInfo.d.ts +0 -2
  43. package/core/QueryInfo.d.ts.map +1 -1
  44. package/core/QueryInfo.js +0 -2
  45. package/core/QueryInfo.js.map +1 -1
  46. package/core/QueryManager.d.ts +4 -2
  47. package/core/QueryManager.d.ts.map +1 -1
  48. package/core/QueryManager.js +15 -14
  49. package/core/QueryManager.js.map +1 -1
  50. package/core/core.cjs +39 -33
  51. package/core/core.cjs.map +1 -1
  52. package/core/core.cjs.native.js +39 -33
  53. package/dev/dev.cjs +125 -101
  54. package/dev/dev.cjs.map +1 -1
  55. package/dev/dev.cjs.native.js +125 -101
  56. package/dev/loadErrorMessageHandler.js +2 -2
  57. package/dev/loadErrorMessageHandler.js.map +1 -1
  58. package/invariantErrorCodes.js +96 -81
  59. package/link/core/ApolloLink.js +2 -2
  60. package/link/core/core.cjs +2 -2
  61. package/link/core/core.cjs.map +1 -1
  62. package/link/core/core.cjs.native.js +2 -2
  63. package/link/http/checkFetcher.js +1 -1
  64. package/link/http/createHttpLink.js +1 -1
  65. package/link/http/http.cjs +3 -3
  66. package/link/http/http.cjs.map +1 -1
  67. package/link/http/http.cjs.native.js +3 -3
  68. package/link/http/serializeFetchParameter.js +1 -1
  69. package/link/persisted-queries/index.js +2 -2
  70. package/link/persisted-queries/persisted-queries.cjs +2 -2
  71. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  72. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  73. package/link/utils/toPromise.js +1 -1
  74. package/link/utils/utils.cjs +2 -2
  75. package/link/utils/utils.cjs.map +1 -1
  76. package/link/utils/utils.cjs.native.js +2 -2
  77. package/link/utils/validateOperation.js +1 -1
  78. package/package.json +27 -26
  79. package/react/cache/QueryReference.d.ts.map +1 -1
  80. package/react/cache/QueryReference.js +7 -2
  81. package/react/cache/QueryReference.js.map +1 -1
  82. package/react/context/ApolloConsumer.js +1 -1
  83. package/react/context/ApolloContext.js +1 -1
  84. package/react/context/ApolloProvider.js +1 -1
  85. package/react/context/context.cjs +3 -3
  86. package/react/context/context.cjs.map +1 -1
  87. package/react/context/context.cjs.native.js +3 -3
  88. package/react/hoc/hoc-utils.js +1 -1
  89. package/react/hoc/hoc.cjs +2 -2
  90. package/react/hoc/hoc.cjs.map +1 -1
  91. package/react/hoc/hoc.cjs.native.js +2 -2
  92. package/react/hoc/withApollo.js +1 -1
  93. package/react/hooks/hooks.cjs +15 -10
  94. package/react/hooks/hooks.cjs.map +1 -1
  95. package/react/hooks/hooks.cjs.native.js +15 -10
  96. package/react/hooks/index.d.ts +1 -0
  97. package/react/hooks/index.d.ts.map +1 -1
  98. package/react/hooks/index.js.map +1 -1
  99. package/react/hooks/useApolloClient.js +1 -1
  100. package/react/hooks/useQuery.js +1 -1
  101. package/react/hooks/useReadQuery.d.ts +7 -4
  102. package/react/hooks/useReadQuery.d.ts.map +1 -1
  103. package/react/hooks/useReadQuery.js +1 -1
  104. package/react/hooks/useReadQuery.js.map +1 -1
  105. package/react/hooks/useSubscription.js +2 -2
  106. package/react/hooks/useSuspenseQuery.js +2 -2
  107. package/react/hooks/useSyncExternalStore.js +1 -1
  108. package/react/parser/index.js +5 -5
  109. package/react/parser/parser.cjs +5 -5
  110. package/react/parser/parser.cjs.map +1 -1
  111. package/react/parser/parser.cjs.native.js +5 -5
  112. package/testing/core/core.cjs +2 -2
  113. package/testing/core/core.cjs.map +1 -1
  114. package/testing/core/core.cjs.native.js +2 -2
  115. package/testing/core/mocking/mockLink.js +2 -2
  116. package/testing/internal/ObservableStream.d.ts +26 -0
  117. package/testing/internal/ObservableStream.d.ts.map +1 -0
  118. package/testing/internal/ObservableStream.js +101 -0
  119. package/testing/internal/ObservableStream.js.map +1 -0
  120. package/testing/internal/index.d.ts +1 -0
  121. package/testing/internal/index.d.ts.map +1 -1
  122. package/testing/internal/index.js +1 -0
  123. package/testing/internal/index.js.map +1 -1
  124. package/testing/react/MockedProvider.d.ts +1 -0
  125. package/testing/react/MockedProvider.d.ts.map +1 -1
  126. package/testing/react/MockedProvider.js +2 -1
  127. package/testing/react/MockedProvider.js.map +1 -1
  128. package/testing/testing.cjs +2 -1
  129. package/testing/testing.cjs.map +1 -1
  130. package/testing/testing.cjs.native.js +2 -1
  131. package/utilities/common/canonicalStringify.d.ts +4 -0
  132. package/utilities/common/canonicalStringify.d.ts.map +1 -0
  133. package/utilities/common/canonicalStringify.js +37 -0
  134. package/utilities/common/canonicalStringify.js.map +1 -0
  135. package/utilities/globals/globals.cjs +29 -19
  136. package/utilities/globals/globals.cjs.map +1 -1
  137. package/utilities/globals/globals.cjs.native.js +29 -19
  138. package/utilities/globals/invariantWrappers.d.ts.map +1 -1
  139. package/utilities/globals/invariantWrappers.js +28 -18
  140. package/utilities/globals/invariantWrappers.js.map +1 -1
  141. package/utilities/graphql/DocumentTransform.js +1 -1
  142. package/utilities/graphql/directives.js +4 -4
  143. package/utilities/graphql/fragments.js +3 -3
  144. package/utilities/graphql/getFromAST.js +8 -8
  145. package/utilities/graphql/storeUtils.d.ts +7 -2
  146. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  147. package/utilities/graphql/storeUtils.js +8 -20
  148. package/utilities/graphql/storeUtils.js.map +1 -1
  149. package/utilities/graphql/transform.js +2 -2
  150. package/utilities/index.d.ts +2 -1
  151. package/utilities/index.d.ts.map +1 -1
  152. package/utilities/index.js +1 -0
  153. package/utilities/index.js.map +1 -1
  154. package/utilities/observables/asyncMap.d.ts.map +1 -1
  155. package/utilities/observables/asyncMap.js +17 -34
  156. package/utilities/observables/asyncMap.js.map +1 -1
  157. package/utilities/subscriptions/relay/index.d.ts +6 -0
  158. package/utilities/subscriptions/relay/index.d.ts.map +1 -0
  159. package/utilities/subscriptions/relay/index.js +43 -0
  160. package/utilities/subscriptions/relay/index.js.map +1 -0
  161. package/utilities/subscriptions/relay/package.json +8 -0
  162. package/utilities/subscriptions/relay/relay.cjs +368 -0
  163. package/utilities/subscriptions/relay/relay.cjs.map +1 -0
  164. package/utilities/subscriptions/relay/relay.cjs.native.js +368 -0
  165. package/utilities/subscriptions/shared.d.ts +9 -0
  166. package/utilities/subscriptions/shared.d.ts.map +1 -0
  167. package/utilities/subscriptions/shared.js +7 -0
  168. package/utilities/subscriptions/shared.js.map +1 -0
  169. package/utilities/subscriptions/urql/index.d.ts +7 -0
  170. package/utilities/subscriptions/urql/index.d.ts.map +1 -0
  171. package/utilities/subscriptions/urql/index.js +40 -0
  172. package/utilities/subscriptions/urql/index.js.map +1 -0
  173. package/utilities/subscriptions/urql/package.json +8 -0
  174. package/utilities/subscriptions/urql/urql.cjs +364 -0
  175. package/utilities/subscriptions/urql/urql.cjs.map +1 -0
  176. package/utilities/subscriptions/urql/urql.cjs.native.js +364 -0
  177. package/utilities/utilities.cjs +80 -72
  178. package/utilities/utilities.cjs.map +1 -1
  179. package/utilities/utilities.cjs.native.js +80 -72
  180. 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.1";
34
+ var version = "3.9.0-alpha.3";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -71,11 +71,14 @@ function wrap(fn) {
71
71
  args[_i - 1] = arguments[_i];
72
72
  }
73
73
  if (typeof message === "number") {
74
- fn(getErrorMsg(message, args));
75
- }
76
- else {
77
- fn.apply(void 0, tslib.__spreadArray([message], args, false));
74
+ var arg0 = message;
75
+ message = getHandledErrorMsg(arg0);
76
+ if (!message) {
77
+ message = getFallbackErrorMsg(arg0, args);
78
+ args = [];
79
+ }
78
80
  }
81
+ fn.apply(void 0, [message].concat(args));
79
82
  };
80
83
  }
81
84
  var invariant = Object.assign(function invariant(condition, message) {
@@ -84,7 +87,7 @@ var invariant = Object.assign(function invariant(condition, message) {
84
87
  args[_i - 2] = arguments[_i];
85
88
  }
86
89
  if (!condition) {
87
- tsInvariant.invariant(condition, getErrorMsg(message, args));
90
+ tsInvariant.invariant(condition, getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args));
88
91
  }
89
92
  }, {
90
93
  debug: wrap(tsInvariant.invariant.debug),
@@ -97,23 +100,31 @@ function newInvariantError(message) {
97
100
  for (var _i = 1; _i < arguments.length; _i++) {
98
101
  optionalParams[_i - 1] = arguments[_i];
99
102
  }
100
- return new tsInvariant.InvariantError(getErrorMsg(message, optionalParams));
103
+ return new tsInvariant.InvariantError(getHandledErrorMsg(message, optionalParams) ||
104
+ getFallbackErrorMsg(message, optionalParams));
101
105
  }
102
106
  var ApolloErrorMessageHandler = Symbol.for("ApolloErrorMessageHandler_" + version);
103
- function getErrorMsg(message, messageArgs) {
107
+ function stringify(arg) {
108
+ return typeof arg == "string"
109
+ ? arg
110
+ : stringifyForDisplay(arg, 2).slice(0, 1000);
111
+ }
112
+ function getHandledErrorMsg(message, messageArgs) {
104
113
  if (messageArgs === void 0) { messageArgs = []; }
105
114
  if (!message)
106
115
  return;
107
- var args = messageArgs.map(function (arg) {
108
- return typeof arg == "string" ? arg : stringifyForDisplay(arg, 2).slice(0, 1000);
109
- });
110
- return ((global$1[ApolloErrorMessageHandler] &&
111
- global$1[ApolloErrorMessageHandler](message, args)) ||
112
- "An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
113
- version: version,
114
- message: message,
115
- args: args,
116
- }))));
116
+ return (global$1[ApolloErrorMessageHandler] &&
117
+ global$1[ApolloErrorMessageHandler](message, messageArgs.map(stringify)));
118
+ }
119
+ function getFallbackErrorMsg(message, messageArgs) {
120
+ if (messageArgs === void 0) { messageArgs = []; }
121
+ if (!message)
122
+ return;
123
+ return "An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
124
+ version: version,
125
+ message: message,
126
+ args: messageArgs.map(stringify),
127
+ })));
117
128
  }
118
129
 
119
130
  function shouldInclude(_a, variables) {
@@ -127,7 +138,7 @@ function shouldInclude(_a, variables) {
127
138
  if (ifArgument.value.kind === "Variable") {
128
139
  evaledValue =
129
140
  variables && variables[ifArgument.value.name.value];
130
- invariant(evaledValue !== void 0, 65, directive.name.value);
141
+ invariant(evaledValue !== void 0, 67, directive.name.value);
131
142
  }
132
143
  else {
133
144
  evaledValue = ifArgument.value.value;
@@ -162,12 +173,12 @@ function getInclusionDirectives(directives) {
162
173
  return;
163
174
  var directiveArguments = directive.arguments;
164
175
  var directiveName = directive.name.value;
165
- invariant(directiveArguments && directiveArguments.length === 1, 66, directiveName);
176
+ invariant(directiveArguments && directiveArguments.length === 1, 68, directiveName);
166
177
  var ifArgument = directiveArguments[0];
167
- invariant(ifArgument.name && ifArgument.name.value === "if", 67, directiveName);
178
+ invariant(ifArgument.name && ifArgument.name.value === "if", 69, directiveName);
168
179
  var ifValue = ifArgument.value;
169
180
  invariant(ifValue &&
170
- (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 68, directiveName);
181
+ (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 70, directiveName);
171
182
  result.push({ directive: directive, ifArgument: ifArgument });
172
183
  });
173
184
  }
@@ -193,7 +204,7 @@ function getFragmentQueryDocument(document, fragmentName) {
193
204
  document.definitions.forEach(function (definition) {
194
205
  if (definition.kind === "OperationDefinition") {
195
206
  throw newInvariantError(
196
- 69,
207
+ 71,
197
208
  definition.operation,
198
209
  definition.name ? " named '".concat(definition.name.value, "'") : ""
199
210
  );
@@ -203,7 +214,7 @@ function getFragmentQueryDocument(document, fragmentName) {
203
214
  }
204
215
  });
205
216
  if (typeof actualFragmentName === "undefined") {
206
- invariant(fragments.length === 1, 70, fragments.length);
217
+ invariant(fragments.length === 1, 72, fragments.length);
207
218
  actualFragmentName = fragments[0].name.value;
208
219
  }
209
220
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -244,7 +255,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
244
255
  return fragmentMap(fragmentName);
245
256
  }
246
257
  var fragment = fragmentMap && fragmentMap[fragmentName];
247
- invariant(fragment, 71, fragmentName);
258
+ invariant(fragment, 73, fragmentName);
248
259
  return fragment || null;
249
260
  }
250
261
  default:
@@ -252,6 +263,43 @@ function getFragmentFromSelection(selection, fragmentMap) {
252
263
  }
253
264
  }
254
265
 
266
+ var canonicalStringify = Object.assign(function canonicalStringify(value) {
267
+ return JSON.stringify(value, stableObjectReplacer);
268
+ }, {
269
+ reset: function () {
270
+ sortingMap.clear();
271
+ },
272
+ });
273
+ var sortingMap = new Map();
274
+ function stableObjectReplacer(key, value) {
275
+ if (value && typeof value === "object") {
276
+ var proto = Object.getPrototypeOf(value);
277
+ if (proto === Object.prototype || proto === null) {
278
+ var keys = Object.keys(value);
279
+ if (keys.every(everyKeyInOrder))
280
+ return value;
281
+ var unsortedKey = JSON.stringify(keys);
282
+ var sortedKeys = sortingMap.get(unsortedKey);
283
+ if (!sortedKeys) {
284
+ keys.sort();
285
+ var sortedKey = JSON.stringify(keys);
286
+ sortedKeys = sortingMap.get(sortedKey) || keys;
287
+ sortingMap.set(unsortedKey, sortedKeys);
288
+ sortingMap.set(sortedKey, sortedKeys);
289
+ }
290
+ var sortedObject_1 = Object.create(proto);
291
+ sortedKeys.forEach(function (key) {
292
+ sortedObject_1[key] = value[key];
293
+ });
294
+ return sortedObject_1;
295
+ }
296
+ }
297
+ return value;
298
+ }
299
+ function everyKeyInOrder(key, i, keys) {
300
+ return i === 0 || keys[i - 1] <= key;
301
+ }
302
+
255
303
  function makeReference(id) {
256
304
  return { __ref: String(id) };
257
305
  }
@@ -322,7 +370,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
322
370
  argObj[name.value] = null;
323
371
  }
324
372
  else {
325
- throw newInvariantError(80, name.value, value.kind);
373
+ throw newInvariantError(82, name.value, value.kind);
326
374
  }
327
375
  }
328
376
  function storeKeyNameFromField(field, variables) {
@@ -358,6 +406,7 @@ var KNOWN_DIRECTIVES = [
358
406
  "export",
359
407
  "nonreactive",
360
408
  ];
409
+ var storeKeyNameStringify = canonicalStringify;
361
410
  var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
362
411
  if (args &&
363
412
  directives &&
@@ -373,7 +422,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
373
422
  filterKeys.forEach(function (key) {
374
423
  filteredArgs_1[key] = args[key];
375
424
  });
376
- return "".concat(directives["connection"]["key"], "(").concat(stringify(filteredArgs_1), ")");
425
+ return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
377
426
  }
378
427
  else {
379
428
  return directives["connection"]["key"];
@@ -381,7 +430,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
381
430
  }
382
431
  var completeFieldName = fieldName;
383
432
  if (args) {
384
- var stringifiedArgs = stringify(args);
433
+ var stringifiedArgs = storeKeyNameStringify(args);
385
434
  completeFieldName += "(".concat(stringifiedArgs, ")");
386
435
  }
387
436
  if (directives) {
@@ -389,7 +438,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
389
438
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
390
439
  return;
391
440
  if (directives[key] && Object.keys(directives[key]).length) {
392
- completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
441
+ completeFieldName += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
393
442
  }
394
443
  else {
395
444
  completeFieldName += "@".concat(key);
@@ -399,25 +448,11 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
399
448
  return completeFieldName;
400
449
  }, {
401
450
  setStringify: function (s) {
402
- var previous = stringify;
403
- stringify = s;
451
+ var previous = storeKeyNameStringify;
452
+ storeKeyNameStringify = s;
404
453
  return previous;
405
454
  },
406
455
  });
407
- var stringify = function defaultStringify(value) {
408
- return JSON.stringify(value, stringifyReplacer);
409
- };
410
- function stringifyReplacer(_key, value) {
411
- if (isNonNullObject(value) && !Array.isArray(value)) {
412
- value = Object.keys(value)
413
- .sort()
414
- .reduce(function (copy, key) {
415
- copy[key] = value[key];
416
- return copy;
417
- }, {});
418
- }
419
- return value;
420
- }
421
456
  function argumentsObjectFromField(field, variables) {
422
457
  if (field.arguments && field.arguments.length) {
423
458
  var argObj_1 = {};
@@ -469,16 +504,16 @@ function isInlineFragment(selection) {
469
504
  }
470
505
 
471
506
  function checkDocument(doc) {
472
- invariant(doc && doc.kind === "Document", 72);
507
+ invariant(doc && doc.kind === "Document", 74);
473
508
  var operations = doc.definitions
474
509
  .filter(function (d) { return d.kind !== "FragmentDefinition"; })
475
510
  .map(function (definition) {
476
511
  if (definition.kind !== "OperationDefinition") {
477
- throw newInvariantError(73, definition.kind);
512
+ throw newInvariantError(75, definition.kind);
478
513
  }
479
514
  return definition;
480
515
  });
481
- invariant(operations.length <= 1, 74, operations.length);
516
+ invariant(operations.length <= 1, 76, operations.length);
482
517
  return doc;
483
518
  }
484
519
  function getOperationDefinition(doc) {
@@ -501,14 +536,14 @@ function getFragmentDefinitions(doc) {
501
536
  }
502
537
  function getQueryDefinition(doc) {
503
538
  var queryDef = getOperationDefinition(doc);
504
- invariant(queryDef && queryDef.operation === "query", 75);
539
+ invariant(queryDef && queryDef.operation === "query", 77);
505
540
  return queryDef;
506
541
  }
507
542
  function getFragmentDefinition(doc) {
508
- invariant(doc.kind === "Document", 76);
509
- invariant(doc.definitions.length <= 1, 77);
543
+ invariant(doc.kind === "Document", 78);
544
+ invariant(doc.definitions.length <= 1, 79);
510
545
  var fragmentDef = doc.definitions[0];
511
- invariant(fragmentDef.kind === "FragmentDefinition", 78);
546
+ invariant(fragmentDef.kind === "FragmentDefinition", 80);
512
547
  return fragmentDef;
513
548
  }
514
549
  function getMainDefinition(queryDoc) {
@@ -531,7 +566,7 @@ function getMainDefinition(queryDoc) {
531
566
  if (fragmentDefinition) {
532
567
  return fragmentDefinition;
533
568
  }
534
- throw newInvariantError(79);
569
+ throw newInvariantError(81);
535
570
  }
536
571
  function getDefaultValues(definition) {
537
572
  var defaultValues = Object.create(null);
@@ -603,7 +638,7 @@ var DocumentTransform = (function () {
603
638
  return;
604
639
  var cacheKeys = this.getCacheKey(document);
605
640
  if (cacheKeys) {
606
- invariant(Array.isArray(cacheKeys), 64);
641
+ invariant(Array.isArray(cacheKeys), 66);
607
642
  return this.stableCacheKeys.lookupArray(cacheKeys);
608
643
  }
609
644
  };
@@ -699,7 +734,7 @@ function removeDirectivesFromDocument(directives, doc) {
699
734
  return getInUseByFragmentName(ancestor.name.value);
700
735
  }
701
736
  }
702
- globalThis.__DEV__ !== false && invariant.error(81);
737
+ globalThis.__DEV__ !== false && invariant.error(83);
703
738
  return null;
704
739
  };
705
740
  var operationCount = 0;
@@ -1092,48 +1127,31 @@ function iterateObserversSafely(observers, method, argument) {
1092
1127
 
1093
1128
  function asyncMap(observable, mapFn, catchFn) {
1094
1129
  return new zenObservableTs.Observable(function (observer) {
1095
- var next = observer.next, error = observer.error, complete = observer.complete;
1096
- var activeCallbackCount = 0;
1097
- var completed = false;
1098
1130
  var promiseQueue = {
1099
1131
  then: function (callback) {
1100
1132
  return new Promise(function (resolve) { return resolve(callback()); });
1101
1133
  },
1102
1134
  };
1103
- function makeCallback(examiner, delegate) {
1104
- if (examiner) {
1105
- return function (arg) {
1106
- ++activeCallbackCount;
1107
- var both = function () { return examiner(arg); };
1108
- promiseQueue = promiseQueue
1109
- .then(both, both)
1110
- .then(function (result) {
1111
- --activeCallbackCount;
1112
- next && next.call(observer, result);
1113
- if (completed) {
1114
- handler.complete();
1115
- }
1116
- }, function (error) {
1117
- --activeCallbackCount;
1118
- throw error;
1119
- })
1120
- .catch(function (caught) {
1121
- error && error.call(observer, caught);
1122
- });
1123
- };
1124
- }
1125
- else {
1126
- return function (arg) { return delegate && delegate.call(observer, arg); };
1127
- }
1135
+ function makeCallback(examiner, key) {
1136
+ return function (arg) {
1137
+ if (examiner) {
1138
+ var both = function () {
1139
+ return observer.closed
1140
+ ? 0
1141
+ : examiner(arg);
1142
+ };
1143
+ promiseQueue = promiseQueue.then(both, both).then(function (result) { return observer.next(result); }, function (error) { return observer.error(error); });
1144
+ }
1145
+ else {
1146
+ observer[key](arg);
1147
+ }
1148
+ };
1128
1149
  }
1129
1150
  var handler = {
1130
- next: makeCallback(mapFn, next),
1131
- error: makeCallback(catchFn, error),
1151
+ next: makeCallback(mapFn, "next"),
1152
+ error: makeCallback(catchFn, "error"),
1132
1153
  complete: function () {
1133
- completed = true;
1134
- if (!activeCallbackCount) {
1135
- complete && complete.call(observer);
1136
- }
1154
+ promiseQueue.then(function () { return observer.complete(); });
1137
1155
  },
1138
1156
  };
1139
1157
  var sub = observable.subscribe(handler);
@@ -1369,7 +1387,7 @@ function toPromise(observable) {
1369
1387
  observable.subscribe({
1370
1388
  next: function (data) {
1371
1389
  if (completed) {
1372
- globalThis.__DEV__ !== false && invariant.warn(40);
1390
+ globalThis.__DEV__ !== false && invariant.warn(42);
1373
1391
  }
1374
1392
  else {
1375
1393
  completed = true;
@@ -1412,7 +1430,7 @@ function validateOperation(operation) {
1412
1430
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1413
1431
  var key = _a[_i];
1414
1432
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1415
- throw newInvariantError(41, key);
1433
+ throw newInvariantError(43, key);
1416
1434
  }
1417
1435
  }
1418
1436
  return operation;
@@ -1519,7 +1537,7 @@ var ApolloLink = (function () {
1519
1537
  ApolloLink.concat = function (first, second) {
1520
1538
  var firstLink = toLink(first);
1521
1539
  if (isTerminating(firstLink)) {
1522
- globalThis.__DEV__ !== false && invariant.warn(33, firstLink);
1540
+ globalThis.__DEV__ !== false && invariant.warn(35, firstLink);
1523
1541
  return firstLink;
1524
1542
  }
1525
1543
  var nextLink = toLink(second);
@@ -1543,7 +1561,7 @@ var ApolloLink = (function () {
1543
1561
  return ApolloLink.concat(this, next);
1544
1562
  };
1545
1563
  ApolloLink.prototype.request = function (operation, forward) {
1546
- throw newInvariantError(34);
1564
+ throw newInvariantError(36);
1547
1565
  };
1548
1566
  ApolloLink.prototype.onError = function (error, observer) {
1549
1567
  if (observer && observer.error) {
@@ -1920,7 +1938,7 @@ var serializeFetchParameter = function (p, label) {
1920
1938
  serialized = JSON.stringify(p);
1921
1939
  }
1922
1940
  catch (e) {
1923
- var parseError = newInvariantError(37, label, e.message);
1941
+ var parseError = newInvariantError(39, label, e.message);
1924
1942
  parseError.parseError = e;
1925
1943
  throw parseError;
1926
1944
  }
@@ -2006,7 +2024,7 @@ function removeDuplicateHeaders(headers, preserveHeaderCase) {
2006
2024
 
2007
2025
  var checkFetcher = function (fetcher) {
2008
2026
  if (!fetcher && typeof fetch === "undefined") {
2009
- throw newInvariantError(35);
2027
+ throw newInvariantError(37);
2010
2028
  }
2011
2029
  };
2012
2030
 
@@ -2139,7 +2157,7 @@ var createHttpLink = function (linkOptions) {
2139
2157
  options.headers = options.headers || {};
2140
2158
  var acceptHeader = "multipart/mixed;";
2141
2159
  if (isSubscription && hasDefer) {
2142
- globalThis.__DEV__ !== false && invariant.warn(36);
2160
+ globalThis.__DEV__ !== false && invariant.warn(38);
2143
2161
  }
2144
2162
  if (isSubscription) {
2145
2163
  acceptHeader +=
@@ -2566,6 +2584,41 @@ var EntityStore = (function () {
2566
2584
  changedFields_1[storeFieldName] = newValue;
2567
2585
  needToMerge_1 = true;
2568
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
+ }
2569
2622
  }
2570
2623
  }
2571
2624
  }
@@ -2962,28 +3015,6 @@ var ObjectCanon = (function () {
2962
3015
  };
2963
3016
  return ObjectCanon;
2964
3017
  }());
2965
- var canonicalStringify = Object.assign(function (value) {
2966
- if (isNonNullObject(value)) {
2967
- if (stringifyCanon === void 0) {
2968
- resetCanonicalStringify();
2969
- }
2970
- var canonical = stringifyCanon.admit(value);
2971
- var json = stringifyCache.get(canonical);
2972
- if (json === void 0) {
2973
- stringifyCache.set(canonical, (json = JSON.stringify(canonical)));
2974
- }
2975
- return json;
2976
- }
2977
- return JSON.stringify(value);
2978
- }, {
2979
- reset: resetCanonicalStringify,
2980
- });
2981
- var stringifyCanon;
2982
- var stringifyCache;
2983
- function resetCanonicalStringify() {
2984
- stringifyCanon = new ObjectCanon();
2985
- stringifyCache = new (canUseWeakMap ? WeakMap : Map)();
2986
- }
2987
3018
 
2988
3019
  function execSelectionSetKeyArgs(options) {
2989
3020
  return [
@@ -3157,7 +3188,7 @@ var StoreReader = (function () {
3157
3188
  else {
3158
3189
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
3159
3190
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
3160
- throw newInvariantError(7, selection.name.value);
3191
+ throw newInvariantError(9, selection.name.value);
3161
3192
  }
3162
3193
  if (fragment && policies.fragmentMatches(fragment, typename)) {
3163
3194
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
@@ -3241,7 +3272,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
3241
3272
  if (isNonNullObject(value)) {
3242
3273
  invariant(
3243
3274
  !isReference(value),
3244
- 8,
3275
+ 10,
3245
3276
  getTypenameFromStoreObject(store, value),
3246
3277
  field.name.value
3247
3278
  );
@@ -3333,7 +3364,7 @@ function keyFieldsFnFromSpecifier(specifier) {
3333
3364
  hasOwn.call(object, schemaKeyPath[0])) {
3334
3365
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
3335
3366
  }
3336
- invariant(extracted !== void 0, 2, schemaKeyPath.join("."), object);
3367
+ invariant(extracted !== void 0, 4, schemaKeyPath.join("."), object);
3337
3368
  return extracted;
3338
3369
  }));
3339
3370
  return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
@@ -3435,7 +3466,6 @@ function normalize(value) {
3435
3466
  return value;
3436
3467
  }
3437
3468
 
3438
- getStoreKeyName.setStringify(canonicalStringify);
3439
3469
  function argsFromFieldSpecifier(spec) {
3440
3470
  return spec.args !== void 0
3441
3471
  ? spec.args
@@ -3588,7 +3618,7 @@ var Policies = (function () {
3588
3618
  var rootId = "ROOT_" + which.toUpperCase();
3589
3619
  var old = this.rootTypenamesById[rootId];
3590
3620
  if (typename !== old) {
3591
- invariant(!old || old === which, 3, which);
3621
+ invariant(!old || old === which, 5, which);
3592
3622
  if (old)
3593
3623
  delete this.rootIdsByTypename[old];
3594
3624
  this.rootIdsByTypename[typename] = rootId;
@@ -3685,7 +3715,7 @@ var Policies = (function () {
3685
3715
  if (supertypeSet.has(supertype)) {
3686
3716
  if (!typenameSupertypeSet.has(supertype)) {
3687
3717
  if (checkingFuzzySubtypes) {
3688
- globalThis.__DEV__ !== false && invariant.warn(4, typename, supertype);
3718
+ globalThis.__DEV__ !== false && invariant.warn(6, typename, supertype);
3689
3719
  }
3690
3720
  typenameSupertypeSet.add(supertype);
3691
3721
  }
@@ -3847,7 +3877,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3847
3877
  }
3848
3878
  }
3849
3879
  if (globalThis.__DEV__ !== false && options.from === void 0) {
3850
- globalThis.__DEV__ !== false && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
3880
+ globalThis.__DEV__ !== false && invariant.warn(7, stringifyForDisplay(Array.from(readFieldArgs)));
3851
3881
  }
3852
3882
  if (void 0 === options.variables) {
3853
3883
  options.variables = variables;
@@ -3857,7 +3887,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3857
3887
  function makeMergeObjectsFunction(store) {
3858
3888
  return function mergeObjects(existing, incoming) {
3859
3889
  if (isArray(existing) || isArray(incoming)) {
3860
- throw newInvariantError(6);
3890
+ throw newInvariantError(8);
3861
3891
  }
3862
3892
  if (isNonNullObject(existing) && isNonNullObject(incoming)) {
3863
3893
  var eType = store.getFieldValue(existing, "__typename");
@@ -3917,7 +3947,7 @@ var StoreWriter = (function () {
3917
3947
  context: context,
3918
3948
  });
3919
3949
  if (!isReference(ref)) {
3920
- throw newInvariantError(9, result);
3950
+ throw newInvariantError(11, result);
3921
3951
  }
3922
3952
  context.incomingById.forEach(function (_a, dataId) {
3923
3953
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -4022,7 +4052,7 @@ var StoreWriter = (function () {
4022
4052
  !context.deferred &&
4023
4053
  !addTypenameToDocument.added(field) &&
4024
4054
  !policies.getReadFunction(typename, field.name.value)) {
4025
- globalThis.__DEV__ !== false && invariant.error(10, resultKeyNameFromField(field), result);
4055
+ globalThis.__DEV__ !== false && invariant.error(12, resultKeyNameFromField(field), result);
4026
4056
  }
4027
4057
  });
4028
4058
  try {
@@ -4127,7 +4157,7 @@ var StoreWriter = (function () {
4127
4157
  else {
4128
4158
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
4129
4159
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
4130
- throw newInvariantError(11, selection.name.value);
4160
+ throw newInvariantError(13, selection.name.value);
4131
4161
  }
4132
4162
  if (fragment &&
4133
4163
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -4269,7 +4299,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
4269
4299
  }
4270
4300
  });
4271
4301
  }
4272
- globalThis.__DEV__ !== false && invariant.warn(12, fieldName, parentType, childTypenames.length
4302
+ globalThis.__DEV__ !== false && invariant.warn(14, fieldName, parentType, childTypenames.length
4273
4303
  ? "either ensure all objects of type " +
4274
4304
  childTypenames.join(" and ") +
4275
4305
  " have an ID or a custom merge function, or "
@@ -4830,7 +4860,7 @@ var ObservableQuery = (function (_super) {
4830
4860
  var vars = queryDef.variableDefinitions;
4831
4861
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4832
4862
  globalThis.__DEV__ !== false && invariant.warn(
4833
- 18,
4863
+ 20,
4834
4864
  variables,
4835
4865
  ((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || queryDef
4836
4866
  );
@@ -4928,7 +4958,7 @@ var ObservableQuery = (function (_super) {
4928
4958
  options.onError(err);
4929
4959
  return;
4930
4960
  }
4931
- globalThis.__DEV__ !== false && invariant.error(19, err);
4961
+ globalThis.__DEV__ !== false && invariant.error(21, err);
4932
4962
  },
4933
4963
  });
4934
4964
  this.subscriptions.add(subscription);
@@ -5007,9 +5037,9 @@ var ObservableQuery = (function (_super) {
5007
5037
  }
5008
5038
  return options.fetchPolicy;
5009
5039
  };
5010
- ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
5040
+ ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
5011
5041
  this.queryManager.setObservableQuery(this);
5012
- return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus);
5042
+ return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
5013
5043
  };
5014
5044
  ObservableQuery.prototype.updatePolling = function () {
5015
5045
  var _this = this;
@@ -5027,7 +5057,7 @@ var ObservableQuery = (function (_super) {
5027
5057
  if (pollingInfo && pollingInfo.interval === pollInterval) {
5028
5058
  return;
5029
5059
  }
5030
- invariant(pollInterval, 20);
5060
+ invariant(pollInterval, 22);
5031
5061
  var info = pollingInfo || (this.pollingInfo = {});
5032
5062
  info.interval = pollInterval;
5033
5063
  var maybeFetch = function () {
@@ -5091,15 +5121,14 @@ var ObservableQuery = (function (_super) {
5091
5121
  }
5092
5122
  }
5093
5123
  }
5094
- var fetchOptions = query === options.query ? options : tslib.__assign(tslib.__assign({}, options), { query: query });
5095
- this.waitForOwnResult && (this.waitForOwnResult = skipCacheDataFor(fetchOptions.fetchPolicy));
5124
+ this.waitForOwnResult && (this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy));
5096
5125
  var finishWaitingForOwnResult = function () {
5097
5126
  if (_this.concast === concast) {
5098
5127
  _this.waitForOwnResult = false;
5099
5128
  }
5100
5129
  };
5101
- var variables = fetchOptions.variables && tslib.__assign({}, fetchOptions.variables);
5102
- var _a = this.fetch(fetchOptions, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
5130
+ var variables = options.variables && tslib.__assign({}, options.variables);
5131
+ var _a = this.fetch(options, newNetworkStatus, query), concast = _a.concast, fromLink = _a.fromLink;
5103
5132
  var observer = {
5104
5133
  next: function (result) {
5105
5134
  finishWaitingForOwnResult();
@@ -5193,11 +5222,11 @@ function reobserveCacheFirst(obsQuery) {
5193
5222
  return obsQuery.reobserve();
5194
5223
  }
5195
5224
  function defaultSubscriptionObserverErrorCallback(error) {
5196
- globalThis.__DEV__ !== false && invariant.error(21, error.message, error.stack);
5225
+ globalThis.__DEV__ !== false && invariant.error(23, error.message, error.stack);
5197
5226
  }
5198
5227
  function logMissingFieldErrors(missing) {
5199
5228
  if (globalThis.__DEV__ !== false && missing) {
5200
- globalThis.__DEV__ !== false && invariant.debug(22, missing);
5229
+ globalThis.__DEV__ !== false && invariant.debug(24, missing);
5201
5230
  }
5202
5231
  }
5203
5232
  function skipCacheDataFor(fetchPolicy) {
@@ -5382,7 +5411,7 @@ var LocalState = (function () {
5382
5411
  }
5383
5412
  else {
5384
5413
  fragment = fragmentMap[selection.name.value];
5385
- invariant(fragment, 16, selection.name.value);
5414
+ invariant(fragment, 18, selection.name.value);
5386
5415
  }
5387
5416
  if (fragment && fragment.typeCondition) {
5388
5417
  typeCondition = fragment.typeCondition.name.value;
@@ -5495,7 +5524,7 @@ var LocalState = (function () {
5495
5524
  },
5496
5525
  FragmentSpread: function (spread, _, __, ___, ancestors) {
5497
5526
  var fragment = fragmentMap[spread.name.value];
5498
- invariant(fragment, 17, spread.name.value);
5527
+ invariant(fragment, 19, spread.name.value);
5499
5528
  var fragmentSelections = collectByDefinition(fragment);
5500
5529
  if (fragmentSelections.size > 0) {
5501
5530
  ancestors.forEach(function (node) {
@@ -5541,7 +5570,6 @@ var QueryInfo = (function () {
5541
5570
  this.listeners = new Set();
5542
5571
  this.document = null;
5543
5572
  this.lastRequestId = 1;
5544
- this.subscriptions = new Set();
5545
5573
  this.stopped = false;
5546
5574
  this.dirty = false;
5547
5575
  this.observableQuery = null;
@@ -5676,7 +5704,6 @@ var QueryInfo = (function () {
5676
5704
  this.reset();
5677
5705
  this.cancel();
5678
5706
  this.cancel = QueryInfo.prototype.cancel;
5679
- this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
5680
5707
  var oq = this.observableQuery;
5681
5708
  if (oq)
5682
5709
  oq.stopPolling();
@@ -5795,7 +5822,7 @@ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
5795
5822
  var QueryManager = (function () {
5796
5823
  function QueryManager(_a) {
5797
5824
  var _this = this;
5798
- 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;
5799
5826
  this.clientAwareness = {};
5800
5827
  this.queries = new Map();
5801
5828
  this.fetchCancelFns = new Map();
@@ -5818,6 +5845,7 @@ var QueryManager = (function () {
5818
5845
  .concat(documentTransform)
5819
5846
  .concat(defaultDocumentTransform)
5820
5847
  : defaultDocumentTransform;
5848
+ this.defaultContext = defaultContext || Object.create(null);
5821
5849
  if ((this.onBroadcast = onBroadcast)) {
5822
5850
  this.mutationStore = Object.create(null);
5823
5851
  }
@@ -5827,7 +5855,7 @@ var QueryManager = (function () {
5827
5855
  this.queries.forEach(function (_info, queryId) {
5828
5856
  _this.stopQueryNoBroadcast(queryId);
5829
5857
  });
5830
- this.cancelPendingFetches(newInvariantError(23));
5858
+ this.cancelPendingFetches(newInvariantError(25));
5831
5859
  };
5832
5860
  QueryManager.prototype.cancelPendingFetches = function (error) {
5833
5861
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -5841,8 +5869,8 @@ var QueryManager = (function () {
5841
5869
  return tslib.__generator(this, function (_h) {
5842
5870
  switch (_h.label) {
5843
5871
  case 0:
5844
- invariant(mutation, 24);
5845
- invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 25);
5872
+ invariant(mutation, 26);
5873
+ invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
5846
5874
  mutationId = this.generateMutationId();
5847
5875
  mutation = this.cache.transformForLink(this.transform(mutation));
5848
5876
  hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
@@ -6163,10 +6191,10 @@ var QueryManager = (function () {
6163
6191
  QueryManager.prototype.query = function (options, queryId) {
6164
6192
  var _this = this;
6165
6193
  if (queryId === void 0) { queryId = this.generateQueryId(); }
6166
- invariant(options.query, 26);
6167
- invariant(options.query.kind === "Document", 27);
6168
- invariant(!options.returnPartialData, 28);
6169
- 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);
6170
6198
  return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
6171
6199
  };
6172
6200
  QueryManager.prototype.generateQueryId = function () {
@@ -6191,7 +6219,7 @@ var QueryManager = (function () {
6191
6219
  if (options === void 0) { options = {
6192
6220
  discardWatches: true,
6193
6221
  }; }
6194
- this.cancelPendingFetches(newInvariantError(30));
6222
+ this.cancelPendingFetches(newInvariantError(32));
6195
6223
  this.queries.forEach(function (queryInfo) {
6196
6224
  if (queryInfo.observableQuery) {
6197
6225
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -6267,7 +6295,7 @@ var QueryManager = (function () {
6267
6295
  if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
6268
6296
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
6269
6297
  if (!included) {
6270
- globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 31 : 32, nameOrDoc);
6298
+ globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
6271
6299
  }
6272
6300
  });
6273
6301
  }
@@ -6423,7 +6451,7 @@ var QueryManager = (function () {
6423
6451
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
6424
6452
  var requestId = (queryInfo.lastRequestId = this.generateRequestId());
6425
6453
  var linkDocument = this.cache.transformForLink(options.query);
6426
- 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) {
6427
6455
  var graphQLErrors = getGraphQLErrorsFromResult(result);
6428
6456
  var hasErrors = graphQLErrors.length > 0;
6429
6457
  if (requestId >= queryInfo.lastRequestId) {
@@ -6455,10 +6483,10 @@ var QueryManager = (function () {
6455
6483
  throw error;
6456
6484
  });
6457
6485
  };
6458
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
6486
+ QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus, query) {
6459
6487
  var _this = this;
6460
6488
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
6461
- var query = options.query;
6489
+ if (query === void 0) { query = options.query; }
6462
6490
  var variables = this.getVariables(query, options.variables);
6463
6491
  var queryInfo = this.getQuery(queryId);
6464
6492
  var defaults = this.defaultOptions.watchQuery;
@@ -6704,11 +6732,11 @@ var ApolloClient = (function () {
6704
6732
  this.resetStoreCallbacks = [];
6705
6733
  this.clearStoreCallbacks = [];
6706
6734
  if (!options.cache) {
6707
- throw newInvariantError(13);
6735
+ throw newInvariantError(15);
6708
6736
  }
6709
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" &&
6710
6738
  !window.__APOLLO_CLIENT__ &&
6711
- 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;
6712
6740
  var link = options.link;
6713
6741
  if (!link) {
6714
6742
  link = uri
@@ -6740,6 +6768,7 @@ var ApolloClient = (function () {
6740
6768
  cache: this.cache,
6741
6769
  link: this.link,
6742
6770
  defaultOptions: this.defaultOptions,
6771
+ defaultContext: defaultContext,
6743
6772
  documentTransform: documentTransform,
6744
6773
  queryDeduplication: queryDeduplication,
6745
6774
  ssrMode: ssrMode,
@@ -6829,7 +6858,7 @@ var ApolloClient = (function () {
6829
6858
  if (this.defaultOptions.query) {
6830
6859
  options = mergeOptions(this.defaultOptions.query, options);
6831
6860
  }
6832
- invariant(options.fetchPolicy !== "cache-and-network", 14);
6861
+ invariant(options.fetchPolicy !== "cache-and-network", 16);
6833
6862
  if (this.disableNetworkFetches && options.fetchPolicy === "network-only") {
6834
6863
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "cache-first" });
6835
6864
  }
@@ -6922,7 +6951,7 @@ var ApolloClient = (function () {
6922
6951
  result.queries = queries;
6923
6952
  result.results = results;
6924
6953
  result.catch(function (error) {
6925
- globalThis.__DEV__ !== false && invariant.debug(15, error);
6954
+ globalThis.__DEV__ !== false && invariant.debug(17, error);
6926
6955
  });
6927
6956
  return result;
6928
6957
  };
@@ -6951,6 +6980,13 @@ var ApolloClient = (function () {
6951
6980
  ApolloClient.prototype.setLink = function (newLink) {
6952
6981
  this.link = this.queryManager.link = newLink;
6953
6982
  };
6983
+ Object.defineProperty(ApolloClient.prototype, "defaultContext", {
6984
+ get: function () {
6985
+ return this.queryManager.defaultContext;
6986
+ },
6987
+ enumerable: false,
6988
+ configurable: true
6989
+ });
6954
6990
  return ApolloClient;
6955
6991
  }());
6956
6992
 
@@ -6958,7 +6994,7 @@ var contextKey = canUseSymbol
6958
6994
  ? Symbol.for("__APOLLO_CONTEXT__")
6959
6995
  : "__APOLLO_CONTEXT__";
6960
6996
  function getApolloContext() {
6961
- invariant("createContext" in React__namespace, 43);
6997
+ invariant("createContext" in React__namespace, 45);
6962
6998
  var context = React__namespace.createContext[contextKey];
6963
6999
  if (!context) {
6964
7000
  Object.defineProperty(React__namespace.createContext, contextKey, {
@@ -6976,7 +7012,7 @@ var resetApolloContext = getApolloContext;
6976
7012
  var ApolloConsumer = function (props) {
6977
7013
  var ApolloContext = getApolloContext();
6978
7014
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6979
- invariant(context && context.client, 42);
7015
+ invariant(context && context.client, 44);
6980
7016
  return props.children(context.client);
6981
7017
  }));
6982
7018
  };
@@ -6988,14 +7024,14 @@ var ApolloProvider = function (_a) {
6988
7024
  var context = React__namespace.useMemo(function () {
6989
7025
  return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client });
6990
7026
  }, [parentContext, client]);
6991
- invariant(context.client, 44);
7027
+ invariant(context.client, 46);
6992
7028
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6993
7029
  };
6994
7030
 
6995
7031
  function useApolloClient(override) {
6996
7032
  var context = React__namespace.useContext(getApolloContext());
6997
7033
  var client = override || context.client;
6998
- invariant(!!client, 47);
7034
+ invariant(!!client, 49);
6999
7035
  return client;
7000
7036
  }
7001
7037
 
@@ -7009,7 +7045,7 @@ var useSyncExternalStore = realHook$1 ||
7009
7045
  !didWarnUncachedGetSnapshot &&
7010
7046
  value !== getSnapshot()) {
7011
7047
  didWarnUncachedGetSnapshot = true;
7012
- globalThis.__DEV__ !== false && invariant.error(56);
7048
+ globalThis.__DEV__ !== false && invariant.error(58);
7013
7049
  }
7014
7050
  var _a = React__namespace.useState({
7015
7051
  inst: { value: value, getSnapshot: getSnapshot },
@@ -7074,7 +7110,7 @@ function parser(document) {
7074
7110
  if (cached)
7075
7111
  return cached;
7076
7112
  var variables, type, name;
7077
- invariant(!!document && !!document.kind, 57, document);
7113
+ invariant(!!document && !!document.kind, 59, document);
7078
7114
  var fragments = [];
7079
7115
  var queries = [];
7080
7116
  var mutations = [];
@@ -7102,10 +7138,10 @@ function parser(document) {
7102
7138
  invariant(!fragments.length ||
7103
7139
  queries.length ||
7104
7140
  mutations.length ||
7105
- subscriptions.length, 58);
7141
+ subscriptions.length, 60);
7106
7142
  invariant(
7107
7143
  queries.length + mutations.length + subscriptions.length <= 1,
7108
- 59,
7144
+ 61,
7109
7145
  document,
7110
7146
  queries.length,
7111
7147
  subscriptions.length,
@@ -7119,7 +7155,7 @@ function parser(document) {
7119
7155
  : mutations.length
7120
7156
  ? mutations
7121
7157
  : subscriptions;
7122
- invariant(definitions.length === 1, 60, document, definitions.length);
7158
+ invariant(definitions.length === 1, 62, document, definitions.length);
7123
7159
  var definition = definitions[0];
7124
7160
  variables = definition.variableDefinitions || [];
7125
7161
  if (definition.name && definition.name.kind === "Name") {
@@ -7138,7 +7174,7 @@ function verifyDocumentType(document, type) {
7138
7174
  var usedOperationName = operationName(operation.type);
7139
7175
  invariant(
7140
7176
  operation.type === type,
7141
- 61,
7177
+ 63,
7142
7178
  requiredOperationName,
7143
7179
  requiredOperationName,
7144
7180
  usedOperationName
@@ -7188,7 +7224,7 @@ var InternalState = (function () {
7188
7224
  }
7189
7225
  }
7190
7226
  InternalState.prototype.forceUpdateState = function () {
7191
- globalThis.__DEV__ !== false && invariant.warn(48);
7227
+ globalThis.__DEV__ !== false && invariant.warn(50);
7192
7228
  };
7193
7229
  InternalState.prototype.executeQuery = function (options) {
7194
7230
  var _this = this;
@@ -7609,10 +7645,10 @@ function useSubscription(subscription, options) {
7609
7645
  if (!hasIssuedDeprecationWarningRef.current) {
7610
7646
  hasIssuedDeprecationWarningRef.current = true;
7611
7647
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
7612
- globalThis.__DEV__ !== false && invariant.warn(options.onData ? 50 : 51);
7648
+ globalThis.__DEV__ !== false && invariant.warn(options.onData ? 52 : 53);
7613
7649
  }
7614
7650
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
7615
- globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 52 : 53);
7651
+ globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 54 : 55);
7616
7652
  }
7617
7653
  }
7618
7654
  var _b = React__namespace.useState(function () {
@@ -7829,7 +7865,6 @@ var OBSERVED_CHANGED_OPTIONS = [
7829
7865
  var InternalQueryReference = (function () {
7830
7866
  function InternalQueryReference(observable, options) {
7831
7867
  var _this = this;
7832
- var _a;
7833
7868
  this.listeners = new Set();
7834
7869
  this.status = "loading";
7835
7870
  this.references = 0;
@@ -7863,7 +7898,13 @@ var InternalQueryReference = (function () {
7863
7898
  next: this.handleNext,
7864
7899
  error: this.handleError,
7865
7900
  });
7866
- 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);
7867
7908
  }
7868
7909
  Object.defineProperty(InternalQueryReference.prototype, "watchQueryOptions", {
7869
7910
  get: function () {
@@ -8118,11 +8159,11 @@ function validateFetchPolicy(fetchPolicy) {
8118
8159
  "no-cache",
8119
8160
  "cache-and-network",
8120
8161
  ];
8121
- invariant(supportedFetchPolicies.includes(fetchPolicy), 54, fetchPolicy);
8162
+ invariant(supportedFetchPolicies.includes(fetchPolicy), 56, fetchPolicy);
8122
8163
  }
8123
8164
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
8124
8165
  if (fetchPolicy === "no-cache" && returnPartialData) {
8125
- globalThis.__DEV__ !== false && invariant.warn(55);
8166
+ globalThis.__DEV__ !== false && invariant.warn(57);
8126
8167
  }
8127
8168
  }
8128
8169
  function toApolloError(result) {
@@ -8197,7 +8238,7 @@ function useBackgroundQuery(query, options) {
8197
8238
 
8198
8239
  function useReadQuery(queryRef) {
8199
8240
  var internalQueryRef = unwrapQueryRef(queryRef);
8200
- invariant(internalQueryRef.promiseCache, 49);
8241
+ invariant(internalQueryRef.promiseCache, 51);
8201
8242
  var promiseCache = internalQueryRef.promiseCache, key = internalQueryRef.key;
8202
8243
  if (!promiseCache.has(key)) {
8203
8244
  promiseCache.set(key, internalQueryRef.promise);