@apollo/client 4.0.0-alpha.4 → 4.0.0-alpha.6

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 (254) hide show
  1. package/.changeset/eleven-kangaroos-jump.md +5 -0
  2. package/.changeset/forty-shrimps-fry.md +5 -0
  3. package/.changeset/giant-bags-share.md +5 -0
  4. package/.changeset/grumpy-vans-type.md +5 -0
  5. package/.changeset/little-spoons-kick.md +7 -0
  6. package/.changeset/loud-cows-raise.md +7 -0
  7. package/.changeset/many-buses-allow.md +5 -0
  8. package/.changeset/nervous-fireants-bow.md +5 -0
  9. package/.changeset/poor-eels-punch.md +5 -0
  10. package/.changeset/pre.json +17 -0
  11. package/.changeset/real-teachers-peel.md +5 -0
  12. package/.changeset/slimy-chicken-melt.md +5 -0
  13. package/.changeset/tame-points-work.md +11 -0
  14. package/.changeset/tender-swans-flash.md +16 -0
  15. package/.changeset/thick-books-grin.md +5 -0
  16. package/.changeset/tough-rockets-allow.md +5 -0
  17. package/.changeset/tricky-tables-shave.md +5 -0
  18. package/.changeset/warm-ties-sit.md +7 -0
  19. package/CHANGELOG.md +72 -0
  20. package/__cjs/cache/core/cache.cjs +1 -1
  21. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  22. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  23. package/__cjs/cache/inmemory/policies.cjs +4 -4
  24. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  25. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  26. package/__cjs/config/jest/areCombinedGraphQLErrorsEqual.cjs +3 -1
  27. package/__cjs/config/jest/areCombinedGraphQLErrorsEqual.cjs.map +1 -1
  28. package/__cjs/config/jest/setup.cjs +6 -0
  29. package/__cjs/config/jest/setup.cjs.map +1 -1
  30. package/__cjs/core/ApolloClient.cjs +9 -3
  31. package/__cjs/core/ApolloClient.cjs.map +1 -1
  32. package/__cjs/core/ApolloClient.d.cts +8 -8
  33. package/__cjs/core/LocalState.cjs +2 -2
  34. package/__cjs/core/ObservableQuery.cjs +25 -17
  35. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  36. package/__cjs/core/ObservableQuery.d.cts +6 -6
  37. package/__cjs/core/QueryManager.cjs +78 -47
  38. package/__cjs/core/QueryManager.cjs.map +1 -1
  39. package/__cjs/core/QueryManager.d.cts +6 -6
  40. package/__cjs/core/types.d.cts +56 -2
  41. package/__cjs/errors/CombinedGraphQLErrors.cjs +8 -1
  42. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  43. package/__cjs/errors/CombinedGraphQLErrors.d.cts +7 -2
  44. package/__cjs/invariantErrorCodes.cjs +108 -106
  45. package/__cjs/link/core/ApolloLink.cjs +2 -2
  46. package/__cjs/link/http/checkFetcher.cjs +1 -1
  47. package/__cjs/link/http/createHttpLink.cjs +1 -1
  48. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  49. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  50. package/__cjs/link/persisted-queries/index.cjs +2 -2
  51. package/__cjs/link/subscriptions/index.cjs +3 -1
  52. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  53. package/__cjs/link/utils/validateOperation.cjs +1 -1
  54. package/__cjs/masking/maskDefinition.cjs +2 -2
  55. package/__cjs/masking/maskFragment.cjs +2 -2
  56. package/__cjs/masking/maskOperation.cjs +1 -1
  57. package/__cjs/masking/utils.cjs +1 -1
  58. package/__cjs/react/context/ApolloConsumer.cjs +1 -1
  59. package/__cjs/react/context/ApolloContext.cjs +1 -1
  60. package/__cjs/react/context/ApolloContext.cjs.map +1 -1
  61. package/__cjs/react/context/ApolloContext.d.cts +2 -2
  62. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  63. package/__cjs/react/hooks/internal/wrapHook.cjs +26 -5
  64. package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
  65. package/__cjs/react/hooks/internal/wrapHook.d.cts +3 -1
  66. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  67. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  68. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  69. package/__cjs/react/hooks/useLazyQuery.d.cts +4 -4
  70. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  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 +4 -4
  74. package/__cjs/react/hooks/useQuery.cjs +82 -187
  75. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  76. package/__cjs/react/hooks/useQuery.d.cts +7 -3
  77. package/__cjs/react/hooks/useSubscription.cjs +8 -57
  78. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  79. package/__cjs/react/hooks/useSubscription.d.cts +6 -42
  80. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -2
  81. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  82. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  83. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  84. package/__cjs/react/internal/cache/QueryReference.d.cts +3 -3
  85. package/__cjs/react/internal/index.cjs +3 -1
  86. package/__cjs/react/internal/index.cjs.map +1 -1
  87. package/__cjs/react/internal/index.d.cts +1 -0
  88. package/__cjs/react/internal/types.d.cts +2 -2
  89. package/__cjs/react/parser/index.cjs +5 -5
  90. package/__cjs/react/ssr/getDataFromTree.cjs +24 -30
  91. package/__cjs/react/ssr/getDataFromTree.cjs.map +1 -1
  92. package/__cjs/react/ssr/getDataFromTree.d.cts +12 -1
  93. package/__cjs/react/ssr/index.cjs +3 -3
  94. package/__cjs/react/ssr/index.cjs.map +1 -1
  95. package/__cjs/react/ssr/index.d.cts +1 -1
  96. package/__cjs/react/ssr/prerenderStatic.cjs +151 -0
  97. package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -0
  98. package/__cjs/react/ssr/prerenderStatic.d.cts +122 -0
  99. package/__cjs/react/ssr/renderToStringWithData.cjs +11 -5
  100. package/__cjs/react/ssr/renderToStringWithData.cjs.map +1 -1
  101. package/__cjs/react/ssr/renderToStringWithData.d.cts +5 -0
  102. package/__cjs/react/ssr/useSSRQuery.cjs +60 -0
  103. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -0
  104. package/__cjs/react/ssr/useSSRQuery.d.cts +5 -0
  105. package/__cjs/react/types/deprecated.d.cts +1 -1
  106. package/__cjs/react/types/types.documentation.d.cts +4 -12
  107. package/__cjs/testing/internal/index.cjs +3 -1
  108. package/__cjs/testing/internal/index.cjs.map +1 -1
  109. package/__cjs/testing/internal/index.d.cts +1 -0
  110. package/__cjs/testing/internal/resetApolloContext.cjs +24 -0
  111. package/__cjs/testing/internal/resetApolloContext.cjs.map +1 -0
  112. package/__cjs/testing/internal/resetApolloContext.d.cts +10 -0
  113. package/__cjs/testing/matchers/index.cjs +2 -0
  114. package/__cjs/testing/matchers/index.cjs.map +1 -1
  115. package/__cjs/testing/matchers/toEmitStrictTyped.cjs +42 -0
  116. package/__cjs/testing/matchers/toEmitStrictTyped.cjs.map +1 -0
  117. package/__cjs/testing/matchers/toEmitStrictTyped.d.cts +7 -0
  118. package/__cjs/testing/matchers/toEqualStrictTyped.cjs +2 -20
  119. package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -1
  120. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +23 -0
  121. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -0
  122. package/__cjs/testing/matchers/utils/getSerializableProperties.d.cts +2 -0
  123. package/__cjs/utilities/internal/index.cjs +3 -1
  124. package/__cjs/utilities/internal/index.cjs.map +1 -1
  125. package/__cjs/utilities/internal/index.d.cts +1 -0
  126. package/__cjs/utilities/internal/toQueryResult.cjs +13 -0
  127. package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -0
  128. package/__cjs/utilities/internal/toQueryResult.d.cts +3 -0
  129. package/__cjs/version.cjs +1 -1
  130. package/__cjs/version.d.cts +1 -1
  131. package/cache/core/cache.js +1 -1
  132. package/cache/inmemory/entityStore.js +3 -3
  133. package/cache/inmemory/key-extractor.js +1 -1
  134. package/cache/inmemory/policies.js +4 -4
  135. package/cache/inmemory/readFromStore.js +2 -2
  136. package/cache/inmemory/writeToStore.js +4 -4
  137. package/config/jest/areCombinedGraphQLErrorsEqual.js +3 -1
  138. package/config/jest/areCombinedGraphQLErrorsEqual.js.map +1 -1
  139. package/config/jest/setup.js +6 -0
  140. package/config/jest/setup.js.map +1 -1
  141. package/core/ApolloClient.d.ts +8 -8
  142. package/core/ApolloClient.js +9 -3
  143. package/core/ApolloClient.js.map +1 -1
  144. package/core/LocalState.js +2 -2
  145. package/core/ObservableQuery.d.ts +6 -6
  146. package/core/ObservableQuery.js +25 -17
  147. package/core/ObservableQuery.js.map +1 -1
  148. package/core/QueryManager.d.ts +6 -6
  149. package/core/QueryManager.js +80 -49
  150. package/core/QueryManager.js.map +1 -1
  151. package/core/types.d.ts +56 -2
  152. package/errors/CombinedGraphQLErrors.d.ts +7 -2
  153. package/errors/CombinedGraphQLErrors.js +8 -1
  154. package/errors/CombinedGraphQLErrors.js.map +1 -1
  155. package/invariantErrorCodes.js +108 -106
  156. package/link/core/ApolloLink.js +2 -2
  157. package/link/http/checkFetcher.js +1 -1
  158. package/link/http/createHttpLink.js +1 -1
  159. package/link/http/parseAndCheckHttpResponse.js +1 -1
  160. package/link/http/serializeFetchParameter.js +1 -1
  161. package/link/persisted-queries/index.js +2 -2
  162. package/link/subscriptions/index.js +3 -1
  163. package/link/subscriptions/index.js.map +1 -1
  164. package/link/utils/validateOperation.js +1 -1
  165. package/masking/maskDefinition.js +2 -2
  166. package/masking/maskFragment.js +2 -2
  167. package/masking/maskOperation.js +1 -1
  168. package/masking/utils.js +1 -1
  169. package/package.json +1 -1
  170. package/react/context/ApolloConsumer.js +1 -1
  171. package/react/context/ApolloContext.d.ts +2 -2
  172. package/react/context/ApolloContext.js +1 -1
  173. package/react/context/ApolloContext.js.map +1 -1
  174. package/react/context/ApolloProvider.js +1 -1
  175. package/react/hooks/internal/wrapHook.d.ts +3 -1
  176. package/react/hooks/internal/wrapHook.js +24 -5
  177. package/react/hooks/internal/wrapHook.js.map +1 -1
  178. package/react/hooks/useApolloClient.js +1 -1
  179. package/react/hooks/useLazyQuery.d.ts +4 -4
  180. package/react/hooks/useLazyQuery.js +2 -2
  181. package/react/hooks/useLazyQuery.js.map +1 -1
  182. package/react/hooks/useLoadableQuery.js +2 -2
  183. package/react/hooks/useMutation.d.ts +4 -4
  184. package/react/hooks/useMutation.js +14 -19
  185. package/react/hooks/useMutation.js.map +1 -1
  186. package/react/hooks/useQuery.d.ts +7 -3
  187. package/react/hooks/useQuery.js +83 -188
  188. package/react/hooks/useQuery.js.map +1 -1
  189. package/react/hooks/useSubscription.d.ts +6 -42
  190. package/react/hooks/useSubscription.js +7 -53
  191. package/react/hooks/useSubscription.js.map +1 -1
  192. package/react/hooks/useSuspenseQuery.js +2 -2
  193. package/react/hooks/useSyncExternalStore.js +1 -1
  194. package/react/internal/cache/QueryReference.d.ts +3 -3
  195. package/react/internal/cache/QueryReference.js +1 -1
  196. package/react/internal/cache/QueryReference.js.map +1 -1
  197. package/react/internal/index.d.ts +1 -0
  198. package/react/internal/index.js +2 -1
  199. package/react/internal/index.js.map +1 -1
  200. package/react/internal/types.d.ts +2 -2
  201. package/react/parser/index.js +5 -5
  202. package/react/ssr/getDataFromTree.d.ts +12 -1
  203. package/react/ssr/getDataFromTree.js +24 -29
  204. package/react/ssr/getDataFromTree.js.map +1 -1
  205. package/react/ssr/index.d.ts +1 -1
  206. package/react/ssr/index.js +1 -1
  207. package/react/ssr/index.js.map +1 -1
  208. package/react/ssr/prerenderStatic.d.ts +122 -0
  209. package/react/ssr/prerenderStatic.js +147 -0
  210. package/react/ssr/prerenderStatic.js.map +1 -0
  211. package/react/ssr/renderToStringWithData.d.ts +5 -0
  212. package/react/ssr/renderToStringWithData.js +11 -5
  213. package/react/ssr/renderToStringWithData.js.map +1 -1
  214. package/react/ssr/useSSRQuery.d.ts +5 -0
  215. package/react/ssr/useSSRQuery.js +56 -0
  216. package/react/ssr/useSSRQuery.js.map +1 -0
  217. package/react/types/deprecated.d.ts +1 -1
  218. package/react/types/types.documentation.d.ts +4 -12
  219. package/testing/internal/index.d.ts +1 -0
  220. package/testing/internal/index.js +2 -1
  221. package/testing/internal/index.js.map +1 -1
  222. package/testing/internal/resetApolloContext.d.ts +10 -0
  223. package/testing/internal/resetApolloContext.js +20 -0
  224. package/testing/internal/resetApolloContext.js.map +1 -0
  225. package/testing/matchers/index.js +2 -0
  226. package/testing/matchers/index.js.map +1 -1
  227. package/testing/matchers/toEmitStrictTyped.d.ts +7 -0
  228. package/testing/matchers/toEmitStrictTyped.js +38 -0
  229. package/testing/matchers/toEmitStrictTyped.js.map +1 -0
  230. package/testing/matchers/toEqualStrictTyped.js +1 -19
  231. package/testing/matchers/toEqualStrictTyped.js.map +1 -1
  232. package/testing/matchers/utils/getSerializableProperties.d.ts +2 -0
  233. package/testing/matchers/utils/getSerializableProperties.js +20 -0
  234. package/testing/matchers/utils/getSerializableProperties.js.map +1 -0
  235. package/utilities/internal/index.d.ts +1 -0
  236. package/utilities/internal/index.js +2 -1
  237. package/utilities/internal/index.js.map +1 -1
  238. package/utilities/internal/toQueryResult.d.ts +3 -0
  239. package/utilities/internal/toQueryResult.js +10 -0
  240. package/utilities/internal/toQueryResult.js.map +1 -0
  241. package/version.d.ts +1 -1
  242. package/version.js +1 -1
  243. package/__cjs/react/ssr/RenderPromises.cjs +0 -104
  244. package/__cjs/react/ssr/RenderPromises.cjs.map +0 -1
  245. package/__cjs/react/ssr/RenderPromises.d.cts +0 -25
  246. package/__cjs/utilities/types/TODO.cjs +0 -3
  247. package/__cjs/utilities/types/TODO.cjs.map +0 -1
  248. package/__cjs/utilities/types/TODO.d.cts +0 -3
  249. package/react/ssr/RenderPromises.d.ts +0 -25
  250. package/react/ssr/RenderPromises.js +0 -100
  251. package/react/ssr/RenderPromises.js.map +0 -1
  252. package/utilities/types/TODO.d.ts +0 -3
  253. package/utilities/types/TODO.js +0 -2
  254. package/utilities/types/TODO.js.map +0 -1
