@apollo/client 4.3.3 → 4.3.5

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 (99) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +4 -1
  5. package/__cjs/cache/core/types/Cache.d.cts +5 -0
  6. package/__cjs/cache/inmemory/entityStore.cjs +4 -4
  7. package/__cjs/cache/inmemory/helpers.cjs +5 -0
  8. package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs +17 -6
  10. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  11. package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -1
  12. package/__cjs/cache/inmemory/key-extractor.cjs +15 -3
  13. package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  14. package/__cjs/cache/inmemory/policies.cjs +21 -5
  15. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  16. package/__cjs/cache/inmemory/policies.d.cts +2 -0
  17. package/__cjs/cache/inmemory/readFromStore.cjs +28 -10
  18. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  19. package/__cjs/cache/inmemory/types.d.cts +7 -2
  20. package/__cjs/cache/inmemory/writeToStore.cjs +32 -16
  21. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  22. package/__cjs/cache/inmemory/writeToStore.d.cts +5 -2
  23. package/__cjs/core/ApolloClient.cjs +14 -14
  24. package/__cjs/core/ObservableQuery.cjs +8 -8
  25. package/__cjs/core/QueryInfo.cjs +22 -33
  26. package/__cjs/core/QueryInfo.cjs.map +1 -1
  27. package/__cjs/core/QueryInfo.d.cts +1 -1
  28. package/__cjs/core/QueryManager.cjs +22 -15
  29. package/__cjs/core/QueryManager.cjs.map +1 -1
  30. package/__cjs/core/RefetchEventManager.cjs +3 -3
  31. package/__cjs/incremental/handlers/defer20220824.cjs +15 -2
  32. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  33. package/__cjs/incremental/handlers/defer20220824.d.cts +5 -1
  34. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +58 -14
  35. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  36. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +23 -12
  37. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  38. package/__cjs/incremental/types.d.cts +19 -1
  39. package/__cjs/invariantErrorCodes.cjs +64 -58
  40. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  41. package/__cjs/react/hooks/useFragment.d.cts +42 -43
  42. package/__cjs/utilities/internal/index.cjs.map +1 -1
  43. package/__cjs/utilities/internal/index.d.cts +0 -1
  44. package/__cjs/version.cjs +1 -1
  45. package/cache/core/cache.d.ts +4 -1
  46. package/cache/core/cache.js +1 -1
  47. package/cache/core/cache.js.map +1 -1
  48. package/cache/core/types/Cache.d.ts +5 -0
  49. package/cache/core/types/Cache.js.map +1 -1
  50. package/cache/inmemory/entityStore.js +4 -4
  51. package/cache/inmemory/helpers.js +5 -0
  52. package/cache/inmemory/helpers.js.map +1 -1
  53. package/cache/inmemory/inMemoryCache.d.ts +3 -1
  54. package/cache/inmemory/inMemoryCache.js +17 -6
  55. package/cache/inmemory/inMemoryCache.js.map +1 -1
  56. package/cache/inmemory/key-extractor.js +15 -3
  57. package/cache/inmemory/key-extractor.js.map +1 -1
  58. package/cache/inmemory/policies.d.ts +2 -0
  59. package/cache/inmemory/policies.js +22 -6
  60. package/cache/inmemory/policies.js.map +1 -1
  61. package/cache/inmemory/readFromStore.js +28 -10
  62. package/cache/inmemory/readFromStore.js.map +1 -1
  63. package/cache/inmemory/types.d.ts +7 -2
  64. package/cache/inmemory/types.js.map +1 -1
  65. package/cache/inmemory/writeToStore.d.ts +5 -2
  66. package/cache/inmemory/writeToStore.js +33 -17
  67. package/cache/inmemory/writeToStore.js.map +1 -1
  68. package/core/ApolloClient.js +14 -14
  69. package/core/ObservableQuery.js +8 -8
  70. package/core/QueryInfo.d.ts +1 -1
  71. package/core/QueryInfo.js +23 -34
  72. package/core/QueryInfo.js.map +1 -1
  73. package/core/QueryManager.js +22 -15
  74. package/core/QueryManager.js.map +1 -1
  75. package/core/RefetchEventManager.js +3 -3
  76. package/incremental/handlers/defer20220824.d.ts +5 -1
  77. package/incremental/handlers/defer20220824.js +15 -2
  78. package/incremental/handlers/defer20220824.js.map +1 -1
  79. package/incremental/handlers/graphql17Alpha9.d.ts +23 -12
  80. package/incremental/handlers/graphql17Alpha9.js +58 -14
  81. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  82. package/incremental/handlers/notImplemented.js +1 -1
  83. package/incremental/types.d.ts +19 -1
  84. package/incremental/types.js.map +1 -1
  85. package/invariantErrorCodes.js +64 -58
  86. package/package.json +1 -1
  87. package/react/hooks/useFragment.d.ts +42 -43
  88. package/react/hooks/useFragment.js.map +1 -1
  89. package/react/hooks-compiled/useFragment.d.ts +42 -43
  90. package/react/hooks-compiled/useFragment.js.map +1 -1
  91. package/utilities/internal/index.d.ts +0 -1
  92. package/utilities/internal/index.js.map +1 -1
  93. package/version.js +1 -1
  94. package/__cjs/utilities/internal/types/DeferInfo.cjs +0 -3
  95. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +0 -1
  96. package/__cjs/utilities/internal/types/DeferInfo.d.cts +0 -10
  97. package/utilities/internal/types/DeferInfo.d.ts +0 -10
  98. package/utilities/internal/types/DeferInfo.js +0 -2
  99. package/utilities/internal/types/DeferInfo.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/incremental/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DocumentNode,\n FormattedExecutionResult,\n GraphQLFormattedError,\n} from \"graphql\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\nimport type { DeepPartial, DocumentTransform } from \"@apollo/client/utilities\";\nimport type { StreamInfoTrie } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace Incremental {\n export type Path = ReadonlyArray<string | number>;\n\n export interface PendingResult {\n id: string;\n path: Incremental.Path;\n label?: string;\n }\n\n /** @internal */\n export interface Handler<\n Chunk extends Record<string, unknown> = Record<string, unknown>,\n > {\n isIncrementalResult: (result: ApolloLink.Result<any>) => result is Chunk;\n prepareRequest: (request: ApolloLink.Request) => ApolloLink.Request;\n extractErrors: (\n result: ApolloLink.Result<any>\n ) => readonly GraphQLFormattedError[] | undefined | void;\n startRequest: <TData extends Record<string, unknown>>(\n request: Incremental.StartRequestOptions\n ) => IncrementalRequest<Chunk, TData>;\n readonly documentTransform?: DocumentTransform;\n }\n\n /** @internal */\n export interface StartRequestOptions {\n query: DocumentNode;\n }\n\n export interface IncrementalRequest<\n Chunk extends Record<string, unknown>,\n TData,\n > {\n hasNext: boolean;\n\n /** @internal */\n readonly streamInfo?: StreamInfoTrie;\n /** @internal */\n getPendingWithInfo?: () => Array<PendingItemWithInfo>;\n\n handle: (\n cacheData: TData | DeepPartial<TData> | undefined | null,\n chunk: Chunk\n ) => FormattedExecutionResult<TData>;\n }\n\n /** @internal */\n export interface PendingDeferResultWithInfo {\n type: \"defer\";\n delivered: boolean;\n path: Incremental.Path;\n label: string | undefined;\n }\n\n /** @internal */\n export interface PendingStreamResultWithInfo {\n type: \"stream\";\n path: Incremental.Path;\n }\n\n /** @internal */\n export type PendingItemWithInfo =\n | PendingDeferResultWithInfo\n | PendingStreamResultWithInfo;\n\n /** @internal */\n export interface StreamFieldInfo {\n isFirstChunk: boolean;\n isLastChunk: boolean;\n }\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/incremental/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DocumentNode,\n FormattedExecutionResult,\n GraphQLFormattedError,\n} from \"graphql\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\nimport type { DeepPartial, DocumentTransform } from \"@apollo/client/utilities\";\nimport type { StreamInfoTrie } from \"@apollo/client/utilities/internal\";\n\nexport declare namespace Incremental {\n export type Path = ReadonlyArray<string | number>;\n\n export interface PendingResult {\n id: string;\n path: Incremental.Path;\n label?: string;\n }\n\n /** @internal */\n export interface Handler<\n Chunk extends Record<string, unknown> = Record<string, unknown>,\n > {\n isIncrementalResult: (result: ApolloLink.Result<any>) => result is Chunk;\n prepareRequest: (request: ApolloLink.Request) => ApolloLink.Request;\n extractErrors: (\n result: ApolloLink.Result<any>\n ) => readonly GraphQLFormattedError[] | undefined | void;\n startRequest: <TData extends Record<string, unknown>>(\n request: Incremental.StartRequestOptions\n ) => IncrementalRequest<Chunk, TData>;\n readonly documentTransform?: DocumentTransform;\n }\n\n /** @internal */\n export interface StartRequestOptions {\n query: DocumentNode;\n }\n\n export interface IncrementalRequest<\n Chunk extends Record<string, unknown>,\n TData,\n > {\n hasNext: boolean;\n\n /** @internal Whether this request granularly tracks pending boundaries. */\n tracksPending?: boolean;\n /** @internal */\n readonly streamInfo?: StreamInfoTrie;\n /** @internal */\n markStreamedPendingForTruncation?: () => void;\n /** @internal returns if any defer is pending */\n isDeferPending(): boolean;\n /** @internal returns if a specific defer is pending */\n isDeferPending(path: Incremental.Path, label: string | undefined): boolean;\n\n handle: (\n cacheData: TData | DeepPartial<TData> | undefined | null,\n chunk: Chunk\n ) => FormattedExecutionResult<TData>;\n }\n\n /** @internal */\n export interface PendingDeferResultWithInfo {\n type: \"defer\";\n delivered: boolean;\n path: Incremental.Path;\n label: string | undefined;\n }\n\n /** @internal */\n export interface PendingStreamResultWithInfo {\n type: \"stream\";\n path: Incremental.Path;\n }\n\n /** @internal */\n export type PendingItemWithInfo =\n | PendingDeferResultWithInfo\n | PendingStreamResultWithInfo;\n\n /** @internal */\n export interface StreamFieldInfo {\n isFirstChunk: boolean;\n isLastChunk: boolean;\n }\n}\n"]}
