@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
@@ -9,7 +9,7 @@ import type { DefaultOptions } from "./ApolloClient.js";
9
9
  import type { LocalState } from "./LocalState.js";
10
10
  import { NetworkStatus } from "./networkStatus.js";
11
11
  import { ObservableQuery } from "./ObservableQuery.js";
12
- import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutationUpdaterFunction, OnQueryUpdated, OperationVariables } from "./types.js";
12
+ import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, MutationUpdaterFunction, OnQueryUpdated, OperationVariables, SubscribeResult } from "./types.js";
13
13
  import type { ErrorPolicy, MutationFetchPolicy, MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
14
14
  interface MutationStoreValue {
15
15
  mutation: DocumentNode;
@@ -65,6 +65,17 @@ export declare class QueryManager {
65
65
  private queryDeduplication;
66
66
  private clientAwareness;
67
67
  private localState;
68
+ /**
69
+ * Whether to prioritize cache values over network results when
70
+ * `fetchObservableWithInfo` is called.
71
+ * This will essentially turn a `"network-only"` or `"cache-and-network"`
72
+ * fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
73
+ * the `fetchPolicy` of the `ObservableQuery`.
74
+ *
75
+ * This can e.g. be used to prioritize the cache during the first render after
76
+ * SSR.
77
+ */
78
+ prioritizeCacheValues: boolean;
68
79
  private onBroadcast?;
69
80
  mutationStore?: {
70
81
  [mutationId: string]: MutationStoreValue;
@@ -78,7 +89,7 @@ export declare class QueryManager {
78
89
  */
79
90
  stop(): void;
80
91
  private cancelPendingFetches;
81
- mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<MaybeMasked<TData>>>;
92
+ mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<MutateResult<MaybeMasked<TData>>>;
82
93
  markMutationResult<TData, TVariables extends OperationVariables, TContext, TCache extends ApolloCache>(mutation: {
83
94
  mutationId: string;
84
95
  result: FetchResult<TData>;
@@ -123,7 +134,7 @@ export declare class QueryManager {
123
134
  getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
124
135
  reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]>;
125
136
  setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
126
- startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<FetchResult<TData>>;
137
+ startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<SubscribeResult<TData>>;
127
138
  stopQuery(queryId: string): void;
128
139
  removeQuery(queryId: string): void;
129
140
  broadcastQueries(): void;
@@ -1,5 +1,5 @@
1
1
  import { Trie } from "@wry/trie";
2
- import { catchError, concat, EMPTY, from, lastValueFrom, map, mergeMap, mergeWith, Observable, of, share, shareReplay, Subject, tap, } from "rxjs";
2
+ import { catchError, concat, EMPTY, filter, from, lastValueFrom, map, mergeMap, mergeWith, Observable, of, share, shareReplay, Subject, tap, } from "rxjs";
3
3
  import { canonicalStringify } from "@apollo/client/cache";
4
4
  import { CombinedGraphQLErrors, graphQLResultHasProtocolErrors, UnconventionalError, } from "@apollo/client/errors";
5
5
  import { PROTOCOL_ERRORS_SYMBOL } from "@apollo/client/errors";
@@ -30,6 +30,17 @@ export class QueryManager {
30
30
  queryDeduplication;
31
31
  clientAwareness = {};
32
32
  localState;
33
+ /**
34
+ * Whether to prioritize cache values over network results when
35
+ * `fetchObservableWithInfo` is called.
36
+ * This will essentially turn a `"network-only"` or `"cache-and-network"`
37
+ * fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
38
+ * the `fetchPolicy` of the `ObservableQuery`.
39
+ *
40
+ * This can e.g. be used to prioritize the cache during the first render after
41
+ * SSR.
42
+ */
43
+ prioritizeCacheValues = false;
33
44
  onBroadcast;
34
45
  mutationStore;
35
46
  // All the queries that the QueryManager is currently managing (not
@@ -77,15 +88,15 @@ export class QueryManager {
77
88
  this.queries.forEach((_info, queryId) => {
78
89
  this.removeQuery(queryId);
79
90
  });
80
- this.cancelPendingFetches(newInvariantError(72));
91
+ this.cancelPendingFetches(newInvariantError(68));
81
92
  }
82
93
  cancelPendingFetches(error) {
83
94
  this.fetchCancelFns.forEach((cancel) => cancel(error));
84
95
  this.fetchCancelFns.clear();
85
96
  }
86
97
  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, }) {
87
- invariant(mutation, 73);
88
- invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 74);
98
+ invariant(mutation, 69);
99
+ invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 70);
89
100
  const mutationId = this.generateMutationId();
90
101
  mutation = this.cache.transformForLink(this.transform(mutation));
91
102
  const { hasClientExports } = this.getDocumentInfo(mutation);
@@ -119,7 +130,8 @@ export class QueryManager {
119
130
  optimisticResponse: isOptimistic ? optimisticResponse : void 0,
120
131
  }, variables, {}, false)
121
132
  .pipe(mergeMap((result) => {
122
- if (graphQLResultHasError(result) && errorPolicy === "none") {
133
+ const hasErrors = graphQLResultHasError(result);
134
+ if (hasErrors && errorPolicy === "none") {
123
135
  throw new CombinedGraphQLErrors(getGraphQLErrorsFromResult(result));
124
136
  }
125
137
  if (mutationStoreValue) {
@@ -130,8 +142,7 @@ export class QueryManager {
130
142
  if (typeof refetchQueries === "function") {
131
143
  refetchQueries = refetchQueries(storeResult);
132
144
  }
133
- if (errorPolicy === "ignore" &&
134
- graphQLResultHasError(storeResult)) {
145
+ if (errorPolicy === "ignore" && hasErrors) {
135
146
  delete storeResult.errors;
136
147
  }
137
148
  return from(this.markMutationResult({
@@ -160,28 +171,40 @@ export class QueryManager {
160
171
  // ExecutionPatchResult has arrived and we have assembled the
161
172
  // multipart response into a single result.
162
173
  if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
163
- resolve({
164
- ...storeResult,
174
+ const result = {
165
175
  data: this.maskOperation({
166
176
  document: mutation,
167
177
  data: storeResult.data,
168
178
  fetchPolicy,
169
179
  id: mutationId,
170
180
  }),
171
- });
181
+ };
182
+ if (graphQLResultHasError(storeResult)) {
183
+ result.error = new CombinedGraphQLErrors(getGraphQLErrorsFromResult(storeResult));
184
+ }
185
+ if (storeResult.extensions) {
186
+ result.extensions = storeResult.extensions;
187
+ }
188
+ resolve(result);
172
189
  }
173
190
  },
174
191
  error: (err) => {
175
- err = maybeWrapError(err);
192
+ const error = maybeWrapError(err);
176
193
  if (mutationStoreValue) {
177
194
  mutationStoreValue.loading = false;
178
- mutationStoreValue.error = err;
195
+ mutationStoreValue.error = error;
179
196
  }
180
197
  if (isOptimistic) {
181
198
  this.cache.removeOptimistic(mutationId);
182
199
  }
183
200
  this.broadcastQueries();
184
- reject(err);
201
+ if (errorPolicy === "ignore") {
202
+ return resolve({ data: undefined });
203
+ }
204
+ if (errorPolicy === "all") {
205
+ return resolve({ data: undefined, error });
206
+ }
207
+ reject(error);
185
208
  },
186
209
  });
187
210
  });
@@ -454,10 +477,10 @@ export class QueryManager {
454
477
  // TODO: catch `EmptyError` and rethrow as network error if `complete`
455
478
  // notification is emitted without a value.
456
479
  query(options, queryId = this.generateQueryId()) {
457
- invariant(options.query, 75);
458
- invariant(options.query.kind === "Document", 76);
459
- invariant(!options.returnPartialData, 77);
460
- invariant(!options.pollInterval, 78);
480
+ invariant(options.query, 71);
481
+ invariant(options.query.kind === "Document", 72);
482
+ invariant(!options.returnPartialData, 73);
483
+ invariant(!options.pollInterval, 74);
461
484
  const query = this.transform(options.query);
462
485
  return this.fetchQuery(queryId, { ...options, query })
463
486
  .then((result) => result && {
@@ -491,7 +514,7 @@ export class QueryManager {
491
514
  // depend on values that previously existed in the data portion of the
492
515
  // store. So, we cancel the promises and observers that we have issued
493
516
  // so far and not yet resolved (in the case of queries).
494
- this.cancelPendingFetches(newInvariantError(79));
517
+ this.cancelPendingFetches(newInvariantError(75));
495
518
  this.queries.forEach((queryInfo) => {
496
519
  if (queryInfo.observableQuery) {
497
520
  // Set loading to true so listeners don't trigger unless they want
@@ -579,10 +602,10 @@ export class QueryManager {
579
602
  if (!included) {
580
603
  const queryName = queryNames.get(nameOrQueryString);
581
604
  if (queryName) {
582
- __DEV__ && invariant.warn(80, queryName);
605
+ __DEV__ && invariant.warn(76, queryName);
583
606
  }
584
607
  else {
585
- __DEV__ && invariant.warn(81);
608
+ __DEV__ && invariant.warn(77);
586
609
  }
587
610
  }
588
611
  });
@@ -611,38 +634,48 @@ export class QueryManager {
611
634
  const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
612
635
  query = this.transform(query);
613
636
  variables = this.getVariables(query, variables);
614
- const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((result) => {
637
+ const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe(map((rawResult) => {
615
638
  if (fetchPolicy !== "no-cache") {
616
639
  // the subscription interface should handle not sending us results we no longer subscribe to.
617
640
  // XXX I don't think we ever send in an object with errors, but we might in the future...
618
- if (shouldWriteResult(result, errorPolicy)) {
641
+ if (shouldWriteResult(rawResult, errorPolicy)) {
619
642
  this.cache.write({
620
643
  query,
621
- result: result.data,
644
+ result: rawResult.data,
622
645
  dataId: "ROOT_SUBSCRIPTION",
623
646
  variables: variables,
624
647
  });
625
648
  }
626
649
  this.broadcastQueries();
627
650
  }
628
- const hasErrors = graphQLResultHasError(result);
629
- const hasProtocolErrors = graphQLResultHasProtocolErrors(result);
630
- if (hasErrors && errorPolicy === "none") {
631
- throw new CombinedGraphQLErrors(result.errors);
651
+ const result = {
652
+ data: rawResult.data ?? undefined,
653
+ };
654
+ if (graphQLResultHasError(rawResult)) {
655
+ result.error = new CombinedGraphQLErrors(rawResult.errors);
656
+ }
657
+ else if (graphQLResultHasProtocolErrors(rawResult)) {
658
+ result.error = rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
659
+ // Don't emit protocol errors added by HttpLink
660
+ delete rawResult.extensions[PROTOCOL_ERRORS_SYMBOL];
661
+ }
662
+ if (rawResult.extensions &&
663
+ Object.keys(rawResult.extensions).length) {
664
+ result.extensions = rawResult.extensions;
632
665
  }
633
- if (hasProtocolErrors) {
634
- // `errorPolicy` is a mechanism for handling GraphQL errors, according
635
- // to our documentation, so we throw protocol errors regardless of the
636
- // set error policy.
637
- throw result.extensions[PROTOCOL_ERRORS_SYMBOL];
666
+ if (result.error && errorPolicy === "none") {
667
+ result.data = undefined;
638
668
  }
639
669
  if (errorPolicy === "ignore") {
640
- delete result.errors;
670
+ delete result.error;
641
671
  }
642
672
  return result;
643
673
  }), catchError((error) => {
644
- throw maybeWrapError(error);
645
- }));
674
+ if (errorPolicy === "ignore") {
675
+ return of({ data: undefined });
676
+ }
677
+ return of({ data: undefined, error: maybeWrapError(error) });
678
+ }), filter((result) => !!(result.data || result.error)));
646
679
  if (this.getDocumentInfo(query).hasClientExports) {
647
680
  const observablePromise = this.localState
648
681
  .addExportedVariables(query, variables, context)
@@ -810,6 +843,10 @@ export class QueryManager {
810
843
  const queryInfo = this.getQuery(queryId);
811
844
  const defaults = this.defaultOptions.watchQuery;
812
845
  let { fetchPolicy = (defaults && defaults.fetchPolicy) || "cache-first", errorPolicy = (defaults && defaults.errorPolicy) || "none", returnPartialData = false, notifyOnNetworkStatusChange = false, context = {}, } = options;
846
+ if (this.prioritizeCacheValues &&
847
+ (fetchPolicy === "network-only" || fetchPolicy === "cache-and-network")) {
848
+ fetchPolicy = "cache-first";
849
+ }
813
850
  const normalized = Object.assign({}, options, {
814
851
  query,
815
852
  variables,
@@ -1009,7 +1046,7 @@ export class QueryManager {
1009
1046
  !isFullyUnmaskedOperation(document) &&
1010
1047
  !this.noCacheWarningsByQueryId.has(operationId)) {
1011
1048
  this.noCacheWarningsByQueryId.add(operationId);
1012
- __DEV__ && invariant.warn(82, getOperationName(document) ??
1049
+ __DEV__ && invariant.warn(78, getOperationName(document) ??
1013
1050
  `Unnamed ${operationType ?? "operation"}`);
1014
1051
  }
1015
1052
  }