@@ -5,7 +5,7 @@ import type { MissingTree } from "@apollo/client/cache";
5
5
  import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
6
6
  import type { QueryInfo } from "./QueryInfo.cjs";
7
7
  import type { QueryManager } from "./QueryManager.cjs";
8
- import type { ApolloQueryResult, ErrorLike, OperationVariables, TypedDocumentNode } from "./types.cjs";
8
+ import type { ApolloQueryResult, ErrorLike, OperationVariables, QueryResult, TypedDocumentNode } from "./types.cjs";
9
9
  import type { FetchMoreQueryOptions, SubscribeToMoreOptions, UpdateQueryMapFn, WatchQueryOptions } from "./watchQueryOptions.cjs";
10
10
  export interface FetchMoreOptions<TData = unknown, TVariables = OperationVariables> {
11
11
  updateQuery?: (previousQueryResult: TData, options: {
@@ -61,7 +61,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
61
61
  * @param variables - The new set of variables. If there are missing variables,
62
62
  * the previous values of those variables will be used.
63
63
  */
64
- refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
64
+ refetch(variables?: Partial<TVariables>): Promise<QueryResult<TData>>;
65
65
  /**
66
66
  * A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
67
67
  */
@@ -70,7 +70,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
70
70
  fetchMoreResult: Unmasked<TFetchData>;
71
71
  variables: TFetchVars;
72
72
  }) => Unmasked<TData>;
73
- }): Promise<ApolloQueryResult<MaybeMasked<TFetchData>>>;
73
+ }): Promise<QueryResult<TFetchData>>;
74
74
  /**
75
75
  * A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
76
76
  *
@@ -97,7 +97,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
97
97
  * @param variables - The new set of variables. If there are missing variables,
98
98
  * the previous values of those variables will be used.
99
99
  */
