@apollo/client 4.0.0-alpha.20 → 4.0.0-alpha.21

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 (90) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +4 -4
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  8. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  9. package/__cjs/core/ApolloClient.cjs +10 -10
  10. package/__cjs/core/ObservableQuery.cjs +15 -11
  11. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  12. package/__cjs/core/ObservableQuery.d.cts +1 -2
  13. package/__cjs/core/QueryInfo.cjs +223 -34
  14. package/__cjs/core/QueryInfo.cjs.map +1 -1
  15. package/__cjs/core/QueryInfo.d.cts +34 -24
  16. package/__cjs/core/QueryManager.cjs +75 -256
  17. package/__cjs/core/QueryManager.cjs.map +1 -1
  18. package/__cjs/core/QueryManager.d.cts +4 -36
  19. package/__cjs/core/networkStatus.cjs +7 -1
  20. package/__cjs/core/networkStatus.cjs.map +1 -1
  21. package/__cjs/core/networkStatus.d.cts +7 -1
  22. package/__cjs/invariantErrorCodes.cjs +64 -69
  23. package/__cjs/link/core/ApolloLink.cjs +2 -2
  24. package/__cjs/link/http/checkFetcher.cjs +1 -1
  25. package/__cjs/link/http/createHttpLink.cjs +1 -1
  26. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  27. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  28. package/__cjs/link/persisted-queries/index.cjs +2 -2
  29. package/__cjs/link/utils/validateOperation.cjs +1 -1
  30. package/__cjs/local-state/LocalState.cjs +10 -10
  31. package/__cjs/masking/maskDefinition.cjs.map +1 -1
  32. package/__cjs/masking/maskFragment.cjs +0 -8
  33. package/__cjs/masking/maskFragment.cjs.map +1 -1
  34. package/__cjs/masking/maskOperation.cjs +0 -8
  35. package/__cjs/masking/maskOperation.cjs.map +1 -1
  36. package/__cjs/masking/utils.cjs +3 -11
  37. package/__cjs/masking/utils.cjs.map +1 -1
  38. package/__cjs/masking/utils.d.cts +0 -1
  39. package/__cjs/react/hooks/useLazyQuery.cjs +1 -2
  40. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  41. package/__cjs/react/hooks/useLazyQuery.d.cts +0 -8
  42. package/__cjs/utilities/index.cjs +1 -16
  43. package/__cjs/utilities/index.cjs.map +1 -1
  44. package/__cjs/utilities/index.d.cts +0 -13
  45. package/__cjs/version.cjs +1 -1
  46. package/cache/core/cache.js +1 -1
  47. package/cache/inmemory/entityStore.js +3 -3
  48. package/cache/inmemory/key-extractor.js +1 -1
  49. package/cache/inmemory/policies.js +4 -4
  50. package/cache/inmemory/policies.js.map +1 -1
  51. package/cache/inmemory/readFromStore.js +2 -2
  52. package/cache/inmemory/writeToStore.js +4 -4
  53. package/core/ApolloClient.js +10 -10
  54. package/core/ObservableQuery.d.ts +1 -2
  55. package/core/ObservableQuery.js +15 -11
  56. package/core/ObservableQuery.js.map +1 -1
  57. package/core/QueryInfo.d.ts +34 -24
  58. package/core/QueryInfo.js +221 -34
  59. package/core/QueryInfo.js.map +1 -1
  60. package/core/QueryManager.d.ts +4 -36
  61. package/core/QueryManager.js +77 -258
  62. package/core/QueryManager.js.map +1 -1
  63. package/core/networkStatus.d.ts +7 -1
  64. package/core/networkStatus.js +7 -1
  65. package/core/networkStatus.js.map +1 -1
  66. package/invariantErrorCodes.js +64 -69
  67. package/link/core/ApolloLink.js +2 -2
  68. package/link/http/checkFetcher.js +1 -1
  69. package/link/http/createHttpLink.js +1 -1
  70. package/link/http/parseAndCheckHttpResponse.js +1 -1
  71. package/link/http/serializeFetchParameter.js +1 -1
  72. package/link/persisted-queries/index.js +2 -2
  73. package/link/utils/validateOperation.js +1 -1
  74. package/local-state/LocalState.js +10 -10
  75. package/masking/maskDefinition.js.map +1 -1
  76. package/masking/maskFragment.js +0 -8
  77. package/masking/maskFragment.js.map +1 -1
  78. package/masking/maskOperation.js +0 -8
  79. package/masking/maskOperation.js.map +1 -1
  80. package/masking/utils.d.ts +0 -1
  81. package/masking/utils.js +3 -10
  82. package/masking/utils.js.map +1 -1
  83. package/package.json +1 -1
  84. package/react/hooks/useLazyQuery.d.ts +0 -8
  85. package/react/hooks/useLazyQuery.js +1 -2
  86. package/react/hooks/useLazyQuery.js.map +1 -1
  87. package/utilities/index.d.ts +0 -13
  88. package/utilities/index.js +0 -12
  89. package/utilities/index.js.map +1 -1
  90. package/version.js +1 -1
