@apollo/client 4.0.4 → 4.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +31 -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 +5 -5
  9. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  10. package/__cjs/core/ApolloClient.cjs +12 -12
  11. package/__cjs/core/ObservableQuery.cjs +157 -106
  12. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  13. package/__cjs/core/ObservableQuery.d.cts +1 -0
  14. package/__cjs/core/QueryManager.cjs +12 -12
  15. package/__cjs/incremental/handlers/defer20220824.cjs +20 -9
  16. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  17. package/__cjs/incremental/handlers/defer20220824.d.cts +14 -5
  18. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +181 -0
  19. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -0
  20. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +97 -0
  21. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  22. package/__cjs/incremental/index.cjs +3 -1
  23. package/__cjs/incremental/index.cjs.map +1 -1
  24. package/__cjs/incremental/index.d.cts +1 -0
  25. package/__cjs/invariantErrorCodes.cjs +51 -45
  26. package/__cjs/react/internal/cache/QueryReference.cjs +16 -0
  27. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  28. package/__cjs/react/internal/cache/QueryReference.d.cts +1 -0
  29. package/__cjs/utilities/internal/DeepMerger.cjs +10 -1
  30. package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
  31. package/__cjs/utilities/internal/DeepMerger.d.cts +14 -2
  32. package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -0
  33. package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
  34. package/__cjs/version.cjs +1 -1
  35. package/__cjs/version.cjs.map +1 -1
  36. package/cache/core/cache.js +1 -1
  37. package/cache/inmemory/entityStore.js +3 -3
  38. package/cache/inmemory/key-extractor.js +1 -1
  39. package/cache/inmemory/policies.js +4 -4
  40. package/cache/inmemory/policies.js.map +1 -1
  41. package/cache/inmemory/readFromStore.js +2 -2
  42. package/cache/inmemory/writeToStore.js +5 -5
  43. package/cache/inmemory/writeToStore.js.map +1 -1
  44. package/core/ApolloClient.js +12 -12
  45. package/core/ObservableQuery.d.ts +1 -0
  46. package/core/ObservableQuery.js +159 -108
  47. package/core/ObservableQuery.js.map +1 -1
  48. package/core/QueryManager.js +12 -12
  49. package/incremental/handlers/defer20220824.d.ts +14 -5
  50. package/incremental/handlers/defer20220824.js +20 -9
  51. package/incremental/handlers/defer20220824.js.map +1 -1
  52. package/incremental/handlers/graphql17Alpha9.d.ts +97 -0
  53. package/incremental/handlers/graphql17Alpha9.js +177 -0
  54. package/incremental/handlers/graphql17Alpha9.js.map +1 -0
  55. package/incremental/handlers/notImplemented.js +1 -1
  56. package/incremental/index.d.ts +1 -0
  57. package/incremental/index.js +3 -2
  58. package/incremental/index.js.map +1 -1
  59. package/invariantErrorCodes.js +51 -45
  60. package/package.json +1 -1
  61. package/react/internal/cache/QueryReference.d.ts +1 -0
  62. package/react/internal/cache/QueryReference.js +16 -0
  63. package/react/internal/cache/QueryReference.js.map +1 -1
  64. package/utilities/internal/DeepMerger.d.ts +14 -2
  65. package/utilities/internal/DeepMerger.js +10 -1
  66. package/utilities/internal/DeepMerger.js.map +1 -1
  67. package/utilities/internal/getStoreKeyName.js +1 -0
  68. package/utilities/internal/getStoreKeyName.js.map +1 -1
  69. package/version.js +1 -1
  70. package/version.js.map +1 -1