100
- setVariables(variables: TVariables): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
100
+ setVariables(variables: TVariables): Promise<QueryResult<TData>>;
101
101
  /**
102
102
  * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
103
103
  *
@@ -120,7 +120,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
120
120
  * Reevaluate the query, optionally against new options. New options will be
121
121
  * merged with the current options when given.
122
122
  */
123
- reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<MaybeMasked<TData>>>;
123
+ reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>): Promise<QueryResult<MaybeMasked<TData>>>;
124
124
  private observe;
125
125
  private reportResult;
126
126
  private reportError;
@@ -129,6 +129,6 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
129
129
  private transformDocument;
130
130
  private maskResult;
131
131
  }
132
- export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<ApolloQueryResult<TData>>;
132
+ export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<QueryResult<TData>>;
133
133
  export declare function logMissingFieldErrors(missing: MissingFieldError | MissingTree | undefined): void;
134
134
  //# sourceMappingURL=ObservableQuery.d.cts.map
@@ -95,15 +95,15 @@ class QueryManager {
95
95
  this.queries.forEach((_info, queryId) => {
96
96
  this.removeQuery(queryId);
97
97
  });
98
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(72));
98
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(74));
99
99
  }
100
100
  cancelPendingFetches(error) {
101
101
  this.fetchCancelFns.forEach((cancel) => cancel(error));
102
102
  this.fetchCancelFns.clear();
103
103
  }
