@apollo/client 4.0.0-alpha.3 → 4.0.0-alpha.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 (247) hide show
  1. package/.changeset/eighty-squids-fix.md +15 -0
  2. package/.changeset/eleven-kangaroos-jump.md +5 -0
  3. package/.changeset/forty-shrimps-fry.md +5 -0
  4. package/.changeset/funny-jeans-invent.md +16 -0
  5. package/.changeset/grumpy-vans-type.md +5 -0
  6. package/.changeset/khaki-spies-work.md +11 -0
  7. package/.changeset/light-apes-rescue.md +5 -0
  8. package/.changeset/little-spoons-kick.md +7 -0
  9. package/.changeset/loud-cows-raise.md +7 -0
  10. package/.changeset/many-buses-allow.md +5 -0
  11. package/.changeset/odd-lemons-relax.md +5 -0
  12. package/.changeset/poor-eels-punch.md +5 -0
  13. package/.changeset/pre.json +18 -0
  14. package/.changeset/real-teachers-peel.md +5 -0
  15. package/.changeset/slimy-chicken-melt.md +5 -0
  16. package/.changeset/thick-books-grin.md +5 -0
  17. package/.changeset/tough-rockets-allow.md +5 -0
  18. package/.changeset/tricky-tables-shave.md +5 -0
  19. package/.changeset/warm-ties-sit.md +7 -0
  20. package/CHANGELOG.md +84 -0
  21. package/__cjs/cache/core/cache.cjs +1 -1
  22. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  23. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  24. package/__cjs/cache/inmemory/policies.cjs +4 -4
  25. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  26. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  27. package/__cjs/core/ApolloClient.cjs +25 -16
  28. package/__cjs/core/ApolloClient.cjs.map +1 -1
  29. package/__cjs/core/ApolloClient.d.cts +17 -5
  30. package/__cjs/core/LocalState.cjs +2 -2
  31. package/__cjs/core/ObservableQuery.cjs +44 -22
  32. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  33. package/__cjs/core/ObservableQuery.d.cts +6 -3
  34. package/__cjs/core/QueryManager.cjs +72 -35
  35. package/__cjs/core/QueryManager.cjs.map +1 -1
  36. package/__cjs/core/QueryManager.d.cts +14 -3
  37. package/__cjs/core/types.d.cts +32 -0
  38. package/__cjs/core/watchQueryOptions.d.cts +18 -25
  39. package/__cjs/invariantErrorCodes.cjs +57 -77
  40. package/__cjs/link/core/ApolloLink.cjs +2 -2
  41. package/__cjs/link/http/checkFetcher.cjs +1 -1
  42. package/__cjs/link/http/createHttpLink.cjs +1 -1
  43. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  44. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  45. package/__cjs/link/persisted-queries/index.cjs +2 -2
  46. package/__cjs/link/utils/validateOperation.cjs +1 -1
  47. package/__cjs/masking/maskDefinition.cjs +2 -2
  48. package/__cjs/masking/maskFragment.cjs +2 -2
  49. package/__cjs/masking/maskOperation.cjs +1 -1
  50. package/__cjs/masking/utils.cjs +1 -1
  51. package/__cjs/react/context/ApolloConsumer.cjs +1 -1
  52. package/__cjs/react/context/ApolloContext.cjs +1 -1
  53. package/__cjs/react/context/ApolloContext.cjs.map +1 -1
  54. package/__cjs/react/context/ApolloContext.d.cts +2 -2
  55. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  56. package/__cjs/react/hooks/index.cjs +13 -8
  57. package/__cjs/react/hooks/index.cjs.map +1 -1
  58. package/__cjs/react/hooks/index.d.cts +6 -12
  59. package/__cjs/react/hooks/internal/wrapHook.cjs +26 -5
  60. package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
  61. package/__cjs/react/hooks/internal/wrapHook.d.cts +3 -1
  62. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  63. package/__cjs/react/hooks/useBackgroundQuery.d.cts +146 -43
  64. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  65. package/__cjs/react/hooks/useFragment.d.cts +51 -26
  66. package/__cjs/react/hooks/useLazyQuery.cjs +1 -1
  67. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  68. package/__cjs/react/hooks/useLazyQuery.d.cts +263 -262
  69. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  70. package/__cjs/react/hooks/useLoadableQuery.d.cts +105 -32
  71. package/__cjs/react/hooks/useMutation.cjs +14 -19
  72. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  73. package/__cjs/react/hooks/useMutation.d.cts +198 -3
  74. package/__cjs/react/hooks/useQuery.cjs +82 -189
  75. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  76. package/__cjs/react/hooks/useQuery.d.cts +283 -4
  77. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  78. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +21 -20
  79. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  80. package/__cjs/react/hooks/useReadQuery.d.cts +26 -24
  81. package/__cjs/react/hooks/useSubscription.cjs +8 -57
  82. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  83. package/__cjs/react/hooks/useSubscription.d.cts +96 -9
  84. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  85. package/__cjs/react/hooks/useSuspenseFragment.d.cts +40 -37
  86. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -2
  87. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  88. package/__cjs/react/hooks/useSuspenseQuery.d.cts +202 -35
  89. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  90. package/__cjs/react/index.cjs.map +1 -1
  91. package/__cjs/react/index.d.cts +2 -1
  92. package/__cjs/react/internal/index.cjs +3 -1
  93. package/__cjs/react/internal/index.cjs.map +1 -1
  94. package/__cjs/react/internal/index.d.cts +2 -0
  95. package/__cjs/react/internal/types.d.cts +46 -0
  96. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  97. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +2 -3
  98. package/__cjs/react/ssr/getDataFromTree.cjs +43 -12
  99. package/__cjs/react/ssr/getDataFromTree.cjs.map +1 -1
  100. package/__cjs/react/ssr/getDataFromTree.d.cts +5 -0
  101. package/__cjs/react/ssr/index.cjs +1 -3
  102. package/__cjs/react/ssr/index.cjs.map +1 -1
  103. package/__cjs/react/ssr/index.d.cts +0 -1
  104. package/__cjs/react/ssr/useSSRQuery.cjs +60 -0
  105. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -0
  106. package/__cjs/react/ssr/useSSRQuery.d.cts +5 -0
  107. package/__cjs/react/types/deprecated.cjs +3 -0
  108. package/__cjs/react/types/deprecated.cjs.map +1 -0
  109. package/__cjs/react/types/deprecated.d.cts +65 -0
  110. package/__cjs/react/types/types.documentation.d.cts +4 -12
  111. package/__cjs/testing/matchers/index.cjs +4 -0
  112. package/__cjs/testing/matchers/index.cjs.map +1 -1
  113. package/__cjs/testing/matchers/toEmitStrictTyped.cjs +42 -0
  114. package/__cjs/testing/matchers/toEmitStrictTyped.cjs.map +1 -0
  115. package/__cjs/testing/matchers/toEmitStrictTyped.d.cts +7 -0
  116. package/__cjs/testing/matchers/toEqualLazyQueryResult.cjs.map +1 -1
  117. package/__cjs/testing/matchers/toEqualLazyQueryResult.d.cts +2 -2
  118. package/__cjs/testing/matchers/toEqualQueryResult.cjs.map +1 -1
  119. package/__cjs/testing/matchers/toEqualQueryResult.d.cts +2 -2
  120. package/__cjs/testing/matchers/toEqualStrictTyped.cjs +26 -0
  121. package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -0
  122. package/__cjs/testing/matchers/toEqualStrictTyped.d.cts +3 -0
  123. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +23 -0
  124. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -0
  125. package/__cjs/testing/matchers/utils/getSerializableProperties.d.cts +2 -0
  126. package/__cjs/version.cjs +1 -1
  127. package/__cjs/version.d.cts +1 -1
  128. package/cache/core/cache.js +1 -1
  129. package/cache/inmemory/entityStore.js +3 -3
  130. package/cache/inmemory/key-extractor.js +1 -1
  131. package/cache/inmemory/policies.js +4 -4
  132. package/cache/inmemory/readFromStore.js +2 -2
  133. package/cache/inmemory/writeToStore.js +4 -4
  134. package/core/ApolloClient.d.ts +17 -5
  135. package/core/ApolloClient.js +25 -16
  136. package/core/ApolloClient.js.map +1 -1
  137. package/core/LocalState.js +2 -2
  138. package/core/ObservableQuery.d.ts +6 -3
  139. package/core/ObservableQuery.js +44 -22
  140. package/core/ObservableQuery.js.map +1 -1
  141. package/core/QueryManager.d.ts +14 -3
  142. package/core/QueryManager.js +73 -36
  143. package/core/QueryManager.js.map +1 -1
  144. package/core/types.d.ts +32 -0
  145. package/core/watchQueryOptions.d.ts +18 -25
  146. package/invariantErrorCodes.js +57 -77
  147. package/link/core/ApolloLink.js +2 -2
  148. package/link/http/checkFetcher.js +1 -1
  149. package/link/http/createHttpLink.js +1 -1
  150. package/link/http/parseAndCheckHttpResponse.js +1 -1
  151. package/link/http/serializeFetchParameter.js +1 -1
  152. package/link/persisted-queries/index.js +2 -2
  153. package/link/utils/validateOperation.js +1 -1
  154. package/masking/maskDefinition.js +2 -2
  155. package/masking/maskFragment.js +2 -2
  156. package/masking/maskOperation.js +1 -1
  157. package/masking/utils.js +1 -1
  158. package/package.json +1 -1
  159. package/react/context/ApolloConsumer.js +1 -1
  160. package/react/context/ApolloContext.d.ts +2 -2
  161. package/react/context/ApolloContext.js +1 -1
  162. package/react/context/ApolloContext.js.map +1 -1
  163. package/react/context/ApolloProvider.js +1 -1
  164. package/react/hooks/index.d.ts +6 -12
  165. package/react/hooks/index.js +6 -6
  166. package/react/hooks/index.js.map +1 -1
  167. package/react/hooks/internal/wrapHook.d.ts +3 -1
  168. package/react/hooks/internal/wrapHook.js +24 -5
  169. package/react/hooks/internal/wrapHook.js.map +1 -1
  170. package/react/hooks/useBackgroundQuery.d.ts +146 -43
  171. package/react/hooks/useBackgroundQuery.js.map +1 -1
  172. package/react/hooks/useFragment.d.ts +51 -26
  173. package/react/hooks/useFragment.js.map +1 -1
  174. package/react/hooks/useLazyQuery.d.ts +263 -262
  175. package/react/hooks/useLazyQuery.js +1 -1
  176. package/react/hooks/useLazyQuery.js.map +1 -1
  177. package/react/hooks/useLoadableQuery.d.ts +105 -32
  178. package/react/hooks/useLoadableQuery.js.map +1 -1
  179. package/react/hooks/useMutation.d.ts +198 -3
  180. package/react/hooks/useMutation.js +14 -19
  181. package/react/hooks/useMutation.js.map +1 -1
  182. package/react/hooks/useQuery.d.ts +283 -4
  183. package/react/hooks/useQuery.js +83 -190
  184. package/react/hooks/useQuery.js.map +1 -1
  185. package/react/hooks/useQueryRefHandlers.d.ts +21 -20
  186. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  187. package/react/hooks/useReadQuery.d.ts +26 -24
  188. package/react/hooks/useReadQuery.js.map +1 -1
  189. package/react/hooks/useSubscription.d.ts +96 -9
  190. package/react/hooks/useSubscription.js +7 -53
  191. package/react/hooks/useSubscription.js.map +1 -1
  192. package/react/hooks/useSuspenseFragment.d.ts +40 -37
  193. package/react/hooks/useSuspenseFragment.js.map +1 -1
  194. package/react/hooks/useSuspenseQuery.d.ts +202 -35
  195. package/react/hooks/useSuspenseQuery.js +2 -2
  196. package/react/hooks/useSuspenseQuery.js.map +1 -1
  197. package/react/hooks/useSyncExternalStore.js +1 -1
  198. package/react/index.d.ts +2 -1
  199. package/react/index.js.map +1 -1
  200. package/react/internal/index.d.ts +2 -0
  201. package/react/internal/index.js +2 -1
  202. package/react/internal/index.js.map +1 -1
  203. package/react/internal/types.d.ts +46 -0
  204. package/react/query-preloader/createQueryPreloader.d.ts +2 -3
  205. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  206. package/react/ssr/getDataFromTree.d.ts +5 -0
  207. package/react/ssr/getDataFromTree.js +43 -12
  208. package/react/ssr/getDataFromTree.js.map +1 -1
  209. package/react/ssr/index.d.ts +0 -1
  210. package/react/ssr/index.js +0 -1
  211. package/react/ssr/index.js.map +1 -1
  212. package/react/ssr/useSSRQuery.d.ts +5 -0
  213. package/react/ssr/useSSRQuery.js +56 -0
  214. package/react/ssr/useSSRQuery.js.map +1 -0
  215. package/react/types/deprecated.d.ts +65 -0
  216. package/react/types/deprecated.js +2 -0
  217. package/react/types/deprecated.js.map +1 -0
  218. package/react/types/types.documentation.d.ts +4 -12
  219. package/testing/matchers/index.js +4 -0
  220. package/testing/matchers/index.js.map +1 -1
  221. package/testing/matchers/toEmitStrictTyped.d.ts +7 -0
  222. package/testing/matchers/toEmitStrictTyped.js +38 -0
  223. package/testing/matchers/toEmitStrictTyped.js.map +1 -0
  224. package/testing/matchers/toEqualLazyQueryResult.d.ts +2 -2
  225. package/testing/matchers/toEqualLazyQueryResult.js.map +1 -1
  226. package/testing/matchers/toEqualQueryResult.d.ts +2 -2
  227. package/testing/matchers/toEqualQueryResult.js.map +1 -1
  228. package/testing/matchers/toEqualStrictTyped.d.ts +3 -0
  229. package/testing/matchers/toEqualStrictTyped.js +22 -0
  230. package/testing/matchers/toEqualStrictTyped.js.map +1 -0
  231. package/testing/matchers/utils/getSerializableProperties.d.ts +2 -0
  232. package/testing/matchers/utils/getSerializableProperties.js +20 -0
  233. package/testing/matchers/utils/getSerializableProperties.js.map +1 -0
  234. package/version.d.ts +1 -1
  235. package/version.js +1 -1
  236. package/__cjs/react/ssr/RenderPromises.cjs +0 -104
  237. package/__cjs/react/ssr/RenderPromises.cjs.map +0 -1
  238. package/__cjs/react/ssr/RenderPromises.d.cts +0 -22
  239. package/__cjs/react/types/types.d.cts +0 -661
  240. package/react/ssr/RenderPromises.d.ts +0 -22
  241. package/react/ssr/RenderPromises.js +0 -100
  242. package/react/ssr/RenderPromises.js.map +0 -1
  243. package/react/types/types.d.ts +0 -661
  244. /package/__cjs/react/{types → internal}/types.cjs +0 -0
  245. /package/__cjs/react/{types → internal}/types.cjs.map +0 -0
  246. /package/react/{types → internal}/types.js +0 -0
  247. /package/react/{types → internal}/types.js.map +0 -0