@@ -334,12 +334,18 @@ const client = new ApolloClient({
334
334
  },
335
335
 
336
336
  64: {
337
+ file: "@apollo/client/incremental/handlers/graphql17Alpha9.js",
338
+ condition: "pending",
339
+ message: "Could not find pending chunk for incremental value. Please file an issue for the Apollo Client team to investigate."
340
+ },
341
+
342
+ 65: {
337
343
  file: "@apollo/client/incremental/handlers/notImplemented.js",
338
344
  condition: "!hasDirectives([\"defer\"], request.query)",
339
345
  message: "`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
340
346
  },
341
347
 
342
- 65: {
348
+ 66: {
343
349
  file: "@apollo/client/core/ApolloClient.js",
344
350
  condition: "options.cache",
345
351
 
@@ -348,7 +354,7 @@ const client = new ApolloClient({
348
354
  "For more information, please visit: https://go.apollo.dev/c/docs"
349
355
  },
350
356
 
351
- 66: {
357
+ 67: {
352
358
  file: "@apollo/client/core/ApolloClient.js",
353
359
  condition: "options.link",
354
360
 
@@ -357,7 +363,7 @@ const client = new ApolloClient({
357
363
  "For more information, please visit: https://go.apollo.dev/c/docs"
358
364
  },
359
365
 
360
- 67: {
366
+ 68: {
361
367
  file: "@apollo/client/core/ApolloClient.js",
362
368
  condition: "options.fetchPolicy !== \"cache-and-network\"",
363
369
 
@@ -367,7 +373,7 @@ const client = new ApolloClient({
367
373
  "using a different fetchPolicy, such as cache-first or network-only."
368
374
  },
369
375
 
370
- 68: {
376
+ 69: {
371
377
  file: "@apollo/client/core/ApolloClient.js",
372
378
  condition: "options.fetchPolicy !== \"standby\"",
373
379
 
@@ -376,7 +382,7 @@ const client = new ApolloClient({
376
382
  "as cache-first or network-only."
377
383
  },
378
384
 
379
- 69: {
385
+ 70: {
380
386
  file: "@apollo/client/core/ApolloClient.js",
381
387
  condition: "options.query",
382
388
 
@@ -384,158 +390,158 @@ const client = new ApolloClient({
384
390
  "in the query option."
385
391
  },
386
392
 
387
- 70: {
393
+ 71: {
388
394
  file: "@apollo/client/core/ApolloClient.js",
389
395
  condition: "options.query.kind === \"Document\"",
390
396
  message: 'You must wrap the query string in a "gql" tag.'
391
397
  },
392
398
 
393
- 71: {
399
+ 72: {
394
400
  file: "@apollo/client/core/ApolloClient.js",
395
401
  condition: "!options.returnPartialData",
396
402
  message: "returnPartialData option only supported on watchQuery."
397
403
  },
398
404
 
399
- 72: {
405
+ 73: {
400
406
  file: "@apollo/client/core/ApolloClient.js",
401
407
  condition: "!options.pollInterval",
402
408
  message: "pollInterval option only supported on watchQuery."
403
409
  },
404
410
 
405
- 73: {
411
+ 74: {
406
412
  file: "@apollo/client/core/ApolloClient.js",
407
413
  condition: "!options.notifyOnNetworkStatusChange",
408
414
  message: "notifyOnNetworkStatusChange option only supported on watchQuery."
409
415
  },
410
416
 
411
- 74: {
417
+ 75: {
412
418
  file: "@apollo/client/core/ApolloClient.js",
413
419
  condition: "optionsWithDefaults.mutation",
414
420
  message: "The `mutation` option is required. Please provide a GraphQL document in the `mutation` option."
415
421
  },
416
422
 
417
- 75: {
423
+ 76: {
418
424
  file: "@apollo/client/core/ApolloClient.js",
419
425
  condition: "optionsWithDefaults.fetchPolicy === \"network-only\" ||\n optionsWithDefaults.fetchPolicy === \"no-cache\"",
420
426
  message: "Mutations only support 'network-only' or 'no-cache' fetch policies. The default 'network-only' behavior automatically writes mutation results to the cache. Passing 'no-cache' skips the cache write."
421
427
  },
422
428
 
423
- 78: {
429
+ 79: {
424
430
  file: "@apollo/client/core/ObservableQuery.js",
425
431
  condition: "this.options.fetchPolicy !== \"cache-only\"",
426
432
  message: "Cannot execute `fetchMore` for 'cache-only' query '%s'. Please use a different fetch policy."
427
433
  },
428
434
 
429
- 79: {
435
+ 80: {
430
436
  file: "@apollo/client/core/ObservableQuery.js",
431
437
  condition: "updateQuery",
432
438
  message: "You must provide an `updateQuery` function when using `fetchMore` with a `no-cache` fetch policy."
433
439
  },
434
440
 
435
- 83: {
441
+ 84: {
436
442
  file: "@apollo/client/core/QueryManager.js",
437
443
  message: "QueryManager stopped while query was in flight"
438
444
  },
439
445
 
440
- 84: {
446
+ 85: {
441
447
  file: "@apollo/client/core/QueryManager.js",
442
448
  condition: "this.localState",
443
449
  message: "Mutation '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
444
450
  },
445
451
 
446
- 85: {
452
+ 86: {
447
453
  file: "@apollo/client/core/QueryManager.js",
448
454
  message: "Store reset while query was in flight (not completed in link chain)"
449
455
  },
450
456
 
451
- 88: {
457
+ 89: {
452
458
  file: "@apollo/client/core/QueryManager.js",
453
459
  condition: "!this.getDocumentInfo(query).hasClientExports || this.localState",
454
460
  message: "Subscription '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
455
461
  },
456
462
 
457
- 89: {
463
+ 90: {
458
464
  file: "@apollo/client/core/QueryManager.js",
459
465
  condition: "this.localState",
460
466
  message: "%s '%s' contains `@client` fields but local state has not been configured."
461
467
  },
462
468
 
463
- 90: {
469
+ 91: {
464
470
  file: "@apollo/client/core/QueryManager.js",
465
471
  condition: "!hasIncrementalDirective",
466
472
  message: "%s '%s' contains `@client` and `@defer` directives. These cannot be used together."
467
473
  },
468
474
 
469
- 91: {
475
+ 92: {
470
476
  file: "@apollo/client/core/QueryManager.js",
471
477
  condition: "this.localState",
472
478
  message: "Query '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
473
479
  },
474
480
 
475
- 93: {
481
+ 94: {
476
482
  file: "@apollo/client/core/QueryManager.js",
477
483
  condition: "this.localState",
478
484
  message: "Query '%s' contains `@client` fields but local state has not been configured."
479
485
  },
480
486
 
481
- 94: {
487
+ 95: {
482
488
  file: "@apollo/client/core/QueryManager.js",
483
489
  condition: "didEmitValue",
484
490
  message: "The link chain completed without emitting a value. This is likely unintentional and should be updated to emit a value before completing."
485
491
  },
486
492
 
487
- 95: {
493
+ 96: {
488
494
  file: "@apollo/client/cache/inmemory/entityStore.js",
489
495
  condition: "typeof dataId === \"string\"",
490
496
  message: "store.merge expects a string ID"
491
497
  },
492
498
 
493
- 98: {
499
+ 99: {
494
500
  file: "@apollo/client/cache/inmemory/key-extractor.js",
495
501
  condition: "extracted !== void 0",
496
502
  message: `Missing field '%s' while extracting keyFields from %s`
497
503
  },
498
504
 
499
- 99: {
505
+ 100: {
500
506
  file: "@apollo/client/cache/inmemory/policies.js",
501
507
  condition: "!old || old === which",
502
508
  message: `Cannot change root %s __typename more than once`
503
509
  },
504
510
 
505
- 102: {
511
+ 103: {
506
512
  file: "@apollo/client/cache/inmemory/policies.js",
507
513
  message: "Cannot automatically merge arrays"
508
514
  },
509
515
 
510
- 103: {
516
+ 104: {
511
517
  file: "@apollo/client/cache/inmemory/readFromStore.js",
512
518
  message: `No fragment named %s`
513
519
  },
514
520
 
515
- 104: {
521
+ 105: {
516
522
  file: "@apollo/client/cache/inmemory/readFromStore.js",
517
523
  condition: "!isReference(value)",
518
524
  message: `Missing selection set for object of type %s returned for query field %s`
519
525
  },
520
526
 
521
- 105: {
527
+ 106: {
522
528
  file: "@apollo/client/cache/inmemory/writeToStore.js",
523
529
  message: `Could not identify object %s`
524
530
  },
525
531
 
526
- 107: {
532
+ 108: {
527
533
  file: "@apollo/client/cache/inmemory/writeToStore.js",
528
534
  message: `No fragment named %s`
529
535
  }
530
536
  };
531
537
 
532
538
  export const devDebug = {
533
- 76: {
539
+ 77: {
534
540
  file: "@apollo/client/core/ApolloClient.js",
535
541
  message: `In client.refetchQueries, Promise.all promise rejected with error %o`
536
542
  },
537
543
 
538
- 82: {
544
+ 83: {
539
545
  file: "@apollo/client/core/ObservableQuery.js",
540
546
  message: `Missing cache result fields: %o`
541
547
  }
@@ -603,34 +609,34 @@ export const devWarn = {
603
609
  "If you are using a split link, ensure each branch contains a terminating link that handles the request."
604
610
  },
605
611
 
606
- 77: {
612
+ 78: {
607
613
  file: "@apollo/client/core/ObservableQuery.js",
608
614
 
609
615
  message: `Called refetch(%o) for query %o, which does not declare a $variables variable.
610
616
  Did you mean to call refetch(variables) instead of refetch({ variables })?`
611
617
  },
612
618
 
613
- 81: {
619
+ 82: {
614
620
  file: "@apollo/client/core/ObservableQuery.js",
615
621
  message: "Cannot poll on 'cache-only' query '%s' and as such, polling is disabled. Please use a different fetch policy."
616
622
  },
617
623
 
618
- 86: {
624
+ 87: {
619
625
  file: "@apollo/client/core/QueryManager.js",
620
626
  message: `Unknown query named "%s" requested in refetchQueries options.include array`
621
627
  },
622
628
 
623
- 87: {
629
+ 88: {
624
630
  file: "@apollo/client/core/QueryManager.js",
625
631
  message: `Unknown anonymous query requested in refetchQueries options.include array`
626
632
  },
627
633
 
628
- 92: {
634
+ 93: {
629
635
  file: "@apollo/client/core/QueryManager.js",
630
636
  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.'
631
637
  },
632
638
 
633
- 96: {
639
+ 97: {
634
640
  file: "@apollo/client/cache/inmemory/entityStore.js",
635
641
 
636
642
  message: "cache.modify: You are trying to write a Reference that is not part of the store: %o\n" +
@@ -638,24 +644,24 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`
638
644
  "`toReference(object, true)`"
639
645
  },
640
646
 
641
- 97: {
647
+ 98: {
642
648
  file: "@apollo/client/cache/inmemory/entityStore.js",
643
649
 
644
650
  message: "cache.modify: Writing an array with a mix of both References and Objects will not result in the Objects being normalized correctly.\n" +
645
651
  "Please convert the object instance %o to a Reference before writing it to the cache by calling `toReference(object, true)`."
646
652
  },
647
653
 
648
- 100: {
654
+ 101: {
649
655
  file: "@apollo/client/cache/inmemory/policies.js",
650
656
  message: `Inferring subtype %s of supertype %s`
651
657
  },
652
658
 
653
- 101: {
659
+ 102: {
654
660
  file: "@apollo/client/cache/inmemory/policies.js",
655
661
  message: `Undefined 'from' passed to readField with arguments %s`
656
662
  },
657
663
 
658
- 108: {
664
+ 109: {
659
665
  file: "@apollo/client/cache/inmemory/writeToStore.js",
660
666
 
661
667
  message: `Cache data may be lost when replacing the %s field of a %s object.
@@ -674,7 +680,7 @@ For more information about these options, please refer to the documentation:
674
680
  `
675
681
  },
676
682
 
677
- 109: {
683
+ 110: {
678
684
  file: "@apollo/client/cache/core/cache.js",
679
685
  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."
680
686
  }
@@ -691,12 +697,12 @@ export const devError = {
691
697
  message: "The result of getSnapshot should be cached to avoid an infinite loop"
692
698
  },
693
699
 
694
- 80: {
700
+ 81: {
695
701
  file: "@apollo/client/core/ObservableQuery.js",
696
702
  message: "Unhandled GraphQL subscription error"
697
703
  },
698
704
 
699
- 106: {
705
+ 107: {
700
706
  file: "@apollo/client/cache/inmemory/writeToStore.js",
701
707
  message: `Missing field '%s' while writing result %o`
702
708
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "4.0.4",
3
+ "version": "4.1.0-alpha.0",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -75,6 +75,7 @@ export declare class InternalQueryReference<TData = unknown, TStates extends Dat
75
75
  readonly key: QueryKey;
76
76
  readonly observable: ObservableQuery<TData>;
77
77
  promise: QueryRefPromise<TData, TStates>;
78
+ private queue;
78
79
  private subscription;
79
80
  private listeners;
80
81
  private autoDisposeTimeoutId?;
@@ -37,6 +37,7 @@ export class InternalQueryReference {
37
37
  key = {};
38
38
  observable;
39
39
  promise;
40
+ queue;
40
41
  subscription;
41
42
  listeners = new Set();
42
43
  autoDisposeTimeoutId;
@@ -149,6 +150,10 @@ export class InternalQueryReference {
149
150
  }
150
151
  listen(listener) {
151
152
  this.listeners.add(listener);
153
+ if (this.queue) {
154
+ this.deliver(this.queue);
155
+ this.queue = undefined;
156
+ }
152
157
  return () => {
153
158
  this.listeners.delete(listener);
154
159
  };
@@ -214,6 +219,17 @@ export class InternalQueryReference {
214
219
  }
215
220
  }
216
221
  deliver(promise) {
222
+ // Maintain a queue of the last item we tried to deliver so that we can
223
+ // deliver it as soon as we get the first listener. This helps in cases such
224
+ // as `@stream` where React may render a component and incremental results
225
+ // are loaded in between when the component renders and effects are run. If
226
+ // effects are run after the incremntal chunks are delivered, we'll have
227
+ // rendered a stale value. The queue ensures we can deliver the most
228
+ // up-to-date value as soon as the component is ready to listen for new
229
+ // values.
230
+ if (this.listeners.size === 0) {
231
+ this.queue = promise;
232
+ }
217
233
  this.listeners.forEach((listener) => listener(promise));
218
234
  }
219
235
  initiateFetch(returnedPromise) {