@apollo/client 4.3.0-alpha.6 → 4.3.0-alpha.7

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 (36) hide show
  1. package/CHANGELOG.md +12 -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 +5 -5
  6. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  7. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  8. package/__cjs/core/ObservableQuery.cjs +166 -54
  9. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  10. package/__cjs/core/ObservableQuery.d.cts +3 -6
  11. package/__cjs/core/QueryInfo.cjs +11 -125
  12. package/__cjs/core/QueryInfo.cjs.map +1 -1
  13. package/__cjs/core/QueryInfo.d.cts +0 -24
  14. package/__cjs/core/QueryManager.cjs +12 -14
  15. package/__cjs/core/QueryManager.cjs.map +1 -1
  16. package/__cjs/core/RefetchEventManager.cjs +3 -3
  17. package/__cjs/invariantErrorCodes.cjs +52 -32
  18. package/__cjs/version.cjs +1 -1
  19. package/cache/core/cache.js +1 -1
  20. package/cache/inmemory/entityStore.js +3 -3
  21. package/cache/inmemory/key-extractor.js +1 -1
  22. package/cache/inmemory/policies.js +5 -5
  23. package/cache/inmemory/readFromStore.js +3 -3
  24. package/cache/inmemory/writeToStore.js +4 -4
  25. package/core/ObservableQuery.d.ts +3 -6
  26. package/core/ObservableQuery.js +162 -54
  27. package/core/ObservableQuery.js.map +1 -1
  28. package/core/QueryInfo.d.ts +1 -25
  29. package/core/QueryInfo.js +11 -125
  30. package/core/QueryInfo.js.map +1 -1
  31. package/core/QueryManager.js +12 -14
  32. package/core/QueryManager.js.map +1 -1
  33. package/core/RefetchEventManager.js +3 -3
  34. package/invariantErrorCodes.js +52 -32
  35. package/package.json +1 -1
  36. package/version.js +1 -1
@@ -34,7 +34,7 @@ class RefetchEventManager {
34
34
  }
35
35
  if (this.client) {
36
36
  if (environment_1.__DEV__) {
37
- __DEV__ && invariant_1.invariant.warn(102);
37
+ __DEV__ && invariant_1.invariant.warn(103);
38
38
  }
39
39
  this.disconnect();
40
40
  }