@@ -340,18 +340,24 @@ const client = new ApolloClient({
340
340
  },
341
341
 
342
342
  68: {
343
+ file: "@apollo/client/incremental/handlers/graphql17Alpha9.js",
344
+ condition: "labelNode && labelNode.value.kind === \"StringValue\"",
345
+ message: "Expected a label for @defer directive"
346
+ },
347
+
348
+ 69: {
343
349
  file: "@apollo/client/incremental/handlers/graphql17Alpha9.js",
344
350
  condition: "pending",
345
351
  message: "Could not find pending chunk for incremental value. Please file an issue for the Apollo Client team to investigate."
346
352
  },
347
353
 
348
- 69: {
354
+ 70: {
349
355
  file: "@apollo/client/incremental/handlers/notImplemented.js",
350
356
  condition: "!hasDirectives([\"defer\", \"stream\"], request.query)",
351
357
  message: "`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
352
358
  },
353
359
 
354
- 70: {
360
+ 71: {
355
361
  file: "@apollo/client/core/ApolloClient.js",
356
362
  condition: "options.cache",
357
363
 
@@ -360,7 +366,7 @@ const client = new ApolloClient({
360
366
  "For more information, please visit: https://go.apollo.dev/c/docs"
361
367
  },
362
368
 
363
- 71: {
369
+ 72: {
364
370
  file: "@apollo/client/core/ApolloClient.js",
365
371
  condition: "options.link",
366
372
 
@@ -369,7 +375,7 @@ const client = new ApolloClient({
369
375
  "For more information, please visit: https://go.apollo.dev/c/docs"
370
376
  },
371
377
 
372
- 74: {
378
+ 75: {
373
379
  file: "@apollo/client/core/ApolloClient.js",
374
380
  condition: "options.fetchPolicy !== \"cache-and-network\"",
375
381
 
@@ -379,7 +385,7 @@ const client = new ApolloClient({
379
385
  "using a different fetchPolicy, such as cache-first or network-only."
380
386
  },
381
387
 
382
- 75: {
388
+ 76: {
383
389
  file: "@apollo/client/core/ApolloClient.js",
384
390
  condition: "options.fetchPolicy !== \"standby\"",
385
391
 
@@ -388,7 +394,7 @@ const client = new ApolloClient({
388
394
  "as cache-first or network-only."
389
395
  },
390
396
 
391
- 76: {
397
+ 77: {
392
398
  file: "@apollo/client/core/ApolloClient.js",
393
399
  condition: "options.query",
394
400
 
@@ -396,164 +402,164 @@ const client = new ApolloClient({
396
402
  "in the query option."
397
403
  },
398
404
 
399
- 77: {
405
+ 78: {
400
406
  file: "@apollo/client/core/ApolloClient.js",
401
407
  condition: "options.query.kind === \"Document\"",
402
408
  message: 'You must wrap the query string in a "gql" tag.'
403
409
  },
404
410
 
405
- 78: {
411
+ 79: {
406
412
  file: "@apollo/client/core/ApolloClient.js",
407
413
  condition: "!options.returnPartialData",
408
414
  message: "returnPartialData option only supported on watchQuery."
409
415
  },
410
416
 
411
- 79: {
417
+ 80: {
412
418
  file: "@apollo/client/core/ApolloClient.js",
413
419
  condition: "!options.pollInterval",
414
420
  message: "pollInterval option only supported on watchQuery."
415
421
  },
416
422
 
417
- 80: {
423
+ 81: {
418
424
  file: "@apollo/client/core/ApolloClient.js",
419
425
  condition: "!options.notifyOnNetworkStatusChange",
420
426
  message: "notifyOnNetworkStatusChange option only supported on watchQuery."
421
427
  },
422
428
 
423
- 81: {
429
+ 82: {
424
430
  file: "@apollo/client/core/ApolloClient.js",
425
431
  condition: "optionsWithDefaults.mutation",
426
432
  message: "The `mutation` option is required. Please provide a GraphQL document in the `mutation` option."
427
433
  },
428
434
 
429
- 82: {
435
+ 83: {
430
436
  file: "@apollo/client/core/ApolloClient.js",
431
437
  condition: "optionsWithDefaults.fetchPolicy === \"network-only\" ||\n optionsWithDefaults.fetchPolicy === \"no-cache\"",
432
438
  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."
433
439
  },
434
440
 
435
- 84: {
441
+ 85: {
436
442
  file: "@apollo/client/core/ObservableQuery.js",
437
443
  condition: "fetchPolicy === \"standby\"",
438
444
  message: "The `variablesUnknown` option can only be used together with a `standby` fetch policy."
439
445
  },
440
446
 
441
- 86: {
447
+ 87: {
442
448
  file: "@apollo/client/core/ObservableQuery.js",
443
449
  condition: "this.options.fetchPolicy !== \"cache-only\"",
444
450
  message: "Cannot execute `fetchMore` for 'cache-only' query '%s'. Please use a different fetch policy."
445
451
  },
446
452
 
447
- 87: {
453
+ 88: {
448
454
  file: "@apollo/client/core/ObservableQuery.js",
449
455
  condition: "updateQuery",
450
456
  message: "You must provide an `updateQuery` function when using `fetchMore` with a `no-cache` fetch policy."
451
457
  },
452
458
 
453
- 93: {
459
+ 94: {
454
460
  file: "@apollo/client/core/QueryManager.js",
455
461
  message: "QueryManager stopped while query was in flight"
456
462
  },
457
463
 
458
- 94: {
464
+ 95: {
459
465
  file: "@apollo/client/core/QueryManager.js",
460
466
  condition: "this.localState",
461
467
  message: "Mutation '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
462
468
  },
463
469
 
464
- 95: {
470
+ 96: {
465
471
  file: "@apollo/client/core/QueryManager.js",
466
472
  message: "Store reset while query was in flight (not completed in link chain)"
467
473
  },
468
474
 
469
- 98: {
475
+ 99: {
470
476
  file: "@apollo/client/core/QueryManager.js",
471
477
  condition: "!this.getDocumentInfo(query).hasClientExports || this.localState",
472
478
  message: "Subscription '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
473
479
  },
474
480
 
475
- 99: {
481
+ 100: {
476
482
  file: "@apollo/client/core/QueryManager.js",
477
483
  condition: "this.localState",
478
484
  message: "%s '%s' contains `@client` fields but local state has not been configured."
479
485
  },
480
486
 
481
- 100: {
487
+ 101: {
482
488
  file: "@apollo/client/core/QueryManager.js",
483
489
  condition: "!hasIncrementalDirective",
484
490
  message: "%s '%s' contains `@client` and `@defer` directives. These cannot be used together."
485
491
  },
486
492
 
487
- 101: {
493
+ 102: {
488
494
  file: "@apollo/client/core/QueryManager.js",
489
495
  condition: "this.localState",
490
496
  message: "Query '%s' contains `@client` fields with variables provided by `@export` but local state has not been configured."
491
497
  },
492
498
 
493
- 103: {
499
+ 104: {
494
500
  file: "@apollo/client/core/QueryManager.js",
495
501
  condition: "this.localState",
496
502
  message: "Query '%s' contains `@client` fields but local state has not been configured."
497
503
  },
498
504
 
499
- 104: {
505
+ 105: {
500
506
  file: "@apollo/client/core/QueryManager.js",
501
507
  condition: "didEmitValue",
502
508
  message: "The link chain completed without emitting a value. This is likely unintentional and should be updated to emit a value before completing."
503
509
  },
504
510
 
505
- 108: {
511
+ 109: {
506
512
  file: "@apollo/client/cache/inmemory/entityStore.js",
507
513
  condition: "typeof dataId === \"string\"",
508
514
  message: "store.merge expects a string ID"
509
515
  },
510
516
 
511
- 113: {
517
+ 114: {
512
518
  file: "@apollo/client/cache/inmemory/key-extractor.js",
513
519
  condition: "extracted !== void 0",
514
520
  message: `Missing field '%s' while extracting keyFields from %s`
515
521
  },
516
522
 
517
- 114: {
523
+ 115: {
518
524
  file: "@apollo/client/cache/inmemory/policies.js",
519
525
  condition: "!old || old === which",
520
526
  message: `Cannot change root %s __typename more than once`
521
527
  },
522
528
 
523
- 117: {
529
+ 118: {
524
530
  file: "@apollo/client/cache/inmemory/policies.js",
525
531
  message: "Cannot automatically merge arrays"
526
532
  },
527
533
 
528
- 120: {
534
+ 121: {
529
535
  file: "@apollo/client/cache/inmemory/readFromStore.js",
530
536
  message: `No fragment named %s`
531
537
  },
532
538
 
533
- 121: {
539
+ 122: {
534
540
  file: "@apollo/client/cache/inmemory/readFromStore.js",
535
541
  condition: "!isReference(value)",
536
542
  message: `Missing selection set for object of type %s returned for query field %s`
537
543
  },
538
544
 
539
- 122: {
545
+ 123: {
540
546
  file: "@apollo/client/cache/inmemory/writeToStore.js",
541
547
  message: `Could not identify object %s`
542
548
  },
543
549
 
544
- 124: {
550
+ 125: {
545
551
  file: "@apollo/client/cache/inmemory/writeToStore.js",
546
552
  message: `No fragment named %s`
547
553
  }
548
554
  };
549
555
 
550
556
  export const devDebug = {
551
- 83: {
557
+ 84: {
552
558
  file: "@apollo/client/core/ApolloClient.js",
553
559
  message: `In client.refetchQueries, Promise.all promise rejected with error %o`
554
560
  },
555
561
 
556
- 90: {
562
+ 91: {
557
563
  file: "@apollo/client/core/ObservableQuery.js",
558
564
  message: `Missing cache result fields: %o`
559
565
  }
@@ -636,29 +642,29 @@ export const devWarn = {
636
642
  "If you are using a split link, ensure each branch contains a terminating link that handles the request."
637
643
  },
638
644
 
639
- 72: {
645
+ 73: {
640
646
  file: "@apollo/client/core/ApolloClient.js",
641
647
  message: "`refetchOn` was set on query '%s' but no `RefetchEventManager` is configured on this `ApolloClient` instance. This option has no effect until a RefetchEventManager is connected to this client. Pass a `RefetchEventManager` instance to the `refetchEventManager` option on the `ApolloClient` constructor."
642
648
  },
643
649
 
644
- 73: {
650
+ 74: {
645
651
  file: "@apollo/client/core/ApolloClient.js",
646
652
  message: "`refetchOn` references the '%s' event on query '%s' but no source is configured for it on the `RefetchEventManager`. This event will never fire. Add a source for the event to the `sources` option or call `setEventSource` on the refetch event manager."
647
653
  },
648
654
 
649
- 85: {
655
+ 86: {
650
656
  file: "@apollo/client/core/ObservableQuery.js",
651
657
 
652
658
  message: `Called refetch(%o) for query %o, which does not declare a $variables variable.
653
659
  Did you mean to call refetch(variables) instead of refetch({ variables })?`
654
660
  },
655
661
 
656
- 89: {
662
+ 90: {
657
663
  file: "@apollo/client/core/ObservableQuery.js",
658
664
  message: "Cannot poll on 'cache-only' query '%s' and as such, polling is disabled. Please use a different fetch policy."
659
665
  },
660
666
 
661
- 91: {
667
+ 92: {
662
668
  file: "@apollo/client/core/ObservableQuery.js",
663
669
 
664
670
  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.
@@ -678,7 +684,7 @@ For more information about these options, please refer to the documentation:
678
684
  `
679
685
  },
680
686
 
681
- 92: {
687
+ 93: {
682
688
  file: "@apollo/client/core/QueryInfo.js",
683
689
 
684
690
  message: `The network result for query %s was written to the cache, but reading it back returned a partial result.
@@ -697,37 +703,37 @@ For more information, please refer to the documentation:
697
703
  `
698
704
  },
699
705
 
700
- 96: {
706
+ 97: {
701
707
  file: "@apollo/client/core/QueryManager.js",
702
708
  message: `Unknown query named "%s" requested in refetchQueries options.include array`
703
709
  },
704
710
 
705
- 97: {
711
+ 98: {
706
712
  file: "@apollo/client/core/QueryManager.js",
707
713
  message: `Unknown anonymous query requested in refetchQueries options.include array`
708
714
  },
709
715
 
710
- 102: {
716
+ 103: {
711
717
  file: "@apollo/client/core/QueryManager.js",
712
718
  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.'
713
719
  },
714
720
 
715
- 105: {
721
+ 106: {
716
722
  file: "@apollo/client/core/RefetchEventManager.js",
717
723
  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."
718
724
  },
719
725
 
720
- 106: {
726
+ 107: {
721
727
  file: "@apollo/client/core/RefetchEventManager.js",
722
728
  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."
723
729
  },
724
730
 
725
- 107: {
731
+ 108: {
726
732
  file: "@apollo/client/core/RefetchEventManager.js",
727
733
  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`."
728
734
  },
729
735
 
730
- 109: {
736
+ 110: {
731
737
  file: "@apollo/client/cache/inmemory/entityStore.js",
732
738
 
733
739
  message: "cache.modify: You are trying to write a Reference that is not part of the store: %o\n" +
@@ -735,44 +741,44 @@ For more information, please refer to the documentation:
735
741
  "`toReference(object, true)`"
736
742
  },
737
743
 
738
- 110: {
744
+ 111: {
739
745
  file: "@apollo/client/cache/inmemory/entityStore.js",
740
746
 
741
747
  message: "cache.modify: Writing an array with a mix of both References and Objects will not result in the Objects being normalized correctly.\n" +
742
748
  "Please convert the object instance %o to a Reference before writing it to the cache by calling `toReference(object, true)`."
743
749
  },
744
750
 
745
- 111: {
751
+ 112: {
746
752
  file: "@apollo/client/cache/inmemory/entityStore.js",
747
753
  message: "The custom scalar configuration for '%s' uses list type '%s', but the value is not an array. The value was coerced as '%s' anyway."
748
754
  },
749
755
 
750
- 112: {
756
+ 113: {
751
757
  file: "@apollo/client/cache/inmemory/inMemoryCache.js",
752
758
  message: "The variable '%s' has list type '%s', but the value is not an array. The value was coerced as '%s' anyway."
753
759
  },
754
760
 
755
- 115: {
761
+ 116: {
756
762
  file: "@apollo/client/cache/inmemory/policies.js",
757
763
  message: `Inferring subtype %s of supertype %s`
758
764
  },
759
765
 
760
- 116: {
766
+ 117: {
761
767
  file: "@apollo/client/cache/inmemory/policies.js",
762
768
  message: `Undefined 'from' passed to readField with arguments %s`
763
769
  },
764
770
 
765
- 118: {
771
+ 119: {
766
772
  file: "@apollo/client/cache/inmemory/policies.js",
767
773
  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."
768
774
  },
769
775
 
770
- 119: {
776
+ 120: {
771
777
  file: "@apollo/client/cache/inmemory/readFromStore.js",
772
778
  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."
773
779
  },
774
780
 
775
- 125: {
781
+ 126: {
776
782
  file: "@apollo/client/cache/inmemory/writeToStore.js",
777
783
 
778
784
  message: `Cache data may be lost when replacing the %s field of a %s object.
@@ -791,7 +797,7 @@ For more information about these options, please refer to the documentation:
791
797
  `
792
798
  },
793
799
 
794
- 126: {
800
+ 127: {
795
801
  file: "@apollo/client/cache/core/cache.js",
796
802
  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."
797
803
  }
@@ -808,12 +814,12 @@ export const devError = {
808
814
  message: "The result of getSnapshot should be cached to avoid an infinite loop"
809
815
  },
810
816
 
811
- 88: {
817
+ 89: {
812
818
  file: "@apollo/client/core/ObservableQuery.js",
813
819
  message: "Unhandled GraphQL subscription error"
814
820
  },
815
821
 
816
- 123: {
822
+ 124: {
817
823
  file: "@apollo/client/cache/inmemory/writeToStore.js",
818
824
  message: `Missing field '%s' while writing result %o`
819
825
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "4.3.3",
3
+ "version": "4.3.5",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,53 +1,52 @@
1
1
  import type { ApolloClient, DataValue, DocumentNode, GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
2
2
  import type { ApolloCache, MissingTree } from "@apollo/client/cache";
3
3
  import type { MaybeMasked } from "@apollo/client/masking";
4
+ import type { DocumentationTypes as UtilityDocumentationTypes, VariablesOption } from "@apollo/client/utilities/internal";
4
5
  export declare namespace useFragment {
5
- import _self = useFragment;
6
- interface Options<TData, TVariables extends OperationVariables> {
7
- /**
8
- * A GraphQL document created using the `gql` template string tag from
9
- * `graphql-tag` with one or more fragments which will be used to determine
10
- * the shape of data to read. If you provide more than one fragment in this
11
- * document then you must also specify `fragmentName` to select a single.
12
- */
13
- fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;
14
- /**
15
- * The name of the fragment in your GraphQL document to be used. If you do
16
- * not provide a `fragmentName` and there is only one fragment in your
17
- * `fragment` document then that fragment will be used.
18
- */
19
- fragmentName?: string;
20
- /**
21
- * Any variables that the GraphQL query may depend on.
22
- */
23
- variables?: NoInfer<TVariables>;
24
- /**
25
- * An object or array containing a `__typename` and primary key fields
26
- * (such as `id`) identifying the entity object from which the fragment will
27
- * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID (uncommon).
28
- */
29
- from: useFragment.FromOptionValue<TData> | Array<useFragment.FromOptionValue<TData> | null> | null;
30
- /**
31
- * Whether to read from optimistic or non-optimistic cache data. If
32
- * this named option is provided, the optimistic parameter of the
33
- * readQuery method can be omitted.
34
- *
35
- * @defaultValue true
36
- */
37
- optimistic?: boolean;
38
- /**
39
- * The instance of `ApolloClient` to use to look up the fragment.
40
- *
41
- * By default, the instance that's passed down via context is used, but you
42
- * can provide a different instance here.
43
- *
44
- * @docGroup 1. Operation options
45
- */
46
- client?: ApolloClient;
6
+ namespace Base {
7
+ interface Options<TData, TVariables extends OperationVariables> {
8
+ /**
9
+ * A GraphQL document created using the `gql` template string tag from
10
+ * `graphql-tag` with one or more fragments which will be used to determine
11
+ * the shape of data to read. If you provide more than one fragment in this
12
+ * document then you must also specify `fragmentName` to select a single.
13
+ */
14
+ fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;
15
+ /**
16
+ * The name of the fragment in your GraphQL document to be used. If you do
17
+ * not provide a `fragmentName` and there is only one fragment in your
18
+ * `fragment` document then that fragment will be used.
19
+ */
20
+ fragmentName?: string;
21
+ /**
22
+ * An object or array containing a `__typename` and primary key fields
23
+ * (such as `id`) identifying the entity object from which the fragment will
24
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID (uncommon).
25
+ */
26
+ from: useFragment.FromOptionValue<TData> | Array<useFragment.FromOptionValue<TData> | null> | null;
27
+ /**
28
+ * Whether to read from optimistic or non-optimistic cache data. If
29
+ * this named option is provided, the optimistic parameter of the
30
+ * readQuery method can be omitted.
31
+ *
32
+ * @defaultValue true
33
+ */
34
+ optimistic?: boolean;
35
+ /**
36
+ * The instance of `ApolloClient` to use to look up the fragment.
37
+ *
38
+ * By default, the instance that's passed down via context is used, but you
39
+ * can provide a different instance here.
40
+ *
41
+ * @docGroup 1. Operation options
42
+ */
43
+ client?: ApolloClient;
44
+ }
47
45
  }
46
+ type Options<TData, TVariables extends OperationVariables> = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;
48
47
  namespace DocumentationTypes {
49
48
  namespace useFragment {
50
- interface Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends _self.Options<TData, TVariables> {
49
+ interface Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends Base.Options<TData, TVariables>, UtilityDocumentationTypes.VariableOptions<TVariables> {
51
50
  }
52
51
  }
53
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../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AACJ,CAAC;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,EAAE;IACR,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,KAAK;CAChB,CAA4B,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache, MissingTree } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n import _self = useFragment;\n\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: NoInfer<TVariables>;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useFragment.FromOptionValue<TData>\n | Array<useFragment.FromOptionValue<TData> | null>\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Options<TData, TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | {\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData extends Array<infer TItem> ?\n Array<DataValue.Partial<TItem> | null>\n : DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n };\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData>>;\n }\n): useFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData> | null>;\n }\n): useFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n // We calculate the cache id seperately because we don't want changes to non\n // key fields in the `from` property to recreate the observable. If the cache\n // identifier stays the same between renders, we want to reuse the existing\n // subscription.\n const ids = useDeepMemo(() => {\n const fromArray = Array.isArray(from) ? from : [from];\n\n const ids = fromArray.map((value) =>\n typeof value === \"string\" ? value\n : value === null ? null\n : cache.identify(value)\n );\n\n return Array.isArray(from) ? ids : ids[0];\n }, [cache, from]);\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from: ids as any }),\n [rest, ids]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n );\n\n // Unfortunately we forgot to update the use case of `from: null` on\n // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to\n // fallback to data: {} with complete: false when `from` is `null` to maintain\n // backwards compatibility. We should plan to change this in v5.\n const getSnapshot = React.useCallback(\n () => (from === null ? nullResult : observable.getCurrentResult()),\n [from, observable]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n let lastTimeout = 0;\n const subscription = observable.subscribe({\n next: () => {\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(update) as any;\n },\n });\n\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [observable]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nconst nullResult = Object.freeze({\n data: {},\n dataState: \"partial\",\n complete: false,\n}) as useFragment.Result<any>;\n"]}
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAiB/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC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CAAC;IAEF,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAC9B,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EACzC,CAAC,MAAM,EAAE,aAAa,CAAC,CACxB,CAAC;IAEF,oEAAoE;IACpE,yEAAyE;IACzE,8EAA8E;IAC9E,gEAAgE;IAChE,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACnC,GAAG,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC,EAClE,CAAC,IAAI,EAAE,UAAU,CAAC,CACnB,CAAC;IAEF,OAAO,oBAAoB,CACzB,KAAK,CAAC,WAAW,CACf,CAAC,MAAM,EAAE,EAAE;QACT,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC;YACxC,IAAI,EAAE,GAAG,EAAE;gBACT,iEAAiE;gBACjE,kEAAkE;gBAClE,6DAA6D;gBAC7D,qEAAqE;gBACrE,YAAY,CAAC,WAAW,CAAC,CAAC;gBAC1B,WAAW,GAAG,UAAU,CAAC,MAAM,CAAQ,CAAC;YAC1C,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,WAAW,EAAE,CAAC;YAC3B,YAAY,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,UAAU,CAAC,CACb,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,EAAE;IACR,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,KAAK;CAChB,CAA4B,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache, MissingTree } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n export namespace Base {\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useFragment.FromOptionValue<TData>\n | Array<useFragment.FromOptionValue<TData> | null>\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n }\n\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | {\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData extends Array<infer TItem> ?\n Array<DataValue.Partial<TItem> | null>\n : DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n };\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData>>;\n }\n): useFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData> | null>;\n }\n): useFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n // We calculate the cache id seperately because we don't want changes to non\n // key fields in the `from` property to recreate the observable. If the cache\n // identifier stays the same between renders, we want to reuse the existing\n // subscription.\n const ids = useDeepMemo(() => {\n const fromArray = Array.isArray(from) ? from : [from];\n\n const ids = fromArray.map((value) =>\n typeof value === \"string\" ? value\n : value === null ? null\n : cache.identify(value)\n );\n\n return Array.isArray(from) ? ids : ids[0];\n }, [cache, from]);\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from: ids as any }),\n [rest, ids]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n );\n\n // Unfortunately we forgot to update the use case of `from: null` on\n // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to\n // fallback to data: {} with complete: false when `from` is `null` to maintain\n // backwards compatibility. We should plan to change this in v5.\n const getSnapshot = React.useCallback(\n () => (from === null ? nullResult : observable.getCurrentResult()),\n [from, observable]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n let lastTimeout = 0;\n const subscription = observable.subscribe({\n next: () => {\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(update) as any;\n },\n });\n\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [observable]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nconst nullResult = Object.freeze({\n data: {},\n dataState: \"partial\",\n complete: false,\n}) as useFragment.Result<any>;\n"]}