@@ -21,8 +21,6 @@ const invariant_1 = require("@apollo/client/utilities/invariant");
21
21
  const networkStatus_js_1 = require("./networkStatus.cjs");
22
22
  const ObservableQuery_js_1 = require("./ObservableQuery.cjs");
23
23
  const QueryInfo_js_1 = require("./QueryInfo.cjs");
24
- const { hasOwnProperty } = Object.prototype;
25
- const IGNORE = {};
26
24
  class QueryManager {
27
25
  defaultOptions;
28
26
  client;
@@ -51,7 +49,7 @@ class QueryManager {
51
49
  * All ObservableQueries that currently have at least one subscriber.
52
50
  */
53
51
  obsQueries = new Set();
54
- // Maps from queryId strings to Promise rejection functions for
52
+ // Maps from queryInfo.id strings to Promise rejection functions for
55
53
  // currently active queries and fetches.
56
54
  // Use protected instead of private field so
57
55
  // @apollo/experimental-nextjs-app-support can access type info.
@@ -96,17 +94,17 @@ class QueryManager {
96
94
  */
97
95
  stop() {
98
96
  this.obsQueries.forEach((oq) => oq.stop());
99
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(82));
97
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(81));
100
98
  }
101
99
  cancelPendingFetches(error) {
102
100
  this.fetchCancelFns.forEach((cancel) => cancel(error));
103
101
  this.fetchCancelFns.clear();
104
102
  }
105
103
  async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy = this.defaultOptions.mutate?.fetchPolicy || "network-only", errorPolicy = this.defaultOptions.mutate?.errorPolicy || "none", keepRootFields, context, }) {
106
- (0, invariant_1.invariant)(mutation, 83);
104
+ (0, invariant_1.invariant)(mutation, 82);
107
105
  (0, internal_1.checkDocument)(mutation, graphql_1.OperationTypeNode.MUTATION);
108
- (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 84);
109
- const mutationId = this.generateMutationId();
106
+ (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 83);
107
+ const queryInfo = new QueryInfo_js_1.QueryInfo(this);
110
108
  mutation = this.cache.transformForLink(this.transform(mutation));
111
109
  const { hasClientExports } = this.getDocumentInfo(mutation);
112
110
  variables = this.getVariables(mutation, variables);
@@ -114,7 +112,7 @@ class QueryManager {
114
112
  if (environment_1.__DEV__) {
115
113
  (0, invariant_1.invariant)(
116
114
  this.localState,
117
- 85,
115
+ 84,
118
116
  (0, internal_1.getOperationName)(mutation, "(anonymous)")
119
117
  );
120
118
  }
@@ -126,18 +124,19 @@ class QueryManager {
126
124
  });
127
125
  }
128
126
  const mutationStoreValue = this.mutationStore &&
