@apollo/client 4.0.0-alpha.16 → 4.0.0-alpha.18

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 (130) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/__cjs/core/ObservableQuery.cjs +104 -48
  3. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  4. package/__cjs/core/ObservableQuery.d.cts +19 -2
  5. package/__cjs/core/QueryInfo.cjs.map +1 -1
  6. package/__cjs/core/QueryManager.cjs +19 -2
  7. package/__cjs/core/QueryManager.cjs.map +1 -1
  8. package/__cjs/core/index.cjs.map +1 -1
  9. package/__cjs/core/index.d.cts +1 -1
  10. package/__cjs/core/types.d.cts +25 -3
  11. package/__cjs/masking/GraphQLCodegenDataMasking.cjs +3 -0
  12. package/__cjs/masking/GraphQLCodegenDataMasking.cjs.map +1 -0
  13. package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +79 -0
  14. package/__cjs/masking/index.cjs.map +1 -1
  15. package/__cjs/masking/index.d.cts +1 -0
  16. package/__cjs/masking/types.d.cts +11 -26
  17. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  18. package/__cjs/react/hooks/useBackgroundQuery.d.cts +50 -14
  19. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  20. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  21. package/__cjs/react/hooks/useLazyQuery.d.cts +28 -53
  22. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  23. package/__cjs/react/hooks/useLoadableQuery.d.cts +7 -8
  24. package/__cjs/react/hooks/useQuery.cjs +3 -2
  25. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  26. package/__cjs/react/hooks/useQuery.d.cts +10 -48
  27. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  28. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +2 -2
  29. package/__cjs/react/hooks/useReadQuery.cjs +1 -0
  30. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  31. package/__cjs/react/hooks/useReadQuery.d.cts +4 -11
  32. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
  33. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  34. package/__cjs/react/hooks/useSuspenseQuery.d.cts +12 -24
  35. package/__cjs/react/index.cjs.map +1 -1
  36. package/__cjs/react/index.d.cts +1 -1
  37. package/__cjs/react/internal/cache/QueryReference.cjs +7 -1
  38. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  39. package/__cjs/react/internal/cache/QueryReference.d.cts +25 -65
  40. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  41. package/__cjs/react/internal/cache/SuspenseCache.d.cts +3 -3
  42. package/__cjs/react/internal/index.cjs.map +1 -1
  43. package/__cjs/react/internal/index.d.cts +1 -1
  44. package/__cjs/react/internal/types.d.cts +2 -2
  45. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  46. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +4 -5
  47. package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
  48. package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
  49. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  50. package/__cjs/react/types/types.documentation.d.cts +12 -0
  51. package/__cjs/utilities/HKT.cjs +3 -0
  52. package/__cjs/utilities/HKT.cjs.map +1 -0
  53. package/__cjs/utilities/HKT.d.cts +35 -0
  54. package/__cjs/utilities/index.cjs.map +1 -1
  55. package/__cjs/utilities/index.d.cts +1 -0
  56. package/__cjs/utilities/internal/index.cjs.map +1 -1
  57. package/__cjs/utilities/internal/index.d.cts +2 -0
  58. package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
  59. package/__cjs/utilities/internal/types/ApplyHKT.cjs +3 -0
  60. package/__cjs/utilities/internal/types/ApplyHKT.cjs.map +1 -0
  61. package/__cjs/utilities/internal/types/ApplyHKT.d.cts +13 -0
  62. package/__cjs/utilities/internal/types/ApplyHKTImplementationWithDefault.cjs +3 -0
  63. package/__cjs/utilities/internal/types/ApplyHKTImplementationWithDefault.cjs.map +1 -0
  64. package/__cjs/utilities/internal/types/ApplyHKTImplementationWithDefault.d.cts +11 -0
  65. package/__cjs/version.cjs +1 -1
  66. package/core/ObservableQuery.d.ts +19 -2
  67. package/core/ObservableQuery.js +105 -49
  68. package/core/ObservableQuery.js.map +1 -1
  69. package/core/QueryInfo.js.map +1 -1
  70. package/core/QueryManager.js +19 -2
  71. package/core/QueryManager.js.map +1 -1
  72. package/core/index.d.ts +1 -1
  73. package/core/index.js.map +1 -1
  74. package/core/types.d.ts +25 -3
  75. package/masking/GraphQLCodegenDataMasking.d.ts +79 -0
  76. package/masking/GraphQLCodegenDataMasking.js +2 -0
  77. package/masking/GraphQLCodegenDataMasking.js.map +1 -0
  78. package/masking/index.d.ts +1 -0
  79. package/masking/index.js.map +1 -1
  80. package/masking/types.d.ts +11 -26
  81. package/package.json +1 -1
  82. package/react/hooks/useBackgroundQuery.d.ts +50 -14
  83. package/react/hooks/useBackgroundQuery.js.map +1 -1
  84. package/react/hooks/useLazyQuery.d.ts +28 -53
  85. package/react/hooks/useLazyQuery.js +1 -0
  86. package/react/hooks/useLazyQuery.js.map +1 -1
  87. package/react/hooks/useLoadableQuery.d.ts +7 -8
  88. package/react/hooks/useLoadableQuery.js.map +1 -1
  89. package/react/hooks/useQuery.d.ts +10 -48
  90. package/react/hooks/useQuery.js +3 -2
  91. package/react/hooks/useQuery.js.map +1 -1
  92. package/react/hooks/useQueryRefHandlers.d.ts +2 -2
  93. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  94. package/react/hooks/useReadQuery.d.ts +4 -11
  95. package/react/hooks/useReadQuery.js +1 -0
  96. package/react/hooks/useReadQuery.js.map +1 -1
  97. package/react/hooks/useSuspenseQuery.d.ts +12 -24
  98. package/react/hooks/useSuspenseQuery.js +2 -0
  99. package/react/hooks/useSuspenseQuery.js.map +1 -1
  100. package/react/index.d.ts +1 -1
  101. package/react/index.js.map +1 -1
  102. package/react/internal/cache/QueryReference.d.ts +25 -65
  103. package/react/internal/cache/QueryReference.js +7 -1
  104. package/react/internal/cache/QueryReference.js.map +1 -1
  105. package/react/internal/cache/SuspenseCache.d.ts +3 -3
  106. package/react/internal/cache/SuspenseCache.js.map +1 -1
  107. package/react/internal/index.d.ts +1 -1
  108. package/react/internal/index.js.map +1 -1
  109. package/react/internal/types.d.ts +2 -2
  110. package/react/query-preloader/createQueryPreloader.d.ts +4 -5
  111. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  112. package/react/ssr/prerenderStatic.js.map +1 -1
  113. package/react/ssr/useSSRQuery.js +1 -0
  114. package/react/ssr/useSSRQuery.js.map +1 -1
  115. package/react/types/types.documentation.d.ts +12 -0
  116. package/utilities/HKT.d.ts +35 -0
  117. package/utilities/HKT.js +2 -0
  118. package/utilities/HKT.js.map +1 -0
  119. package/utilities/index.d.ts +1 -0
  120. package/utilities/index.js.map +1 -1
  121. package/utilities/internal/index.d.ts +2 -0
  122. package/utilities/internal/index.js.map +1 -1
  123. package/utilities/internal/toQueryResult.js.map +1 -1
  124. package/utilities/internal/types/ApplyHKT.d.ts +13 -0
  125. package/utilities/internal/types/ApplyHKT.js +2 -0
  126. package/utilities/internal/types/ApplyHKT.js.map +1 -0
  127. package/utilities/internal/types/ApplyHKTImplementationWithDefault.d.ts +11 -0
  128. package/utilities/internal/types/ApplyHKTImplementationWithDefault.js +2 -0
  129. package/utilities/internal/types/ApplyHKTImplementationWithDefault.js.map +1 -0
  130. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,138 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 4.0.0-alpha.18