@@ -3,7 +3,6 @@ import type { Observable } from "rxjs";
3
3
  import type { MissingFieldError } from "@apollo/client/cache";
4
4
  import type { MissingTree } from "@apollo/client/cache";
5
5
  import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
6
- import { NetworkStatus } from "./networkStatus.cjs";
7
6
  import type { QueryInfo } from "./QueryInfo.cjs";
8
7
  import type { QueryManager } from "./QueryManager.cjs";
9
8
  import type { ApolloQueryResult, ErrorLike, OperationVariables, TypedDocumentNode } from "./types.cjs";
@@ -78,7 +77,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
78
77
  * This function returns _another_ function that you can call to terminate the subscription.
79
78
  */
80
79
  subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void;
81
- setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
80
+ /** @internal */
82
81
  silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
83
82
  /**
84
83
  * Update the variables of this observable query, and fetch the new results
@@ -117,7 +116,11 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
117
116
  private fetch;
118
117
  private updatePolling;
119
118
  private updateLastResult;
120
- reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
119
+ /**
120
+ * Reevaluate the query, optionally against new options. New options will be
121
+ * merged with the current options when given.
122
+ */
123
+ reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
121
124
  private observe;
122
125
  private reportResult;
123
126
  private reportError;
@@ -37,6 +37,17 @@ class QueryManager {
37
37
  queryDeduplication;
38
38
  clientAwareness = {};
39
39
  localState;
40
+ /**
41
+ * Whether to prioritize cache values over network results when
42
+ * `fetchObservableWithInfo` is called.
43
+ * This will essentially turn a `"network-only"` or `"cache-and-network"`
44
+ * fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
45
+ * the `fetchPolicy` of the `ObservableQuery`.
46
+ *
47
+ * This can e.g. be used to prioritize the cache during the first render after
48
+ * SSR.
49
+ */
50
+ prioritizeCacheValues = false;
40
51
  onBroadcast;
41
52
  mutationStore;
42
53
  // All the queries that the QueryManager is currently managing (not
@@ -84,15 +95,15 @@ class QueryManager {
84
95
  this.queries.forEach((_info, queryId) => {
85
96
  this.removeQuery(queryId);
86
97
  });
87
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(72));
98
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(68));
88
99
  }