129
- (this.mutationStore[mutationId] = {
127
+ (this.mutationStore[queryInfo.id] = {
130
128
  mutation,
131
129
  variables,
132
130
  loading: true,
133
131
  error: null,
134
132
  });
135
133
  const isOptimistic = optimisticResponse &&
136
- this.markMutationOptimistic(optimisticResponse, {
137
- mutationId,
134
+ queryInfo.markMutationOptimistic(optimisticResponse, {
138
135
  document: mutation,
139
136
  variables,
140
- fetchPolicy,
137
+ cacheWriteBehavior: fetchPolicy === "no-cache" ?
138
+ 0 /* CacheWriteBehavior.FORBID */
139
+ : 2 /* CacheWriteBehavior.MERGE */,
141
140
  errorPolicy,
142
141
  context,
143
142
  updateQueries,
@@ -167,19 +166,19 @@ class QueryManager {
167
166
  if (errorPolicy === "ignore" && hasErrors) {
168
167
  delete storeResult.errors;
169
168
  }
170
- return (0, rxjs_2.from)(this.markMutationResult({
171
- mutationId,
172
- result: storeResult,
169
+ return (0, rxjs_2.from)(queryInfo.markMutationResult(storeResult, {
173
170
  document: mutation,
174
171
  variables,
175
- fetchPolicy,
172
+ cacheWriteBehavior: fetchPolicy === "no-cache" ?
173
+ 0 /* CacheWriteBehavior.FORBID */
174
+ : 2 /* CacheWriteBehavior.MERGE */,
176
175
  errorPolicy,
177
176
  context,
178
177
  update: updateWithProxyFn,
179
178
  updateQueries,
180
179
  awaitRefetchQueries,
181
180
  refetchQueries,
182
- removeOptimistic: isOptimistic ? mutationId : void 0,
181
+ removeOptimistic: isOptimistic ? queryInfo.id : void 0,
183
182
  onQueryUpdated,
184
183
  keepRootFields,
185
184
  }));
@@ -216,7 +215,7 @@ class QueryManager {
216
215
  mutationStoreValue.error = error;
217
216
  }
218
217
  if (isOptimistic) {
219
- this.cache.removeOptimistic(mutationId);
218
+ this.cache.removeOptimistic(queryInfo.id);
220
219
  }
221
220
  this.broadcastQueries();
222
221
  if (errorPolicy === "ignore") {
@@ -230,190 +229,8 @@ class QueryManager {
230
229
  });
231
230
  });
232
231
  }
233
- markMutationResult(mutation, cache = this.cache) {
234
- let { result } = mutation;
235
- const cacheWrites = [];
236
- const skipCache = mutation.fetchPolicy === "no-cache";
237
- if (!skipCache && (0, QueryInfo_js_1.shouldWriteResult)(result, mutation.errorPolicy)) {
238
- if (!(0, internal_1.isExecutionPatchIncrementalResult)(result)) {
239
- cacheWrites.push({
240
- result: result.data,
241
- dataId: "ROOT_MUTATION",
242
- query: mutation.document,
243
- variables: mutation.variables,
244
- });
245
- }
246
- if ((0, internal_1.isExecutionPatchIncrementalResult)(result) &&
247
- (0, internal_1.isNonEmptyArray)(result.incremental)) {
248
- const diff = cache.diff({
249
- id: "ROOT_MUTATION",
250
- // The cache complains if passed a mutation where it expects a
251
- // query, so we transform mutations and subscriptions to queries
252
- // (only once, thanks to this.transformCache).
253
- query: this.getDocumentInfo(mutation.document).asQuery,
254
- variables: mutation.variables,
255
- optimistic: false,
256
- returnPartialData: true,
257
- });
258
- let mergedData;
259
- if (diff.result) {
260
- mergedData = (0, internal_1.mergeIncrementalData)(diff.result, result);
261
- }
262
- if (typeof mergedData !== "undefined") {
263
- // cast the ExecutionPatchResult to FetchResult here since
264
- // ExecutionPatchResult never has `data` when returned from the server
265
- result.data = mergedData;
266
- cacheWrites.push({
267
- result: mergedData,
268
- dataId: "ROOT_MUTATION",
269
- query: mutation.document,
270
- variables: mutation.variables,
271
- });
272
- }
273
- }
274
- const { updateQueries } = mutation;
275
- if (updateQueries) {
276
- this.obsQueries.forEach((observableQuery) => {
277
- const queryName = observableQuery && observableQuery.queryName;
278
- if (!queryName || !hasOwnProperty.call(updateQueries, queryName)) {
279
- return;
280
- }
281
- const updater = updateQueries[queryName];
282
- const { query: document, variables } = observableQuery;
283
- // Read the current query result from the store.
284
- const { result: currentQueryResult, complete } = observableQuery.getCacheDiff({ optimistic: false });
285
- if (complete && currentQueryResult) {
286
- // Run our reducer using the current query result and the mutation result.
287
- const nextQueryResult = updater(currentQueryResult, {
288
- mutationResult: result,
289
- queryName: (document && (0, internal_1.getOperationName)(document)) || void 0,
290
- queryVariables: variables,
291
- });
292
- // Write the modified result back into the store if we got a new result.
293
- if (nextQueryResult) {
294
- cacheWrites.push({
295
- result: nextQueryResult,
296
- dataId: "ROOT_QUERY",
297
- query: document,
298
- variables,
299
- });
300
- }
301
- }
302
- });
303
- }
304
- }
305
- if (cacheWrites.length > 0 ||
306
- (mutation.refetchQueries || "").length > 0 ||
307
- mutation.update ||
308
- mutation.onQueryUpdated ||
309
- mutation.removeOptimistic) {
310
- const results = [];
311
- this.refetchQueries({
312
- updateCache: (cache) => {
313
- if (!skipCache) {
314
- cacheWrites.forEach((write) => cache.write(write));
315
- }
316
- // If the mutation has some writes associated with it then we need to
317
- // apply those writes to the store by running this reducer again with
318
- // a write action.
319
- const { update } = mutation;
320
- // Determine whether result is a SingleExecutionResult,
321
- // or the final ExecutionPatchResult.
322
- const isFinalResult = !(0, internal_1.isExecutionPatchResult)(result) ||
323
- ((0, internal_1.isExecutionPatchIncrementalResult)(result) && !result.hasNext);
324
- if (update) {
325
- if (!skipCache) {
326
- // Re-read the ROOT_MUTATION data we just wrote into the cache
327
- // (the first cache.write call in the cacheWrites.forEach loop
328
- // above), so field read functions have a chance to run for
329
- // fields within mutation result objects.
330
- const diff = cache.diff({
331
- id: "ROOT_MUTATION",
332
- // The cache complains if passed a mutation where it expects a
333
- // query, so we transform mutations and subscriptions to queries
334
- // (only once, thanks to this.transformCache).
335
- query: this.getDocumentInfo(mutation.document).asQuery,
336
- variables: mutation.variables,
337
- optimistic: false,
338
- returnPartialData: true,
339
- });
340
- if (diff.complete) {
341
- result = { ...result, data: diff.result };
342
- if ("incremental" in result) {
343
- delete result.incremental;
344
- }
345
- if ("hasNext" in result) {
346
- delete result.hasNext;
347
- }
348
- }
349
- }
350
- // If we've received the whole response,
351
- // either a SingleExecutionResult or the final ExecutionPatchResult,
352
- // call the update function.
353
- if (isFinalResult) {
354
- update(cache, result, {
355
- context: mutation.context,
356
- variables: mutation.variables,
357
- });
358
- }
359
- }
360
- // TODO Do this with cache.evict({ id: 'ROOT_MUTATION' }) but make it
361
- // shallow to allow rolling back optimistic evictions.
362
- if (!skipCache && !mutation.keepRootFields && isFinalResult) {
363
- cache.modify({
364
- id: "ROOT_MUTATION",
365
- fields(value, { fieldName, DELETE }) {
366
- return fieldName === "__typename" ? value : DELETE;
367
- },
368
- });
369
- }
370
- },
371
- include: mutation.refetchQueries,
372
- // Write the final mutation.result to the root layer of the cache.
373
- optimistic: false,
374
- // Remove the corresponding optimistic layer at the same time as we
375
- // write the final non-optimistic result.
376
- removeOptimistic: mutation.removeOptimistic,
377
- // Let the caller of client.mutate optionally determine the refetching
378
- // behavior for watched queries after the mutation.update function runs.
379
- // If no onQueryUpdated function was provided for this mutation, pass
380
- // null instead of undefined to disable the default refetching behavior.
381
- onQueryUpdated: mutation.onQueryUpdated || null,
382
- }).forEach((result) => results.push(result));
383
- if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
384
- // Returning a promise here makes the mutation await that promise, so we
385
- // include results in that promise's work if awaitRefetchQueries or an
386
- // onQueryUpdated function was specified.
387
- return Promise.all(results).then(() => result);
388
- }
389
- }
390
- return Promise.resolve(result);
391
- }
392
- markMutationOptimistic(optimisticResponse, mutation) {
393
- const data = typeof optimisticResponse === "function" ?
394
- optimisticResponse(mutation.variables, { IGNORE })
395
- : optimisticResponse;
396
- if (data === IGNORE) {
397
- return false;
398
- }
399
- this.cache.recordOptimisticTransaction((cache) => {
400
- try {
401
- this.markMutationResult({
402
- ...mutation,
403
- result: { data },
404
- }, cache);
405
- }
406
- catch (error) {
407
- __DEV__ && invariant_1.invariant.error(error);
408
- }
409
- }, mutation.mutationId);
410
- return true;
411
- }
412
232
  fetchQuery(options, networkStatus) {
413
- const queryInfo = new QueryInfo_js_1.QueryInfo({
414
- queryManager: this,
415
- });
416
- return (0, rxjs_2.lastValueFrom)(this.fetchObservableWithInfo(queryInfo, options, {
233
+ return (0, rxjs_2.lastValueFrom)(this.fetchObservableWithInfo(options, {
417
234
  networkStatus,
418
235
  }).observable.pipe((0, internal_1.filterMap)((value) => {
419
236
  switch (value.kind) {
@@ -517,18 +334,10 @@ class QueryManager {
517
334
  }),
518
335
  }));
519
336
  }
520
- queryIdCounter = 1;
521
- generateQueryId() {
522
- return String(this.queryIdCounter++);
523
- }
524
337
  requestIdCounter = 1;
525
338
  generateRequestId() {
526
339
  return this.requestIdCounter++;
527
340
  }
528
- mutationIdCounter = 1;
529
- generateMutationId() {
530
- return String(this.mutationIdCounter++);
531
- }
532
341
  clearStore(options = {
533
342
  discardWatches: true,
534
343
  }) {
@@ -537,7 +346,7 @@ class QueryManager {
537
346
  // depend on values that previously existed in the data portion of the
538
347
  // store. So, we cancel the promises and observers that we have issued
539
348
  // so far and not yet resolved (in the case of queries).
540
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(86));
349
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(85));
541
350
  this.obsQueries.forEach((observableQuery) => {
542
351
  // Set loading to true so listeners don't trigger unless they want
543
352
  // results with partial data.
@@ -607,10 +416,10 @@ class QueryManager {
607
416
  if (!included) {
608
417
  const queryName = queryNames.get(nameOrQueryString);
609
418
  if (queryName) {
610
- __DEV__ && invariant_1.invariant.warn(87, queryName);
419
+ __DEV__ && invariant_1.invariant.warn(86, queryName);
611
420
  }
612
421
  else {
613
- __DEV__ && invariant_1.invariant.warn(88);
422
+ __DEV__ && invariant_1.invariant.warn(87);
614
423
  }
615
424
  }
616
425
  });
@@ -639,7 +448,7 @@ class QueryManager {
639
448
  if (environment_1.__DEV__) {
640
449
  (0, invariant_1.invariant)(
641
450
  !this.getDocumentInfo(query).hasClientExports || this.localState,
642
- 89,
451
+ 88,
643
452
  (0, internal_1.getOperationName)(query, "(anonymous)")
644
453
  );
645
454
  }
@@ -652,21 +461,17 @@ class QueryManager {
652
461
  }))
653
462
  : (0, rxjs_2.of)(variables)).pipe((0, rxjs_2.mergeMap)((variables) => {
654
463
  const { observable, restart: res } = this.getObservableFromLink(query, context, variables, extensions);
464
+ const queryInfo = new QueryInfo_js_1.QueryInfo(this);
655
465
  restart = res;
656
466
  return observable.pipe((0, rxjs_2.map)((rawResult) => {
657
- if (fetchPolicy !== "no-cache") {
658
- // the subscription interface should handle not sending us results we no longer subscribe to.
659
- // XXX I don't think we ever send in an object with errors, but we might in the future...
660
- if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
661
- this.cache.write({
662
- query,
663
- result: rawResult.data,
664
- dataId: "ROOT_SUBSCRIPTION",
665
- variables: variables,
666
- });
667
- }
668
- this.broadcastQueries();
669
- }
467
+ queryInfo.markSubscriptionResult(rawResult, {
468
+ document: query,
469
+ variables,
470
+ errorPolicy,
471
+ cacheWriteBehavior: fetchPolicy === "no-cache" ?
472
+ 0 /* CacheWriteBehavior.FORBID */
473
+ : 2 /* CacheWriteBehavior.MERGE */,
474
+ });
670
475
  const result = {
671
476
  data: rawResult.data ?? undefined,
672
477
  };
@@ -782,7 +587,7 @@ class QueryManager {
782
587
  const { operation } = (0, internal_1.getOperationDefinition)(query);
783
588
  (0, invariant_1.invariant)(
784
589
  this.localState,
785
- 90,
590
+ 89,
786
591
  operation[0].toUpperCase() + operation.slice(1),
787
592
  operationName ?? "(anonymous)"
788
593
  );
@@ -806,7 +611,7 @@ class QueryManager {
806
611
  })),
807
612
  };
808
613
  }
809
- getResultsFromLink(queryInfo, cacheWriteBehavior, options) {
614
+ getResultsFromLink(options, { queryInfo, cacheWriteBehavior, observableQuery, }) {
810
615
  const requestId = (queryInfo.lastRequestId = this.generateRequestId());
811
616
  const { errorPolicy } = options;
812
617
  // Performing transformForLink here gives this.cache a chance to fill in
@@ -821,26 +626,35 @@ class QueryManager {
821
626
  if (requestId >= queryInfo.lastRequestId) {
822
627
  if (hasErrors && errorPolicy === "none") {
823
628
  queryInfo.resetLastWrite();
824
- queryInfo.observableQuery?.["resetNotifications"]();
629
+ observableQuery?.["resetNotifications"]();
825
630
  // Throwing here effectively calls observer.error.
826
631
  throw new errors_1.CombinedGraphQLErrors(result);
827
632
  }
828
633
  // Use linkDocument rather than queryInfo.document so the
829
634
  // operation/fragments used to write the result are the same as the
830
635
  // ones used to obtain it from the link.
831
- queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
636
+ queryInfo.markQueryResult(result, {
637
+ ...options,
638
+ document: linkDocument,
639
+ cacheWriteBehavior,
640
+ });
832
641
  }
833
642
  const aqr = {
834
643
  data: result.data,
835
- dataState: result.data ? "complete" : "empty",
836
- loading: false,
837
- networkStatus: networkStatus_js_1.NetworkStatus.ready,
838
- partial: !result.data,
644
+ ...((0, internal_1.isExecutionPatchResult)(result) && result.hasNext ?
645
+ {
646
+ loading: true,
647
+ networkStatus: networkStatus_js_1.NetworkStatus.streaming,
648
+ dataState: "streaming",
649
+ partial: true,
650
+ }
651
+ : {
652
+ dataState: result.data ? "complete" : "empty",
653
+ loading: false,
654
+ networkStatus: networkStatus_js_1.NetworkStatus.ready,
655
+ partial: !result.data,
656
+ }),
839
657
  };
840
- if ((0, internal_1.isExecutionPatchResult)(result) && result.hasNext) {
841
- aqr.dataState = "streaming";
842
- aqr.partial = true;
843
- }
844
658
  // In the case we start multiple network requests simulatenously, we
845
659
  // want to ensure we properly set `data` if we're reporting on an old
846
660
  // result which will not be caught by the conditional above that ends up
@@ -861,7 +675,7 @@ class QueryManager {
861
675
  // Avoid storing errors from older interrupted queries.
862
676
  if (requestId >= queryInfo.lastRequestId && errorPolicy === "none") {
863
677
  queryInfo.resetLastWrite();
864
- queryInfo.observableQuery?.["resetNotifications"]();
678
+ observableQuery?.["resetNotifications"]();
865
679
  throw error;
866
680
  }
867
681
  const aqr = {
@@ -878,11 +692,11 @@ class QueryManager {
878
692
  return (0, rxjs_2.of)(aqr);
879
693
  }));
880
694
  }
881
- fetchObservableWithInfo(queryInfo, options, {
695
+ fetchObservableWithInfo(options, {
882
696
  // The initial networkStatus for this fetch, most often
883
697
  // NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
884
698
  // or setVariables.
885
- networkStatus = networkStatus_js_1.NetworkStatus.loading, query = options.query, fetchQueryOperator = (x) => x, onCacheHit = () => { }, }) {
699
+ networkStatus = networkStatus_js_1.NetworkStatus.loading, query = options.query, fetchQueryOperator = (x) => x, onCacheHit = () => { }, observableQuery, }) {
886
700
  const variables = this.getVariables(query, options.variables);
887
701
  const defaults = this.defaultOptions.watchQuery;
888
702
  let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = true, context = {}, } = options;
@@ -899,6 +713,7 @@ class QueryManager {
899
713
  notifyOnNetworkStatusChange,
900
714
  context,
901
715
  });
716
+ const queryInfo = new QueryInfo_js_1.QueryInfo(this, observableQuery);
902
717
  const fromVariables = (variables) => {
903
718
  // Since normalized is always a fresh copy of options, it's safe to
904
719
  // modify its properties here, rather than creating yet another new
@@ -911,24 +726,23 @@ class QueryManager {
911
726
  normalized.refetchWritePolicy !== "merge") ?
912
727
  1 /* CacheWriteBehavior.OVERWRITE */
913
728
  : 2 /* CacheWriteBehavior.MERGE */;
914
- const observableWithInfo = this.fetchQueryByPolicy(queryInfo, normalized, cacheWriteBehavior, onCacheHit);
729
+ const observableWithInfo = this.fetchQueryByPolicy(normalized, { queryInfo, cacheWriteBehavior, onCacheHit, observableQuery });
915
730
  observableWithInfo.observable =
916
731
  observableWithInfo.observable.pipe(fetchQueryOperator);
917
732
  if (
918
733
  // If we're in standby, postpone advancing options.fetchPolicy using
919
734
  // applyNextFetchPolicy.
920
- normalized.fetchPolicy !== "standby" &&
921
- queryInfo.observableQuery) {
922
- queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
735
+ normalized.fetchPolicy !== "standby") {
736
+ observableQuery?.["applyNextFetchPolicy"]("after-fetch", options);
923
737
  }
924
738
  return observableWithInfo;
925
739
  };
926
740
  // This cancel function needs to be set before the concast is created,
927
741
  // in case concast creation synchronously cancels the request.
928
742
  const cleanupCancelFn = () => {
929
- this.fetchCancelFns.delete(queryInfo.queryId);
743
+ this.fetchCancelFns.delete(queryInfo.id);
930
744
  };
931
- this.fetchCancelFns.set(queryInfo.queryId, (error) => {
745
+ this.fetchCancelFns.set(queryInfo.id, (error) => {
932
746
  fetchCancelSubject.next({
933
747
  kind: "E",
934
748
  error,
@@ -948,7 +762,7 @@ class QueryManager {
948
762
  if (environment_1.__DEV__) {
949
763
  (0, invariant_1.invariant)(
950
764
  this.localState,
951
- 91,
765
+ 90,
952
766
  (0, internal_1.getOperationName)(normalized.query, "(anonymous)")
953
767
  );
954
768
  }
@@ -1120,7 +934,7 @@ class QueryManager {
1120
934
  !this.noCacheWarningsByCause.has(cause)) {
1121
935
  this.noCacheWarningsByCause.add(cause);
1122
936
  __DEV__ && invariant_1.invariant.warn(
1123
- 92,
937
+ 91,
1124
938
  (0, internal_1.getOperationName)(document, `Unnamed ${operationType ?? "operation"}`)
1125
939
  );
1126
940
  }
@@ -1135,12 +949,13 @@ class QueryManager {
1135
949
  (0, masking_1.maskFragment)(data, fragment, this.cache, fragmentName)
1136
950
  : data;
1137
951
  }
1138
- fetchQueryByPolicy(queryInfo, { query, variables, fetchPolicy, errorPolicy, returnPartialData, context, }, cacheWriteBehavior, onCacheHit) {
1139
- queryInfo.init({
1140
- document: query,
952
+ fetchQueryByPolicy({ query, variables, fetchPolicy, errorPolicy, returnPartialData, context, }, { cacheWriteBehavior, onCacheHit, queryInfo, observableQuery, }) {
953
+ const readCache = () => this.cache.diff({
954
+ query,
1141
955
  variables,
956
+ returnPartialData: true,
957
+ optimistic: true,
1142
958
  });
1143
- const readCache = () => this.cache.diff(queryInfo.getDiffOptions());
1144
959
  const resultsFromCache = (diff, networkStatus) => {
1145
960
  const data = diff.result;
1146
961
  if (environment_1.__DEV__ && !returnPartialData && data !== null) {
@@ -1181,7 +996,7 @@ class QueryManager {
1181
996
  if (environment_1.__DEV__) {
1182
997
  (0, invariant_1.invariant)(
1183
998
  this.localState,
1184
- 93,
999
+ 92,
1185
1000
  (0, internal_1.getOperationName)(query, "(anonymous)")
1186
1001
  );
1187
1002
  }
@@ -1211,12 +1026,16 @@ class QueryManager {
1211
1026
  }
1212
1027
  return fromData(data || undefined);
1213
1028
  };
1214
- const resultsFromLink = () => this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
1029
+ const resultsFromLink = () => this.getResultsFromLink({
1215
1030
  query,
1216
1031
  variables,
1217
1032
  context,
1218
1033
  fetchPolicy,
1219
1034
  errorPolicy,
1035
+ }, {
1036
+ cacheWriteBehavior,
1037
+ queryInfo,
1038
+ observableQuery,
1220
1039
  }).pipe(validateDidEmitValue(), (0, rxjs_2.materialize)(), (0, rxjs_2.map)((result) => ({
1221
1040
  ...result,
1222
1041
  source: "network",
@@ -1271,7 +1090,7 @@ function validateDidEmitValue() {
1271
1090
  didEmitValue = true;
1272
1091
  },
1273
1092
  complete() {
1274
- (0, invariant_1.invariant)(didEmitValue, 94);
1093
+ (0, invariant_1.invariant)(didEmitValue, 93);
1275
1094
  },
1276
1095
  });
1277
1096
  }