4
+
5
+ ### Minor Changes
6
+
7
+ - [#12670](https://github.com/apollographql/apollo-client/pull/12670) [`0a880ea`](https://github.com/apollographql/apollo-client/commit/0a880ea4c2360a985fdd2edadb94fcc4b82bad73) Thanks [@phryneas](https://github.com/phryneas)! - Provide a mechanism to override the DataMasking types.
8
+
9
+ Up until now, our types `Masked`, `MaskedDocumentNode`, `FragmentType`, `MaybeMasked` and `Unmasked` would assume that you are stictly using the type output format of GraphQL Codegen.
10
+
11
+ With this change, you can now modify the behaviour of those types if you use a different form of codegen that produces different types for your queries.
12
+
13
+ A simple implementation that would override the `Masked` type to remove all fields starting with `_` from a type would look like this:
14
+
15
+ ```ts
16
+ // your actual implementation of `Masked`
17
+ type CustomMaskedImplementation<TData> = {
18
+ [K in keyof TData as K extends `_${string}` ? never : K]: TData[K];
19
+ };
20
+
21
+ import { HKT } from "@apollo/client/utilities";
22
+ // transform this type into a higher kinded type that can be evaulated at a later time
23
+ interface CustomMaskedType extends HKT {
24
+ arg1: unknown; // TData
25
+ return: CustomMaskedImplementation<this["arg1"]>;
26
+ }
27
+
28
+ // create an "implementation interface" for the types you want to override
29
+ export interface CustomDataMaskingImplementation {
30
+ Masked: CustomMaskedType;
31
+ // other possible keys: `MaskedDocumentNode`, `FragmentType`, `MaybeMasked` and `Unmasked`
32
+ }
33
+ ```
34
+
35
+ then you would use that `CustomDataMaskingImplementation` interface in your project to extend the `DataMasking` interface exported by `@apollo/client` with it's functionality:
36
+
37
+ ```ts
38
+ declare module "@apollo/client" {
39
+ export interface DataMasking extends CustomDataMaskingImplementation {}
40
+ }
41
+ ```
42
+
43
+ After that, all internal usage of `Masked` in Apollo Client as well as all usage in your code base will use the new `CustomMaskedType` implementation.
44
+
45
+ If you don't specify overrides, Apollo Client will still default to the GraphQL Codegen data masking implementation.
46
+ The types for that are also explicitly exported as the `GraphQLCodegenDataMasking` namespace in `@apollo/client/masking`.
47
+
48
+ ## 4.0.0-alpha.17
49
+
50
+ ### Major Changes
51
+
52
+ - [#12649](https://github.com/apollographql/apollo-client/pull/12649) [`0be92ad`](https://github.com/apollographql/apollo-client/commit/0be92ad51cf8de444fa1cc507bab2c21d230a44e) Thanks [@jerelmiller](https://github.com/jerelmiller)! - The `TData` generic provided to types that return a `dataState` property is now modified by the given `DataState` generic instead of passing a modified `TData` type. For example, a `QueryRef` that could return partial data was defined as `QueryRef<DeepPartial<TData>, TVariables>`. Now `TData` should be provided unmodified and a set of allowed states should be given instead: `QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'>`.
53
+
54
+ To migrate, use the following guide to replace your type with the right set of states (all types listed below are changed the same way):
55
+
56
+ ```diff
57
+ - QueryRef<TData, TVariables>
58
+ // `QueryRef`'s default is 'complete' | 'streaming' so this can also be left alone if you prefer
59
+ // All other types affected by this change default to all states
60
+ + QueryRef<TData, TVariables>
61
+ + QueryRef<TData, TVariables, 'complete' | 'streaming'>
62
+
63
+ - QueryRef<TData | undefined, TVariables>
64
+ + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'empty'>
65
+
66
+ - QueryRef<DeepPartial<TData>, TVariables>
67
+ + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'>
68
+
69
+ - QueryRef<DeepPartial<TData> | undefined, TVariables>
70
+ + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>
71
+ ```
72
+
73
+ The following types are affected. Provide the allowed `dataState` values to the `TDataState` generic:
74
+
75
+ - `ApolloQueryResult`
76
+ - `QueryRef`
77
+ - `PreloadedQueryRef`
78
+ - `useLazyQuery.Result`
79
+ - `useQuery.Result`
80
+ - `useReadQuery.Result`
81
+ - `useSuspenseQuery.Result`
82
+
83
+ All `*QueryRef` types default to `complete | streaming` states while the rest of the types default to `'complete' | 'streaming' | 'partial' | 'empty'` states. You shouldn't need to provide the states unless you need to either allow for partial data/empty values (`*QueryRef`) or a restricted set of states.
84
+
85
+ - [#12649](https://github.com/apollographql/apollo-client/pull/12649) [`0be92ad`](https://github.com/apollographql/apollo-client/commit/0be92ad51cf8de444fa1cc507bab2c21d230a44e) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove the deprecated `QueryReference` type. Please use `QueryRef` instead.
86
+
87
+ - [#12633](https://github.com/apollographql/apollo-client/pull/12633) [`9bfb51f`](https://github.com/apollographql/apollo-client/commit/9bfb51fdbca69560da71f9012c74ee172b6c2b69) Thanks [@phryneas](https://github.com/phryneas)! - If the `execute` function of `useLazyQuery` is executed, previously started queries
88
+ from the same `useLazyQuery` usage will be rejected with an `AbortError` unless
89
+ `.retain()` is called on the promise returned by previous `execute` calls.
90
+
91
+ Please keep in mind that `useLazyQuery` is primarily meant as a means to synchronize
92
+ your component to the status of a query and that it's purpose it not to make a
93
+ series of network calls.
94
+ If you plan on making a series of network calls without the need to synchronize
95
+ the result with your component, consider using `ApolloClient.query` instead.
96
+
97
+ ### Minor Changes
98
+
99
+ - [#12633](https://github.com/apollographql/apollo-client/pull/12633) [`9bfb51f`](https://github.com/apollographql/apollo-client/commit/9bfb51fdbca69560da71f9012c74ee172b6c2b69) Thanks [@phryneas](https://github.com/phryneas)! - `ObservableQuery.refetch` and `ObservableQuery.reobserve` and the `execute` function of `useLazyQuery` now return a
100
+ `ResultPromise` with an additional `.retain` method.
101
+ If this method is called, the underlying network operation will be kept running even if the `ObservableQuery` itself does
102
+ not require the result anymore, and the Promise will resolve with the final result instead of resolving with an intermediate
103
+ result in the case of early cancellation.
104
+
105
+ - [#12649](https://github.com/apollographql/apollo-client/pull/12649) [`0be92ad`](https://github.com/apollographql/apollo-client/commit/0be92ad51cf8de444fa1cc507bab2c21d230a44e) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add a new `dataState` property that determines the completeness of the `data` property. `dataState` helps narrow the type of `data`. `dataState` is now emitted from `ObservableQuery` and returned from all React hooks that return a `data` property.
106
+
107
+ The `dataState` values are:
108
+
109
+ - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`.
110
+ - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`.
111
+ - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in.
112
+ - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
113
+
114
+ Example:
115
+
116
+ ```ts
117
+ const { data, dataState } = useQuery<TData>(query);
118
+
119
+ if (dataState === "empty") {
120
+ expectTypeOf(data).toEqualTypeOf<undefined>();
121
+ }
122
+
123
+ if (dataState === "partial") {
124
+ expectTypeOf(data).toEqualTypeOf<DeepPartial<TData>>();
125
+ }
126
+
127
+ if (dataState === "streaming") {
128
+ expectTypeOf(data).toEqualTypeOf<TData>();
129
+ }
130
+
131
+ if (dataState === "complete") {
132
+ expectTypeOf(data).toEqualTypeOf<TData>();
133
+ }
134
+ ```
135
+
3
136
  ## 4.0.0-alpha.16
4
137
 
5
138
  ### Major Changes
@@ -15,17 +15,18 @@ const invariant_1 = require("@apollo/client/utilities/invariant");
15
15
  const equalByQuery_js_1 = require("./equalByQuery.cjs");
16
16
  const networkStatus_js_1 = require("./networkStatus.cjs");
17
17
  const { assign, hasOwnProperty } = Object;
18
- const newNetworkStatusSymbol = Symbol();
19
18
  const uninitialized = {
20
19
  loading: true,
21
20
  networkStatus: networkStatus_js_1.NetworkStatus.loading,
22
21
  data: undefined,
22
+ dataState: "empty",
23
23
  partial: true,
24
24
  };
25
25
  const empty = {
26
26
  loading: false,
27
27
  networkStatus: networkStatus_js_1.NetworkStatus.ready,
28
28
  data: undefined,
29
+ dataState: "empty",
29
30
  partial: true,
30
31
  };
31
32
  class ObservableQuery {
@@ -208,19 +209,23 @@ class ObservableQuery {
208
209
  : initialFetchPolicy || this.options.fetchPolicy;
209
210
  const defaultResult = {
210
211
  data: undefined,
212
+ dataState: "empty",
211
213
  loading: true,
212
214
  networkStatus: networkStatus_js_1.NetworkStatus.loading,
213
215
  partial: true,
214
216
  };
215
217
  const cacheResult = () => {
216
218
  const diff = this.getCacheDiff();
219
+ // TODO: queryInfo.getDiff should handle this since cache.diff returns a
220
+ // null when returnPartialData is false
221
+ const data = this.options.returnPartialData || diff.complete ?
222
+ diff.result ?? undefined
223
+ : undefined;
217
224
  return this.maskResult({
218
- data:
219
- // TODO: queryInfo.getDiff should handle this since cache.diff returns a
220
- // null when returnPartialData is false
221
- this.options.returnPartialData || diff.complete ?
222
- diff.result ?? undefined
223
- : undefined,
225
+ data,
226
+ dataState: diff.complete ? "complete"
227
+ : data === undefined ? "empty"
228
+ : "partial",
224
229
  loading: !diff.complete,
225
230
  networkStatus: diff.complete ? networkStatus_js_1.NetworkStatus.ready : networkStatus_js_1.NetworkStatus.loading,
226
231
  partial: !diff.complete,
@@ -373,9 +378,8 @@ class ObservableQuery {
373
378
  this.getVariablesWithDefaults({ ...this.variables, ...variables });
374
379
  }
375
380
  this.queryInfo.resetLastWrite();
376
- return this.reobserve({
377
- ...reobserveOptions,
378
- [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.refetch,
381
+ return this._reobserve(reobserveOptions, {
382
+ newNetworkStatus: networkStatus_js_1.NetworkStatus.refetch,
379
383
  });
380
384
  }
381
385
  /**
@@ -501,6 +505,7 @@ class ObservableQuery {
501
505
  // will be overwritten anyways, just here for types sake
502
506
  loading: false,
503
507
  data: data,
508
+ dataState: lastResult.dataState === "streaming" ? "streaming" : "complete",
504
509
  },
505
510
  source: "network",
506
511
  });
@@ -607,12 +612,11 @@ class ObservableQuery {
607
612
  if (!this.hasObservers()) {
608
613
  return (0, internal_1.toQueryResult)(this.getCurrentResult());
609
614
  }
610
- return this.reobserve({
615
+ return this._reobserve({
611
616
  // Reset options.fetchPolicy to its original value.
612
617
  fetchPolicy: this.options.initialFetchPolicy,
613
618
  variables,
614
- [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.setVariables,
615
- });
619
+ }, { newNetworkStatus: networkStatus_js_1.NetworkStatus.setVariables });
616
620
  }
617
621
  /**
618
622
  * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
@@ -684,7 +688,7 @@ class ObservableQuery {
684
688
  }
685
689
  return options.fetchPolicy;
686
690
  }
687
- fetch(options, networkStatus, fetchQuery) {
691
+ fetch(options, networkStatus, fetchQuery, operator) {
688
692
  // TODO Make sure we update the networkStatus (and infer fetchVariables)
689
693
  // before actually committing to the fetch.
690
694
  const initialFetchPolicy = this.options.fetchPolicy;
@@ -735,7 +739,7 @@ class ObservableQuery {
735
739
  }
736
740
  }
737
741
  });
738
- const { observable, fromLink } = this.queryManager.fetchObservableWithInfo(queryInfo, options, { networkStatus, query: fetchQuery, onCacheHit, fetchQueryOperator });
742
+ let { observable, fromLink } = this.queryManager.fetchObservableWithInfo(queryInfo, options, { networkStatus, query: fetchQuery, onCacheHit, fetchQueryOperator });
739
743
  // track query and variables from the start of the operation
740
744
  const { query, variables } = this;
741
745
  const operation = {
@@ -746,6 +750,7 @@ class ObservableQuery {
746
750
  this.activeOperations.add(operation);
747
751
  let forceFirstValueEmit = networkStatus == networkStatus_js_1.NetworkStatus.refetch ||
748
752
  networkStatus == networkStatus_js_1.NetworkStatus.setVariables;
753
+ observable = observable.pipe(operator, (0, rxjs_1.share)());
749
754
  const subscription = observable
750
755
  .pipe((0, rxjs_1.tap)({
751
756
  next: (notification) => {
@@ -795,7 +800,7 @@ class ObservableQuery {
795
800
  if (this.pollingInfo) {
796
801
  if (!(0, networkStatus_js_1.isNetworkRequestInFlight)(this.networkStatus) &&
797
802
  !this.options.skipPollAttempt?.()) {
798
- this.reobserve({
803
+ this._reobserve({
799
804
  // Most fetchPolicy options don't make sense to use in a polling context, as
800
805
  // users wouldn't want to be polling the cache directly. However, network-only and
801
806
  // no-cache are both useful for when the user wants to control whether or not the
@@ -803,7 +808,8 @@ class ObservableQuery {
803
808
  fetchPolicy: this.options.initialFetchPolicy === "no-cache" ?
804
809
  "no-cache"
805
810
  : "network-only",
806
- [newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.poll,
811
+ }, {
812
+ newNetworkStatus: networkStatus_js_1.NetworkStatus.poll,
807
813
  }).then(poll, poll);
808
814
  }
809
815
  else {
@@ -832,13 +838,11 @@ class ObservableQuery {
832
838
  * merged with the current options when given.
833
839
  */
834
840
  reobserve(newOptions) {
841
+ return this._reobserve(newOptions);
842
+ }
843
+ _reobserve(newOptions, internalOptions) {
835
844
  this.isTornDown = false;
836
- let newNetworkStatus;
837
- if (newOptions) {
838
- newNetworkStatus = newOptions[newNetworkStatusSymbol];
839
- // Avoid setting the symbol option in this.options
840
- delete newOptions[newNetworkStatusSymbol];
841
- }
845
+ let { newNetworkStatus } = internalOptions || {};
842
846
  const useDisposableObservable =
843
847
  // Refetching uses a disposable Observable to allow refetches using different
844
848
  // options, without permanently altering the options of the
@@ -913,32 +917,38 @@ class ObservableQuery {
913
917
  this.cancelPolling();
914
918
  }
915
919
  this.resubscribeCache();
916
- const { subscription, observable, fromLink } = this.fetch(options, newNetworkStatus, query);
917
- if (!useDisposableObservable && (fromLink || !this.linkSubscription)) {
918
- if (this.linkSubscription) {
919
- this.linkSubscription.unsubscribe();
920
- }
921
- this.linkSubscription = subscription;
922
- }
923
- return (0, internal_1.preventUnhandledRejection)(
924
- // Note: lastValueFrom will create a separate subscription to the
925
- // observable which means that terminating this ObservableQuery will not
926
- // cancel the request from the link chain.
927
- (0, rxjs_1.lastValueFrom)(observable.pipe((0, internal_1.filterMap)((value) => {
920
+ const { promise, operator: promiseOperator } = getTrackingOperatorPromise((value) => {
928
921
  switch (value.kind) {
929
922
  case "E":
930
923
  throw value.error;
931
924
  case "N":
932
- if (value.source !== "newNetworkStatus")
925
+ if (value.source !== "newNetworkStatus" && !value.value.loading)
933
926
  return value.value;
934
927
  }
935
- })), {
936
- // This default value should only be used when using a `fetchPolicy` of
937
- // `standby` since that fetch policy completes without emitting a
938
- // result. Since we are converting this to a QueryResult type, we
939
- // omit the extra fields from ApolloQueryResult in the default value.
940
- defaultValue: { data: undefined },
941
- }).then((result) => (0, internal_1.toQueryResult)(this.maskResult(result))));
928
+ },
929
+ // This default value should only be used when using a `fetchPolicy` of
930
+ // `standby` since that fetch policy completes without emitting a
931
+ // result. Since we are converting this to a QueryResult type, we
932
+ // omit the extra fields from ApolloQueryResult in the default value.
933
+ options.fetchPolicy === "standby" ?
934
+ { data: undefined }
935
+ : undefined);
936
+ const { subscription, observable, fromLink } = this.fetch(options, newNetworkStatus, query, promiseOperator);
937
+ if (!useDisposableObservable && (fromLink || !this.linkSubscription)) {
938
+ if (this.linkSubscription) {
939
+ this.linkSubscription.unsubscribe();
940
+ }
941
+ this.linkSubscription = subscription;
942
+ }
943
+ const ret = Object.assign((0, internal_1.preventUnhandledRejection)(promise.then((result) => (0, internal_1.toQueryResult)(this.maskResult(result)))), {
944
+ retain: () => {
945
+ const subscription = observable.subscribe({});
946
+ const unsubscribe = () => subscription.unsubscribe();
947
+ promise.then(unsubscribe, unsubscribe);
948
+ return ret;
949
+ },
950
+ });
951
+ return ret;
942
952
  }
943
953
  hasObservers() {
944
954
  return this.subject.observed;
@@ -1051,6 +1061,9 @@ class ObservableQuery {
1051
1061
  kind: "N",
1052
1062
  value: {
1053
1063
  data: diff.result,
1064
+ dataState: diff.complete ? "complete"
1065
+ : diff.result ? "partial"
1066
+ : "empty",
1054
1067
  networkStatus: networkStatus_js_1.NetworkStatus.ready,
1055
1068
  loading: false,
1056
1069
  error: undefined,
@@ -1167,14 +1180,17 @@ class ObservableQuery {
1167
1180
  result =
1168
1181
  notification.kind === "E" ?
1169
1182
  {
1170
- data: undefined,
1171
- partial: true,
1172
- ...(isEqualQuery(previous, notification) ? previous.result : {}),
1183
+ ...(isEqualQuery(previous, notification) ?
1184
+ previous.result
1185
+ : { data: undefined, dataState: "empty", partial: true }),
1173
1186
  error: notification.error,
1174
1187
  networkStatus: networkStatus_js_1.NetworkStatus.error,
1175
1188
  loading: false,
1176
1189
  }
1177
1190
  : notification.value;
1191
+ if (result.error && result.dataState === "streaming") {
1192
+ result.dataState = "complete";
1193
+ }
1178
1194
  if (result.error) {
1179
1195
  meta.shouldEmit = 1 /* EmitBehavior.force */;
1180
1196
  }
@@ -1213,7 +1229,7 @@ class ObservableQuery {
1213
1229
  reobserveCacheFirst() {
1214
1230
  const { fetchPolicy, nextFetchPolicy } = this.options;
1215
1231
  if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
1216
- return this.reobserve({
1232
+ this.reobserve({
1217
1233
  fetchPolicy: "cache-first",
1218
1234
  // Use a temporary nextFetchPolicy function that replaces itself with the
1219
1235
  // previous nextFetchPolicy value and returns the original fetchPolicy.
@@ -1231,7 +1247,9 @@ class ObservableQuery {
1231
1247
  },
1232
1248
  });
1233
1249
  }
1234
- return this.reobserve();
1250
+ else {
1251
+ this.reobserve();
1252
+ }
1235
1253
  }
1236
1254
  getVariablesWithDefaults(variables) {
1237
1255
  return this.queryManager.getVariables(this.query, variables);
@@ -1246,4 +1264,42 @@ function logMissingFieldErrors(missing) {
1246
1264
  function isEqualQuery(a, b) {
1247
1265
  return !!(a && b && a.query === b.query && (0, equality_1.equal)(a.variables, b.variables));
1248
1266
  }
1267
+ function getTrackingOperatorPromise(filterMapCb, defaultValue) {
1268
+ let lastValue = defaultValue, resolve, reject;
1269
+ const promise = new Promise((res, rej) => {
1270
+ resolve = res;
1271
+ reject = rej;
1272
+ });
1273
+ const operator = (0, rxjs_1.tap)({
1274
+ next(value) {
1275
+ try {
1276
+ const newValue = filterMapCb(value);
1277
+ if (newValue !== undefined) {
1278
+ lastValue = newValue;
1279
+ }
1280
+ }
1281
+ catch (error) {
1282
+ reject(error);
1283
+ }
1284
+ },
1285
+ finalize: () => {
1286
+ if (lastValue) {
1287
+ resolve(lastValue);
1288
+ }
1289
+ else {
1290
+ const message = "The operation was aborted.";
1291
+ const name = "AbortError";
1292
+ reject(typeof DOMException !== "undefined" ?
1293
+ new DOMException(message, name)
1294
+ // some environments do not have `DOMException`, e.g. node
1295
+ // uses a normal `Error` with a `name` property instead: https://github.com/phryneas/node/blob/d0579b64f0f6b722f8e49bf8a471dd0d0604a21e/lib/internal/errors.js#L964
1296
+ // error.code is a legacy property that is not used anymore,
1297
+ // and also inconsistent across environments (in supporting
1298
+ // browsers it is `20`, in node `'ABORT_ERR'`) so we omit that.
1299
+ : Object.assign(new Error(message), { name }));
1300
+ }
1301
+ },
1302
+ });
1303
+ return { promise, operator };
1304
+ }
1249
1305
  //# sourceMappingURL=ObservableQuery.cjs.map