89
100
  cancelPendingFetches(error) {
90
101
  this.fetchCancelFns.forEach((cancel) => cancel(error));
91
102
  this.fetchCancelFns.clear();
92
103
  }
93
104
  async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy = this.defaultOptions.mutate?.fetchPolicy || "network-only", errorPolicy = this.defaultOptions.mutate?.errorPolicy || "none", keepRootFields, context, }) {
94
- (0, invariant_1.invariant)(mutation, 73);
95
- (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 74);
105
+ (0, invariant_1.invariant)(mutation, 69);
106
+ (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 70);
96
107
  const mutationId = this.generateMutationId();
97
108
  mutation = this.cache.transformForLink(this.transform(mutation));
98
109
  const { hasClientExports } = this.getDocumentInfo(mutation);
@@ -126,7 +137,8 @@ class QueryManager {
126
137
  optimisticResponse: isOptimistic ? optimisticResponse : void 0,
127
138
  }, variables, {}, false)
128
139
  .pipe((0, rxjs_1.mergeMap)((result) => {
129
- if ((0, utilities_4.graphQLResultHasError)(result) && errorPolicy === "none") {
140
+ const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
141
+ if (hasErrors && errorPolicy === "none") {
130
142
  throw new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(result));
131
143
  }
132
144
  if (mutationStoreValue) {
@@ -137,8 +149,7 @@ class QueryManager {
137
149
  if (typeof refetchQueries === "function") {
138
150
  refetchQueries = refetchQueries(storeResult);
139
151
  }
140
- if (errorPolicy === "ignore" &&
141
- (0, utilities_4.graphQLResultHasError)(storeResult)) {
152
+ if (errorPolicy === "ignore" && hasErrors) {
142
153
  delete storeResult.errors;
143
154
  }
144
155
  return (0, rxjs_1.from)(this.markMutationResult({
@@ -167,28 +178,40 @@ class QueryManager {
167
178
  // ExecutionPatchResult has arrived and we have assembled the
168
179
  // multipart response into a single result.
169
180
  if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
170
- resolve({
171
- ...storeResult,
181
+ const result = {
172
182
  data: this.maskOperation({
173
183
  document: mutation,
174
184
  data: storeResult.data,
175
185
  fetchPolicy,
176
186
  id: mutationId,
177
187
  }),
178
- });
188
+ };
189
+ if ((0, utilities_4.graphQLResultHasError)(storeResult)) {
190
+ result.error = new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(storeResult));
191
+ }
192
+ if (storeResult.extensions) {
193
+ result.extensions = storeResult.extensions;
194
+ }
195
+ resolve(result);
179
196
  }
180
197
  },
181
198
  error: (err) => {
182
- err = maybeWrapError(err);
199
+ const error = maybeWrapError(err);
183
200
  if (mutationStoreValue) {
184
201
  mutationStoreValue.loading = false;
185
- mutationStoreValue.error = err;
202
+ mutationStoreValue.error = error;
186
203
  }
187
204
  if (isOptimistic) {
188
205
  this.cache.removeOptimistic(mutationId);
189
206
  }
190
207
  this.broadcastQueries();
191
- reject(err);
208
+ if (errorPolicy === "ignore") {
209
+ return resolve({ data: undefined });
210
+ }
211
+ if (errorPolicy === "all") {
212
+ return resolve({ data: undefined, error });
213
+ }
214
+ reject(error);
192
215
  },
193
216
  });
194
217
  });
@@ -461,10 +484,10 @@ class QueryManager {
461
484
  // TODO: catch `EmptyError` and rethrow as network error if `complete`
462
485
  // notification is emitted without a value.
463
486
  query(options, queryId = this.generateQueryId()) {
464
- (0, invariant_1.invariant)(options.query, 75);
465
- (0, invariant_1.invariant)(options.query.kind === "Document", 76);
466
- (0, invariant_1.invariant)(!options.returnPartialData, 77);
467
- (0, invariant_1.invariant)(!options.pollInterval, 78);
487
+ (0, invariant_1.invariant)(options.query, 71);
488
+ (0, invariant_1.invariant)(options.query.kind === "Document", 72);
489
+ (0, invariant_1.invariant)(!options.returnPartialData, 73);
490
+ (0, invariant_1.invariant)(!options.pollInterval, 74);
468
491
  const query = this.transform(options.query);
469
492
  return this.fetchQuery(queryId, { ...options, query })
470
493
  .then((result) => result && {
@@ -498,7 +521,7 @@ class QueryManager {
498
521
  // depend on values that previously existed in the data portion of the
499
522
  // store. So, we cancel the promises and observers that we have issued
500
523
  // so far and not yet resolved (in the case of queries).
501
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(79));
524
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(75));
502
525
  this.queries.forEach((queryInfo) => {
503
526
  if (queryInfo.observableQuery) {
504
527
  // Set loading to true so listeners don't trigger unless they want
@@ -586,10 +609,10 @@ class QueryManager {
586
609
  if (!included) {
587
610
  const queryName = queryNames.get(nameOrQueryString);
588
611
  if (queryName) {
589
- __DEV__ && invariant_1.invariant.warn(80, queryName);
612
+ __DEV__ && invariant_1.invariant.warn(76, queryName);
590
613
  }
591
614
  else {
592
- __DEV__ && invariant_1.invariant.warn(81);
615
+ __DEV__ && invariant_1.invariant.warn(77);
593
616
  }
594
617
  }
595
618
  });
@@ -618,38 +641,48 @@ class QueryManager {
618
641
  const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
619
642
  query = this.transform(query);
620
643
  variables = this.getVariables(query, variables);
621
- const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((result) => {
644
+ const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((rawResult) => {
622
645
  if (fetchPolicy !== "no-cache") {
623
646
  // the subscription interface should handle not sending us results we no longer subscribe to.
624
647
  // XXX I don't think we ever send in an object with errors, but we might in the future...
625
- if ((0, QueryInfo_js_1.shouldWriteResult)(result, errorPolicy)) {
648
+ if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
626
649
  this.cache.write({
627
650
  query,
628
- result: result.data,
651
+ result: rawResult.data,
629
652
  dataId: "ROOT_SUBSCRIPTION",
630
653
  variables: variables,
631
654
  });
632
655
  }
633
656
  this.broadcastQueries();
634
657
  }
635
- const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
636
- const hasProtocolErrors = (0, errors_1.graphQLResultHasProtocolErrors)(result);
637
- if (hasErrors && errorPolicy === "none") {
638
- throw new errors_1.CombinedGraphQLErrors(result.errors);
658
+ const result = {
659
+ data: rawResult.data ?? undefined,
660
+ };
661
+ if ((0, utilities_4.graphQLResultHasError)(rawResult)) {
662
+ result.error = new errors_1.CombinedGraphQLErrors(rawResult.errors);
663
+ }
664
+ else if ((0, errors_1.graphQLResultHasProtocolErrors)(rawResult)) {
665
+ result.error = rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
666
+ // Don't emit protocol errors added by HttpLink
667
+ delete rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
668
+ }
669
+ if (rawResult.extensions &&
670
+ Object.keys(rawResult.extensions).length) {
671
+ result.extensions = rawResult.extensions;
639
672
  }
640
- if (hasProtocolErrors) {
641
- // `errorPolicy` is a mechanism for handling GraphQL errors, according
642
- // to our documentation, so we throw protocol errors regardless of the
643
- // set error policy.
644
- throw result.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
673
+ if (result.error && errorPolicy === "none") {
674
+ result.data = undefined;
645
675
  }
646
676
  if (errorPolicy === "ignore") {
647
- delete result.errors;
677
+ delete result.error;
648
678
  }
649
679
  return result;
650
680
  }), (0, rxjs_1.catchError)((error) => {
651
- throw maybeWrapError(error);
652
- }));
681
+ if (errorPolicy === "ignore") {
682
+ return (0, rxjs_1.of)({ data: undefined });
683
+ }
684
+ return (0, rxjs_1.of)({ data: undefined, error: maybeWrapError(error) });
685
+ }), (0, rxjs_1.filter)((result) => !!(result.data || result.error)));
653
686
  if (this.getDocumentInfo(query).hasClientExports) {
654
687
  const observablePromise = this.localState
655
688
  .addExportedVariables(query, variables, context)
@@ -817,6 +850,10 @@ class QueryManager {
817
850
  const queryInfo = this.getQuery(queryId);
818
851
  const defaults = this.defaultOptions.watchQuery;
819
852
  let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = false, context = {}, } = options;
853
+ if (this.prioritizeCacheValues &&
854
+ (fetchPolicy === "network-only" || fetchPolicy === "cache-and-network")) {
855
+ fetchPolicy = "cache-first";
856
+ }
820
857
  const normalized = Object.assign({}, options, {
821
858
  query,
822
859
  variables,
@@ -1016,7 +1053,7 @@ class QueryManager {
1016
1053
  !(0, utilities_3.isFullyUnmaskedOperation)(document) &&
1017
1054
  !this.noCacheWarningsByQueryId.has(operationId)) {
1018
1055
  this.noCacheWarningsByQueryId.add(operationId);
1019
- __DEV__ && invariant_1.invariant.warn(82, (0, utilities_4.getOperationName)(document) ??
1056
+ __DEV__ && invariant_1.invariant.warn(78, (0, utilities_4.getOperationName)(document) ??
1020
1057
  `Unnamed ${operationType ?? "operation"}`);
1021
1058
  }
1022
1059
  }