104
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, }) {
105
- (0, invariant_1.invariant)(mutation, 73);
106
- (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 74);
105
+ (0, invariant_1.invariant)(mutation, 75);
106
+ (0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 76);
107
107
  const mutationId = this.generateMutationId();
108
108
  mutation = this.cache.transformForLink(this.transform(mutation));
109
109
  const { hasClientExports } = this.getDocumentInfo(mutation);
@@ -136,9 +136,10 @@ class QueryManager {
136
136
  ...context,
137
137
  optimisticResponse: isOptimistic ? optimisticResponse : void 0,
138
138
  }, variables, {}, false)
139
- .pipe((0, rxjs_1.mergeMap)((result) => {
140
- if ((0, utilities_4.graphQLResultHasError)(result) && errorPolicy === "none") {
141
- throw new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(result));
139
+ .pipe(validateDidEmitValue(), (0, rxjs_1.mergeMap)((result) => {
140
+ const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
141
+ if (hasErrors && errorPolicy === "none") {
142
+ throw new errors_1.CombinedGraphQLErrors(result);
142
143
  }
143
144
  if (mutationStoreValue) {
144
145
  mutationStoreValue.loading = false;
@@ -148,8 +149,7 @@ class QueryManager {
148
149
  if (typeof refetchQueries === "function") {
149
150
  refetchQueries = refetchQueries(storeResult);
150
151
  }
151
- if (errorPolicy === "ignore" &&
152
- (0, utilities_4.graphQLResultHasError)(storeResult)) {
152
+ if (errorPolicy === "ignore" && hasErrors) {
153
153
  delete storeResult.errors;
154
154
  }
155
155
  return (0, rxjs_1.from)(this.markMutationResult({
@@ -178,28 +178,40 @@ class QueryManager {
178
178
  // ExecutionPatchResult has arrived and we have assembled the
179
179
  // multipart response into a single result.
180
180
  if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
181
- resolve({
182
- ...storeResult,
181
+ const result = {
183
182
  data: this.maskOperation({
184
183
  document: mutation,
185
184
  data: storeResult.data,
186
185
  fetchPolicy,
187
186
  id: mutationId,
188
187
  }),
189
- });
188
+ };
189
+ if ((0, utilities_4.graphQLResultHasError)(storeResult)) {
190
+ result.error = new errors_1.CombinedGraphQLErrors(storeResult);
191
+ }
192
+ if (storeResult.extensions) {
193
+ result.extensions = storeResult.extensions;
194
+ }
195
+ resolve(result);
190
196
  }
191
197
  },
192
198
  error: (err) => {
193
- err = maybeWrapError(err);
199
+ const error = maybeWrapError(err);
194
200
  if (mutationStoreValue) {
195
201
  mutationStoreValue.loading = false;
196
- mutationStoreValue.error = err;
202
+ mutationStoreValue.error = error;
197
203
  }
198
204
  if (isOptimistic) {
199
205
  this.cache.removeOptimistic(mutationId);
200
206
  }
201
207
  this.broadcastQueries();
202
- 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);
203
215
  },
204
216
  });
205
217
  });
@@ -389,7 +401,11 @@ class QueryManager {
389
401
  return true;
390
402
  }
391
403
  fetchQuery(queryId, options, networkStatus) {
392
- return (0, rxjs_1.lastValueFrom)(this.fetchObservableWithInfo(queryId, options, networkStatus).observable, { defaultValue: undefined });
404
+ return (0, rxjs_1.lastValueFrom)(this.fetchObservableWithInfo(queryId, options, networkStatus).observable.pipe((0, rxjs_1.map)(internal_1.toQueryResult)), {
405
+ // This default is needed when a `standby` fetch policy is used to avoid
406
+ // an EmptyError from rejecting this promise.
407
+ defaultValue: { data: undefined },
408
+ });
393
409
  }
394
410
  transform(document) {
395
411
  return this.documentTransform.transformDocument(document);
@@ -469,24 +485,18 @@ class QueryManager {
469
485
  });
470
486
  return observable;
471
487
  }
472
- // TODO: catch `EmptyError` and rethrow as network error if `complete`
473
- // notification is emitted without a value.
474
488
  query(options, queryId = this.generateQueryId()) {
475
- (0, invariant_1.invariant)(options.query, 75);
476
- (0, invariant_1.invariant)(options.query.kind === "Document", 76);
477
- (0, invariant_1.invariant)(!options.returnPartialData, 77);
478
- (0, invariant_1.invariant)(!options.pollInterval, 78);
479
489
  const query = this.transform(options.query);
480
490
  return this.fetchQuery(queryId, { ...options, query })
481
- .then((result) => result && {
482
- ...result,
491
+ .then((value) => ({
492
+ ...value,
483
493
  data: this.maskOperation({
484
494
  document: query,
485
- data: result.data,
495
+ data: value?.data,
486
496
  fetchPolicy: options.fetchPolicy,
487
497
  id: queryId,
488
498
  }),
489
- })
499
+ }))
490
500
  .finally(() => this.stopQuery(queryId));
491
501
  }
492
502
  queryIdCounter = 1;
@@ -509,7 +519,7 @@ class QueryManager {
509
519
  // depend on values that previously existed in the data portion of the
510
520
  // store. So, we cancel the promises and observers that we have issued
511
521
  // so far and not yet resolved (in the case of queries).
512
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(79));
522
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(77));
513
523
  this.queries.forEach((queryInfo) => {
514
524
  if (queryInfo.observableQuery) {
515
525
  // Set loading to true so listeners don't trigger unless they want
@@ -597,10 +607,10 @@ class QueryManager {
597
607
  if (!included) {
598
608
  const queryName = queryNames.get(nameOrQueryString);
599
609
  if (queryName) {
600
- __DEV__ && invariant_1.invariant.warn(80, queryName);
610
+ __DEV__ && invariant_1.invariant.warn(78, queryName);
601
611
  }
602
612
  else {
603
- __DEV__ && invariant_1.invariant.warn(81);
613
+ __DEV__ && invariant_1.invariant.warn(79);
604
614
  }
605
615
  }
606
616
  });
@@ -629,38 +639,48 @@ class QueryManager {
629
639
  const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
630
640
  query = this.transform(query);
631
641
  variables = this.getVariables(query, variables);
632
- const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((result) => {
642
+ const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((rawResult) => {
633
643
  if (fetchPolicy !== "no-cache") {
634
644
  // the subscription interface should handle not sending us results we no longer subscribe to.
635
645
  // XXX I don't think we ever send in an object with errors, but we might in the future...
636
- if ((0, QueryInfo_js_1.shouldWriteResult)(result, errorPolicy)) {
646
+ if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
637
647
  this.cache.write({
638
648
  query,
639
- result: result.data,
649
+ result: rawResult.data,
640
650
  dataId: "ROOT_SUBSCRIPTION",
641
651
  variables: variables,
642
652
  });
643
653
  }
644
654
  this.broadcastQueries();
645
655
  }
646
- const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
647
- const hasProtocolErrors = (0, errors_1.graphQLResultHasProtocolErrors)(result);
648
- if (hasErrors && errorPolicy === "none") {
649
- throw new errors_1.CombinedGraphQLErrors(result.errors);
656
+ const result = {
657
+ data: rawResult.data ?? undefined,
658
+ };
659
+ if ((0, utilities_4.graphQLResultHasError)(rawResult)) {
660
+ result.error = new errors_1.CombinedGraphQLErrors(rawResult);
661
+ }
662
+ else if ((0, errors_1.graphQLResultHasProtocolErrors)(rawResult)) {
663
+ result.error = rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
664
+ // Don't emit protocol errors added by HttpLink
665
+ delete rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
650
666
  }
651
- if (hasProtocolErrors) {
652
- // `errorPolicy` is a mechanism for handling GraphQL errors, according
653
- // to our documentation, so we throw protocol errors regardless of the
654
- // set error policy.
655
- throw result.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
667
+ if (rawResult.extensions &&
668
+ Object.keys(rawResult.extensions).length) {
669
+ result.extensions = rawResult.extensions;
670
+ }
671
+ if (result.error && errorPolicy === "none") {
672
+ result.data = undefined;
656
673
  }
657
674
  if (errorPolicy === "ignore") {
658
- delete result.errors;
675
+ delete result.error;
659
676
  }
660
677
  return result;
661
678
  }), (0, rxjs_1.catchError)((error) => {
662
- throw maybeWrapError(error);
663
- }));
679
+ if (errorPolicy === "ignore") {
680
+ return (0, rxjs_1.of)({ data: undefined });
681
+ }
682
+ return (0, rxjs_1.of)({ data: undefined, error: maybeWrapError(error) });
683
+ }), (0, rxjs_1.filter)((result) => !!(result.data || result.error)));
664
684
  if (this.getDocumentInfo(query).hasClientExports) {
665
685
  const observablePromise = this.localState
666
686
  .addExportedVariables(query, variables, context)
@@ -773,7 +793,7 @@ class QueryManager {
773
793
  queryInfo.resetLastWrite();
774
794
  queryInfo.reset();
775
795
  // Throwing here effectively calls observer.error.
776
- throw new errors_1.CombinedGraphQLErrors(graphQLErrors);
796
+ throw new errors_1.CombinedGraphQLErrors(result);
777
797
  }
778
798
  // Use linkDocument rather than queryInfo.document so the
779
799
  // operation/fragments used to write the result are the same as the
@@ -794,7 +814,7 @@ class QueryManager {
794
814
  aqr.data = void 0;
795
815
  }
796
816
  if (hasErrors && errorPolicy !== "ignore") {
797
- aqr.error = new errors_1.CombinedGraphQLErrors(graphQLErrors);
817
+ aqr.error = new errors_1.CombinedGraphQLErrors(result);
798
818
  aqr.networkStatus = networkStatus_js_1.NetworkStatus.error;
799
819
  }
800
820
  return aqr;
@@ -1031,7 +1051,7 @@ class QueryManager {
1031
1051
  !(0, utilities_3.isFullyUnmaskedOperation)(document) &&
1032
1052
  !this.noCacheWarningsByQueryId.has(operationId)) {
1033
1053
  this.noCacheWarningsByQueryId.add(operationId);
1034
- __DEV__ && invariant_1.invariant.warn(82, (0, utilities_4.getOperationName)(document) ??
1054
+ __DEV__ && invariant_1.invariant.warn(80, (0, utilities_4.getOperationName)(document) ??
1035
1055
  `Unnamed ${operationType ?? "operation"}`);
1036
1056
  }
1037
1057
  }
@@ -1121,7 +1141,7 @@ class QueryManager {
1121
1141
  context,
1122
1142
  fetchPolicy,
1123
1143
  errorPolicy,
1124
- });
1144
+ }).pipe(validateDidEmitValue());
1125
1145
  switch (fetchPolicy) {
1126
1146
  default:
1127
1147
  case "cache-first": {
@@ -1211,4 +1231,15 @@ function maybeWrapError(error) {
1211
1231
  }
1212
1232
  return new errors_1.UnconventionalError(error);
1213
1233
  }
1234
+ function validateDidEmitValue() {
1235
+ let didEmitValue = false;
1236
+ return (0, rxjs_1.tap)({
1237
+ next() {
1238
+ didEmitValue = true;
1239
+ },
1240
+ complete() {
1241
+ (0, invariant_1.invariant)(didEmitValue, 81);
1242
+ },
1243
+ });
1244
+ }
1214
1245
  //# sourceMappingURL=QueryManager.cjs.map