@@ -103,13 +103,13 @@ class RefetchEventManager {
103
103
  const [payload] = args;
104
104
  if (!this.client) {
105
105
  if (environment_1.__DEV__) {
106
- __DEV__ && invariant_1.invariant.warn(103, source);
106
+ __DEV__ && invariant_1.invariant.warn(104, source);
107
107
  }
108
108
  return;
109
109
  }
110
110
  if (!this.hasSource(source)) {
111
111
  if (environment_1.__DEV__) {
112
- __DEV__ && invariant_1.invariant.warn(104, source);
112
+ __DEV__ && invariant_1.invariant.warn(105, source);
113
113
  }
114
114
  return;
115
115
  }
@@ -450,98 +450,98 @@ const client = new ApolloClient({
450
450
  message: "You must provide an `updateQuery` function when using `fetchMore` with a `no-cache` fetch policy."
451
451
  },
452
452
 
453
- 90: {
453
+ 91: {
454
454
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
455
455
  message: "QueryManager stopped while query was in flight"
456
456
  },
457
457
 
458
- 91: {
458
+ 92: {
459
459
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
460
460
  condition: "this.localState",
461
461
  message: "Mutation '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
462
462
  },
463
463
 
464
- 92: {
464
+ 93: {
465
465
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
466
466
  message: "Store reset while query was in flight (not completed in link chain)"
467
467
  },
468
468
 
469
- 95: {
469
+ 96: {
470
470
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
471
471
  condition: "!this.getDocumentInfo(query).hasClientExports || this.localState",
472
472
  message: "Subscription '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
473
473
  },
474
474
 
475
- 96: {
475
+ 97: {
476
476
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
477
477
  condition: "this.localState",
478
478
  message: "%s '%s' contains `@client` fields but local state has not been configured."
479
479
  },
480
480
 
481
- 97: {
481
+ 98: {
482
482
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
483
483
  condition: "!hasIncrementalDirective",
484
484
  message: "%s '%s' contains `@client` and `@defer` directives. These cannot be used together."
485
485
  },
486
486
 
487
- 98: {
487
+ 99: {
488
488
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
489
489
  condition: "this.localState",
490
490
  message: "Query '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
491
491
  },
492
492
 
493
- 100: {
493
+ 101: {
494
494
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
495
495
  condition: "this.localState",
496
496
  message: "Query '%s' contains `@client` fields but local state has not been configured."
497
497
  },
498
498
 
499
- 101: {
499
+ 102: {
500
500
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
501
501
  condition: "didEmitValue",
502
502
  message: "The link chain completed without emitting a value. This is likely unintentional and should be updated to emit a value before completing."
503
503
  },
504
504
 
505
- 105: {
505
+ 106: {
506
506
  file: "@apollo/client/__cjs/cache/inmemory/entityStore.cjs",
507
507
  condition: "typeof dataId === \"string\"",
508
508
  message: "store.merge expects a string ID"
509
509
  },
510
510
 
511
- 108: {
511
+ 109: {
512
512
  file: "@apollo/client/__cjs/cache/inmemory/key-extractor.cjs",
513
513
  condition: "extracted !== void 0",
514
514
  message: `Missing field '%s' while extracting keyFields from %s`
515
515
  },
516
516
 
517
- 109: {
517
+ 110: {
518
518
  file: "@apollo/client/__cjs/cache/inmemory/policies.cjs",
519
519
  condition: "!old || old === which",
520
520
  message: `Cannot change root %s __typename more than once`
521
521
  },
522
522
 
523
- 112: {
523
+ 113: {
524
524
  file: "@apollo/client/__cjs/cache/inmemory/policies.cjs",
525
525
  message: "Cannot automatically merge arrays"
526
526
  },
527
527
 
528
- 115: {
528
+ 116: {
529
529
  file: "@apollo/client/__cjs/cache/inmemory/readFromStore.cjs",
530
530
  message: `No fragment named %s`
531
531
  },
532
532
 
533
- 116: {
533
+ 117: {
534
534
  file: "@apollo/client/__cjs/cache/inmemory/readFromStore.cjs",
535
535
  condition: "!(0, utilities_1.isReference)(value)",
536
536
  message: `Missing selection set for object of type %s returned for query field %s`
537
537
  },
538
538
 
539
- 117: {
539
+ 118: {
540
540
  file: "@apollo/client/__cjs/cache/inmemory/writeToStore.cjs",
541
541
  message: `Could not identify object %s`
542
542
  },
543
543
 
544
- 119: {
544
+ 120: {
545
545
  file: "@apollo/client/__cjs/cache/inmemory/writeToStore.cjs",
546
546
  message: `No fragment named %s`
547
547
  }
@@ -654,6 +654,26 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`
654
654
  },
655
655
 
656
656
  89: {
657
+ file: "@apollo/client/__cjs/core/ObservableQuery.cjs",
658
+
659
+ message: `Apollo Client stopped refetching '%s' because the same incomplete cache result was already refetched. Automatic refetching was halted to prevent an endless cycle of network requests.
660
+
661
+ This often means another query is overwriting non-normalized data selected by this query. Common fixes:
662
+
663
+ * Select an \`id\` or \`_id\` field in each query that writes the object
664
+ * Set custom \`keyFields\` if the object uses a different identity
665
+ * Add a field \`merge\` function so partial writes combine instead of replace
666
+
667
+ missing fields: %o
668
+
669
+ For more information about these options, please refer to the documentation:
670
+
671
+ * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers
672
+ * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects
673
+ `
674
+ },
675
+
676
+ 90: {
657
677
  file: "@apollo/client/__cjs/core/QueryInfo.cjs",
658
678
 
659
679
  message: `The network result for query %s was written to the cache, but reading it back returned a partial result.
@@ -672,37 +692,37 @@ For more information, please refer to the documentation:
672
692
  `
673
693
  },
674
694
 
675
- 93: {
695
+ 94: {
676
696
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
677
697
  message: `Unknown query named "%s" requested in refetchQueries options.include array`
678
698
  },
679
699
 
680
- 94: {
700
+ 95: {
681
701
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
682
702
  message: `Unknown anonymous query requested in refetchQueries options.include array`
683
703
  },
684
704
 
685
- 99: {
705
+ 100: {
686
706
  file: "@apollo/client/__cjs/core/QueryManager.cjs",
687
707
  message: '[%s]: Fragments masked by data masking are inaccessible when using fetch policy "no-cache". Please add `@unmask` to each fragment spread to access the data.'
688
708
  },
689
709
 
690
- 102: {
710
+ 103: {
691
711
  file: "@apollo/client/__cjs/core/RefetchEventManager.cjs",
692
712
  message: "Connected an `ApolloClient` instance to a `RefetchEventManager` that was already connected to a different `ApolloClient`. The previous client has been disconnected and will no longer receive refetch events from this manager."
693
713
  },
694
714
 
695
- 103: {
715
+ 104: {
696
716
  file: "@apollo/client/__cjs/core/RefetchEventManager.cjs",
697
717
  message: "Received '%s' event but an `ApolloClient` instance is not connected to the `RefetchEventManager`. No queries will refetch. Pass the manager to the `refetchEventManager` option on the `ApolloClient` constructor."
698
718
  },
699
719
 
700
- 104: {
720
+ 105: {
701
721
  file: "@apollo/client/__cjs/core/RefetchEventManager.cjs",
702
722
  message: "Received '%s' event but no source is configured for it on the `RefetchEventManager`. No queries will refetch. Add the event to the `sources` option or call `setEventSource`."
703
723
  },
704
724
 
705
- 106: {
725
+ 107: {
706
726
  file: "@apollo/client/__cjs/cache/inmemory/entityStore.cjs",
707
727
 
708
728
  message: "cache.modify: You are trying to write a Reference that is not part of the store: %o\n" +
@@ -710,34 +730,34 @@ For more information, please refer to the documentation:
710
730
  "`toReference(object, true)`"
711
731
  },
712
732
 
713
- 107: {
733
+ 108: {
714
734
  file: "@apollo/client/__cjs/cache/inmemory/entityStore.cjs",
715
735
 
716
736
  message: "cache.modify: Writing an array with a mix of both References and Objects will not result in the Objects being normalized correctly.\n" +
717
737
  "Please convert the object instance %o to a Reference before writing it to the cache by calling `toReference(object, true)`."
718
738
  },
719
739
 
720
- 110: {
740
+ 111: {
721
741
  file: "@apollo/client/__cjs/cache/inmemory/policies.cjs",
722
742
  message: `Inferring subtype %s of supertype %s`
723
743
  },
724
744
 
725
- 111: {
745
+ 112: {
726
746
  file: "@apollo/client/__cjs/cache/inmemory/policies.cjs",
727
747
  message: `Undefined 'from' passed to readField with arguments %s`
728
748
  },
729
749
 
730
- 113: {
750
+ 114: {
731
751
  file: "@apollo/client/__cjs/cache/inmemory/policies.cjs",
732
752
  message: "The field policy for '%s' is configured with the '%s' scalar, so its '%s' function is ignored. Scalar configuration cannot be used with custom read or merge functions."
733
753
  },
734
754
 
735
- 114: {
755
+ 115: {
736
756
  file: "@apollo/client/__cjs/cache/inmemory/readFromStore.cjs",
737
757
  message: "The field policy for '%s' is configured with the '%s' scalar, but the field is not a scalar field because it contains a selection set. The field value remains unchanged."
738
758
  },
739
759
 
740
- 120: {
760
+ 121: {
741
761
  file: "@apollo/client/__cjs/cache/inmemory/writeToStore.cjs",
742
762
 
743
763
  message: `Cache data may be lost when replacing the %s field of a %s object.
@@ -756,7 +776,7 @@ For more information about these options, please refer to the documentation:
756
776
  `
757
777
  },
758
778
 
759
- 121: {
779
+ 122: {
760
780
  file: "@apollo/client/__cjs/cache/core/cache.cjs",
761
781
  message: "Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
762
782
  }
@@ -778,7 +798,7 @@ exports.devError = {
778
798
  message: "Unhandled GraphQL subscription error"
779
799
  },
780
800
 
781
- 118: {
801
+ 119: {
782
802
  file: "@apollo/client/__cjs/cache/inmemory/writeToStore.cjs",
783
803
  message: `Missing field '%s' while writing result %o`
784
804
  }
package/__cjs/version.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = exports.version = void 0;
4
- exports.version = "4.3.0-alpha.6";
4
+ exports.version = "4.3.0-alpha.7";
5
5
  exports.build = "cjs";
6
6
  //# sourceMappingURL=version.cjs.map
@@ -140,7 +140,7 @@ export class ApolloCache {
140
140
  if (__DEV__) {
141
141
  const actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
142
142
  if (id === undefined) {
143
- __DEV__ && invariant.warn(121, actualFragmentName);
143
+ __DEV__ && invariant.warn(122, actualFragmentName);
144
144
  }
145
145
  }
146
146
  return id;
@@ -73,7 +73,7 @@ export class EntityStore {
73
73
  // then there are no fields to be merged, so we're done.
74
74
  if (!incoming)
75
75
  return;
76
- invariant(typeof dataId === "string", 105);
76
+ invariant(typeof dataId === "string", 106);
77
77
  // Parse all scalars before merging so that the storeObjectReconciler can
78
78
  // deep compare the parsed value with the existing value
79
79
  incoming = this.coerceStoreObject(incoming, (scalar, value) => scalar.coerceToParsed(value), incoming.__typename ||
@@ -180,7 +180,7 @@ export class EntityStore {
180
180
  if (__DEV__) {
181
181
  const checkReference = (ref) => {
182
182
  if (this.lookup(ref.__ref) === undefined) {
183
- __DEV__ && invariant.warn(106, ref);
183
+ __DEV__ && invariant.warn(107, ref);
184
184
  return true;
185
185
  }
186
186
  };
@@ -209,7 +209,7 @@ export class EntityStore {
209
209
  }
210
210
  }
211
211
  if (seenReference && someNonReference !== undefined) {
212
- __DEV__ && invariant.warn(107, someNonReference);
212
+ __DEV__ && invariant.warn(108, someNonReference);
213
213
  break;
214
214
  }
215
215
  }
@@ -34,7 +34,7 @@ export function keyFieldsFnFromSpecifier(specifier) {
34
34
  // context.readField for this extraction.
35
35
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
36
36
  }
37
- invariant(extracted !== void 0, 108, schemaKeyPath.join("."), object);
37
+ invariant(extracted !== void 0, 109, schemaKeyPath.join("."), object);
38
38
  return extracted;
39
39
  }));
40
40
  return `${context.typename}:${JSON.stringify(keyObject)}`;
@@ -242,7 +242,7 @@ export class Policies {
242
242
  const rootId = "ROOT_" + which.toUpperCase();
243
243
  const old = this.rootTypenamesById[rootId];
244
244
  if (typename !== old) {
245
- invariant(!old || old === which, 109, which);
245
+ invariant(!old || old === which, 110, which);
246
246
  // First, delete any old __typename associated with this rootId from
247
247
  // rootIdsByTypename.
248
248
  if (old)
@@ -385,7 +385,7 @@ export class Policies {
385
385
  if (supertypeSet.has(supertype)) {
386
386
  if (!typenameSupertypeSet.has(supertype)) {
387
387
  if (checkingFuzzySubtypes) {
388
- __DEV__ && invariant.warn(110, typename, supertype);
388
+ __DEV__ && invariant.warn(111, typename, supertype);
389
389
  }
390
390
  // Record positive results for faster future lookup.
391
391
  // Unfortunately, we cannot safely cache negative results,
@@ -641,7 +641,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
641
641
  }
642
642
  }
643
643
  if (__DEV__ && options.from === void 0) {
644
- __DEV__ && invariant.warn(111, stringifyForDisplay(Array.from(readFieldArgs)));
644
+ __DEV__ && invariant.warn(112, stringifyForDisplay(Array.from(readFieldArgs)));
645
645
  }
646
646
  if (void 0 === options.variables) {
647
647
  options.variables = variables;
@@ -651,7 +651,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
651
651
  function makeMergeObjectsFunction(store) {
652
652
  return function mergeObjects(existing, incoming) {
653
653
  if (isArray(existing) || isArray(incoming)) {
654
- throw newInvariantError(112);
654
+ throw newInvariantError(113);
655
655
  }
656
656
  // These dynamic checks are necessary because the parameters of a
657
657
  // custom merge function can easily have the any type, so the type
@@ -688,6 +688,6 @@ function makeMergeObjectsFunction(store) {
688
688
  };
689
689
  }
690
690
  function warnAboutScalarConfig(typename, fieldName, scalar, kind) {
691
- __DEV__ && invariant.warn(113, `${typename}.${fieldName}`, scalar, kind);
691
+ __DEV__ && invariant.warn(114, `${typename}.${fieldName}`, scalar, kind);
692
692
  }
693
693
  //# sourceMappingURL=policies.js.map
@@ -282,7 +282,7 @@ export class StoreReader {
282
282
  if (typename) {
283
283
  const policy = policies["getFieldPolicy"](typename, fieldName);
284
284
  if (policy?.scalar) {
285
- __DEV__ && invariant.warn(114, `${typename}.${fieldName}`, policy.scalar);
285
+ __DEV__ && invariant.warn(115, `${typename}.${fieldName}`, policy.scalar);
286
286
  }
287
287
  }
288
288
  }
@@ -319,7 +319,7 @@ export class StoreReader {
319
319
  else {
320
320
  const fragment = getFragmentFromSelection(selection, context.lookupFragment);
321
321
  if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
322
- throw newInvariantError(115, selection.name.value);
322
+ throw newInvariantError(116, selection.name.value);
323
323
  }
324
324
  if (fragment && policies.fragmentMatches(fragment, typename)) {
325
325
  const isDeferBoundary = isDeferredFragment(selection, context.variables);
@@ -616,7 +616,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
616
616
  if (isNonNullObject(value)) {
617
617
  invariant(
618
618
  !isReference(value),
619
- 116,
619
+ 117,
620
620
  getTypenameFromStoreObject(store, value),
621
621
  field.name.value
622
622
  );
@@ -68,7 +68,7 @@ export class StoreWriter {
68
68
  path: [],
69
69
  });
70
70
  if (!isReference(ref)) {
71
- throw newInvariantError(117, result);
71
+ throw newInvariantError(118, result);
72
72
  }
73
73
  // So far, the store has not been modified, so now it's time to process
74
74
  // context.incomingById and merge those incoming fields into context.store.
@@ -230,7 +230,7 @@ export class StoreWriter {
230
230
  // provide a default value, so its absence from the written data should
231
231
  // not be cause for alarm.
232
232
  !policies.getReadFunction(typename, field.name.value)) {
233
- invariant.error(118, resultKeyNameFromField(field), result);
233
+ invariant.error(119, resultKeyNameFromField(field), result);
234
234
  }
235
235
  });
236
236
  // Identify the result object, even if dataId was already provided,
@@ -378,7 +378,7 @@ export class StoreWriter {
378
378
  else {
379
379
  const fragment = getFragmentFromSelection(selection, context.lookupFragment);
380
380
  if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
381
- throw newInvariantError(119, selection.name.value);
381
+ throw newInvariantError(120, selection.name.value);
382
382
  }
383
383
  if (fragment &&
384
384
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -550,7 +550,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
550
550
  }
551
551
  });
552
552
  }
553
- __DEV__ && invariant.warn(120, fieldName, parentType, childTypenames.length ?
553
+ __DEV__ && invariant.warn(121, fieldName, parentType, childTypenames.length ?
554
554
  "either ensure all objects of type " +
555
555
  childTypenames.join(" and ") +
556
556
  " have an ID or a custom merge function, or "
@@ -278,12 +278,8 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
278
278
  readonly options: ObservableQuery.Options<TData, TVariables>;
279
279
  readonly queryName?: string;
280
280
  private variablesUnknown;
281
- /**
282
- * @internal will be read and written from `QueryInfo`
283
- *
284
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
285
- */
286
- _lastWrite?: unknown;
281
+ private didWarnOnFeud;
282
+ private lastMissing?;
287
283
  get query(): TypedDocumentNode<TData, TVariables>;
288
284
  /**
289
285
  * An object containing the variables that were provided for the query.
@@ -469,6 +465,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
469
465
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
470
466
  */
471
467
  notify(scheduled?: boolean): void;
468
+ private deliverCacheDiff;
472
469
  private activeOperations;
473
470
  private pushOperation;
474
471
  private calculateNetworkStatus;