@apollo/client 4.0.0-alpha.22 → 4.0.0-alpha.23

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 (268) hide show
  1. package/CHANGELOG.md +238 -2
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  5. package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  6. package/__cjs/cache/inmemory/policies.cjs +4 -4
  7. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  8. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  9. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  10. package/__cjs/core/ApolloClient.cjs +15 -13
  11. package/__cjs/core/ApolloClient.cjs.map +1 -1
  12. package/__cjs/core/ApolloClient.d.cts +8 -3
  13. package/__cjs/core/ObservableQuery.cjs +52 -48
  14. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  15. package/__cjs/core/ObservableQuery.d.cts +48 -14
  16. package/__cjs/core/QueryInfo.cjs +146 -168
  17. package/__cjs/core/QueryInfo.cjs.map +1 -1
  18. package/__cjs/core/QueryInfo.d.cts +14 -11
  19. package/__cjs/core/QueryManager.cjs +121 -111
  20. package/__cjs/core/QueryManager.cjs.map +1 -1
  21. package/__cjs/core/QueryManager.d.cts +4 -0
  22. package/__cjs/core/index.cjs +2 -1
  23. package/__cjs/core/index.cjs.map +1 -1
  24. package/__cjs/core/index.d.cts +4 -4
  25. package/__cjs/core/types.d.cts +68 -15
  26. package/__cjs/core/watchQueryOptions.d.cts +2 -24
  27. package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
  28. package/__cjs/errors/CombinedGraphQLErrors.cjs +6 -3
  29. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  30. package/__cjs/errors/CombinedGraphQLErrors.d.cts +7 -2
  31. package/__cjs/errors/index.cjs +1 -1
  32. package/__cjs/errors/index.cjs.map +1 -1
  33. package/__cjs/errors/index.d.cts +1 -3
  34. package/__cjs/incremental/handlers/defer20220824.cjs +102 -0
  35. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -0
  36. package/__cjs/incremental/handlers/defer20220824.d.cts +55 -0
  37. package/__cjs/incremental/handlers/notImplemented.cjs +19 -0
  38. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -0
  39. package/__cjs/incremental/handlers/notImplemented.d.cts +9 -0
  40. package/__cjs/incremental/index.cjs +9 -0
  41. package/__cjs/incremental/index.cjs.map +1 -0
  42. package/__cjs/incremental/index.d.cts +4 -0
  43. package/__cjs/incremental/types.cjs +3 -0
  44. package/__cjs/incremental/types.cjs.map +1 -0
  45. package/__cjs/incremental/types.d.cts +24 -0
  46. package/__cjs/invariantErrorCodes.cjs +62 -45
  47. package/__cjs/link/context/index.cjs +36 -25
  48. package/__cjs/link/context/index.cjs.map +1 -1
  49. package/__cjs/link/context/index.d.cts +8 -1
  50. package/__cjs/link/core/types.d.cts +4 -32
  51. package/__cjs/link/error/index.cjs +68 -65
  52. package/__cjs/link/error/index.cjs.map +1 -1
  53. package/__cjs/link/error/index.d.cts +15 -14
  54. package/__cjs/link/http/BaseHttpLink.cjs +0 -6
  55. package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
  56. package/__cjs/link/http/HttpLink.cjs +4 -0
  57. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  58. package/__cjs/link/http/HttpLink.d.cts +4 -0
  59. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +45 -57
  60. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  61. package/__cjs/link/index.cjs.map +1 -1
  62. package/__cjs/link/index.d.cts +1 -1
  63. package/__cjs/link/persisted-queries/index.cjs +158 -142
  64. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  65. package/__cjs/link/persisted-queries/index.d.cts +19 -19
  66. package/__cjs/link/remove-typename/index.cjs +2 -1
  67. package/__cjs/link/remove-typename/index.cjs.map +1 -1
  68. package/__cjs/link/remove-typename/index.d.cts +1 -1
  69. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +34 -23
  70. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
  71. package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +8 -9
  72. package/__cjs/local-state/LocalState.cjs.map +1 -1
  73. package/__cjs/local-state/LocalState.d.cts +3 -4
  74. package/__cjs/masking/types.d.cts +6 -5
  75. package/__cjs/react/hooks/useBackgroundQuery.cjs +1 -0
  76. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  77. package/__cjs/react/hooks/useFragment.cjs +1 -0
  78. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  79. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  80. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  81. package/__cjs/react/hooks/useLazyQuery.d.cts +2 -7
  82. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  83. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  84. package/__cjs/react/hooks/useMutation.d.cts +2 -2
  85. package/__cjs/react/hooks/useQuery.cjs +23 -21
  86. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  87. package/__cjs/react/hooks/useQuery.d.cts +3 -8
  88. package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -0
  89. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  90. package/__cjs/react/hooks/useReadQuery.cjs +1 -0
  91. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  92. package/__cjs/react/hooks/useSuspenseFragment.cjs +1 -0
  93. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  94. package/__cjs/react/hooks/useSuspenseQuery.cjs +1 -0
  95. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  96. package/__cjs/react/internal/cache/QueryReference.cjs +4 -4
  97. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  98. package/__cjs/react/internal/cache/QueryReference.d.cts +2 -3
  99. package/__cjs/react/internal/types.d.cts +2 -7
  100. package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs +9 -0
  101. package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs.map +1 -0
  102. package/__cjs/utilities/graphql/isFormattedExecutionResult.d.cts +3 -0
  103. package/__cjs/utilities/index.cjs +3 -1
  104. package/__cjs/utilities/index.cjs.map +1 -1
  105. package/__cjs/utilities/index.d.cts +1 -0
  106. package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs +1 -12
  107. package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs.map +1 -1
  108. package/__cjs/utilities/internal/getGraphQLErrorsFromResult.d.cts +4 -2
  109. package/__cjs/utilities/internal/graphQLResultHasError.cjs +1 -4
  110. package/__cjs/utilities/internal/graphQLResultHasError.cjs.map +1 -1
  111. package/__cjs/utilities/internal/graphQLResultHasError.d.cts +2 -2
  112. package/__cjs/utilities/internal/index.cjs +2 -10
  113. package/__cjs/utilities/internal/index.cjs.map +1 -1
  114. package/__cjs/utilities/internal/index.d.cts +0 -4
  115. package/__cjs/version.cjs +3 -2
  116. package/__cjs/version.cjs.map +1 -1
  117. package/__cjs/version.d.cts +1 -0
  118. package/cache/core/cache.js +1 -1
  119. package/cache/inmemory/entityStore.js +3 -3
  120. package/cache/inmemory/key-extractor.js +1 -1
  121. package/cache/inmemory/key-extractor.js.map +1 -1
  122. package/cache/inmemory/policies.js +4 -4
  123. package/cache/inmemory/policies.js.map +1 -1
  124. package/cache/inmemory/readFromStore.js +2 -2
  125. package/cache/inmemory/writeToStore.js +4 -4
  126. package/core/ApolloClient.d.ts +8 -3
  127. package/core/ApolloClient.js +15 -13
  128. package/core/ApolloClient.js.map +1 -1
  129. package/core/ObservableQuery.d.ts +48 -14
  130. package/core/ObservableQuery.js +53 -49
  131. package/core/ObservableQuery.js.map +1 -1
  132. package/core/QueryInfo.d.ts +14 -11
  133. package/core/QueryInfo.js +147 -169
  134. package/core/QueryInfo.js.map +1 -1
  135. package/core/QueryManager.d.ts +4 -0
  136. package/core/QueryManager.js +123 -113
  137. package/core/QueryManager.js.map +1 -1
  138. package/core/index.d.ts +4 -4
  139. package/core/index.js +1 -1
  140. package/core/index.js.map +1 -1
  141. package/core/types.d.ts +68 -15
  142. package/core/watchQueryOptions.d.ts +2 -24
  143. package/dev/setErrorMessageHandler.js.map +1 -1
  144. package/errors/CombinedGraphQLErrors.d.ts +7 -2
  145. package/errors/CombinedGraphQLErrors.js +6 -3
  146. package/errors/CombinedGraphQLErrors.js.map +1 -1
  147. package/errors/index.d.ts +1 -3
  148. package/errors/index.js +1 -1
  149. package/errors/index.js.map +1 -1
  150. package/incremental/handlers/defer20220824.d.ts +55 -0
  151. package/incremental/handlers/defer20220824.js +97 -0
  152. package/incremental/handlers/defer20220824.js.map +1 -0
  153. package/incremental/handlers/notImplemented.d.ts +9 -0
  154. package/incremental/handlers/notImplemented.js +15 -0
  155. package/incremental/handlers/notImplemented.js.map +1 -0
  156. package/incremental/index.d.ts +4 -0
  157. package/incremental/index.js +3 -0
  158. package/incremental/index.js.map +1 -0
  159. package/incremental/types.d.ts +24 -0
  160. package/incremental/types.js +2 -0
  161. package/incremental/types.js.map +1 -0
  162. package/invariantErrorCodes.js +63 -49
  163. package/legacyEntryPoints/incremental/incremental.cjs +1 -0
  164. package/legacyEntryPoints/incremental/incremental.d.cts +1 -0
  165. package/legacyEntryPoints/incremental/index.d.ts +1 -0
  166. package/legacyEntryPoints/incremental/index.js +1 -0
  167. package/link/context/index.d.ts +8 -1
  168. package/link/context/index.js +34 -25
  169. package/link/context/index.js.map +1 -1
  170. package/link/core/types.d.ts +4 -32
  171. package/link/error/index.d.ts +15 -14
  172. package/link/error/index.js +68 -65
  173. package/link/error/index.js.map +1 -1
  174. package/link/http/BaseHttpLink.js +1 -7
  175. package/link/http/BaseHttpLink.js.map +1 -1
  176. package/link/http/HttpLink.d.ts +4 -0
  177. package/link/http/HttpLink.js +4 -0
  178. package/link/http/HttpLink.js.map +1 -1
  179. package/link/http/parseAndCheckHttpResponse.js +45 -57
  180. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  181. package/link/index.d.ts +1 -1
  182. package/link/index.js.map +1 -1
  183. package/link/persisted-queries/index.d.ts +19 -19
  184. package/link/persisted-queries/index.js +156 -141
  185. package/link/persisted-queries/index.js.map +1 -1
  186. package/link/remove-typename/index.d.ts +1 -1
  187. package/link/remove-typename/index.js +1 -1
  188. package/link/remove-typename/index.js.map +1 -1
  189. package/link/remove-typename/removeTypenameFromVariables.d.ts +8 -9
  190. package/link/remove-typename/removeTypenameFromVariables.js +32 -22
  191. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  192. package/local-state/LocalState.d.ts +3 -4
  193. package/local-state/LocalState.js.map +1 -1
  194. package/masking/types.d.ts +6 -5
  195. package/package.json +9 -2
  196. package/react/hooks/useApolloClient.js +14 -1
  197. package/react/hooks/useApolloClient.js.map +1 -1
  198. package/react/hooks/useBackgroundQuery.js +7 -6
  199. package/react/hooks/useBackgroundQuery.js.map +1 -1
  200. package/react/hooks/useFragment.js +12 -11
  201. package/react/hooks/useFragment.js.map +1 -1
  202. package/react/hooks/useLazyQuery.d.ts +2 -7
  203. package/react/hooks/useLazyQuery.js +15 -15
  204. package/react/hooks/useLazyQuery.js.map +1 -1
  205. package/react/hooks/useLoadableQuery.js +229 -69
  206. package/react/hooks/useLoadableQuery.js.map +1 -1
  207. package/react/hooks/useMutation.d.ts +2 -2
  208. package/react/hooks/useMutation.js +191 -81
  209. package/react/hooks/useMutation.js.map +1 -1
  210. package/react/hooks/useQuery.d.ts +3 -8
  211. package/react/hooks/useQuery.js +243 -70
  212. package/react/hooks/useQuery.js.map +1 -1
  213. package/react/hooks/useQueryRefHandlers.js +64 -23
  214. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  215. package/react/hooks/useReadQuery.js +3 -2
  216. package/react/hooks/useReadQuery.js.map +1 -1
  217. package/react/hooks/useSubscription.js +4 -4
  218. package/react/hooks/useSubscription.js.map +1 -1
  219. package/react/hooks/useSuspenseFragment.js +1 -0
  220. package/react/hooks/useSuspenseFragment.js.map +1 -1
  221. package/react/hooks/useSuspenseQuery.js +59 -33
  222. package/react/hooks/useSuspenseQuery.js.map +1 -1
  223. package/react/internal/cache/QueryReference.d.ts +2 -3
  224. package/react/internal/cache/QueryReference.js +4 -4
  225. package/react/internal/cache/QueryReference.js.map +1 -1
  226. package/react/internal/types.d.ts +2 -7
  227. package/utilities/graphql/isFormattedExecutionResult.d.ts +3 -0
  228. package/utilities/graphql/isFormattedExecutionResult.js +6 -0
  229. package/utilities/graphql/isFormattedExecutionResult.js.map +1 -0
  230. package/utilities/index.d.ts +1 -0
  231. package/utilities/index.js +1 -0
  232. package/utilities/index.js.map +1 -1
  233. package/utilities/internal/getGraphQLErrorsFromResult.d.ts +4 -2
  234. package/utilities/internal/getGraphQLErrorsFromResult.js +1 -12
  235. package/utilities/internal/getGraphQLErrorsFromResult.js.map +1 -1
  236. package/utilities/internal/graphQLResultHasError.d.ts +2 -2
  237. package/utilities/internal/graphQLResultHasError.js +1 -4
  238. package/utilities/internal/graphQLResultHasError.js.map +1 -1
  239. package/utilities/internal/index.d.ts +0 -4
  240. package/utilities/internal/index.js +0 -4
  241. package/utilities/internal/index.js.map +1 -1
  242. package/version.d.ts +1 -0
  243. package/version.js +2 -1
  244. package/version.js.map +1 -1
  245. package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs +0 -12
  246. package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs.map +0 -1
  247. package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.d.cts +0 -8
  248. package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs +0 -12
  249. package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs.map +0 -1
  250. package/__cjs/utilities/internal/isExecutionPatchIninitialResult.d.cts +0 -8
  251. package/__cjs/utilities/internal/isExecutionPatchResult.cjs +0 -15
  252. package/__cjs/utilities/internal/isExecutionPatchResult.cjs.map +0 -1
  253. package/__cjs/utilities/internal/isExecutionPatchResult.d.cts +0 -8
  254. package/__cjs/utilities/internal/mergeIncrementalData.cjs +0 -30
  255. package/__cjs/utilities/internal/mergeIncrementalData.cjs.map +0 -1
  256. package/__cjs/utilities/internal/mergeIncrementalData.d.cts +0 -8
  257. package/utilities/internal/isExecutionPatchIncrementalResult.d.ts +0 -8
  258. package/utilities/internal/isExecutionPatchIncrementalResult.js +0 -9
  259. package/utilities/internal/isExecutionPatchIncrementalResult.js.map +0 -1
  260. package/utilities/internal/isExecutionPatchIninitialResult.d.ts +0 -8
  261. package/utilities/internal/isExecutionPatchIninitialResult.js +0 -9
  262. package/utilities/internal/isExecutionPatchIninitialResult.js.map +0 -1
  263. package/utilities/internal/isExecutionPatchResult.d.ts +0 -8
  264. package/utilities/internal/isExecutionPatchResult.js +0 -12
  265. package/utilities/internal/isExecutionPatchResult.js.map +0 -1
  266. package/utilities/internal/mergeIncrementalData.d.ts +0 -8
  267. package/utilities/internal/mergeIncrementalData.js +0 -27
  268. package/utilities/internal/mergeIncrementalData.js.map +0 -1
@@ -33,6 +33,7 @@ class QueryManager {
33
33
  ssrMode;
34
34
  defaultContext;
35
35
  dataMasking;
36
+ incrementalHandler;
36
37
  localState;
37
38
  queryDeduplication;
38
39
  /**
@@ -69,6 +70,7 @@ class QueryManager {
69
70
  this.assumeImmutableResults = options.assumeImmutableResults;
70
71
  this.dataMasking = options.dataMasking;
71
72
  this.localState = options.localState;
73
+ this.incrementalHandler = options.incrementalHandler;
72
74
  const documentTransform = options.documentTransform;
73
75
  this.documentTransform =
74
76
  documentTransform ?
@@ -97,7 +99,7 @@ class QueryManager {
97
99
  */
98
100
  stop() {
99
101
  this.obsQueries.forEach((oq) => oq.stop());
100
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(83));
102
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(85));
101
103
  }
102
104
  cancelPendingFetches(error) {
103
105
  this.fetchCancelFns.forEach((cancel) => cancel(error));
@@ -112,7 +114,7 @@ class QueryManager {
112
114
  if (environment_1.__DEV__) {
113
115
  (0, invariant_1.invariant)(
114
116
  this.localState,
115
- 84,
117
+ 86,
116
118
  (0, internal_1.getOperationName)(mutation, "(anonymous)")
117
119
  );
118
120
  }
@@ -151,21 +153,7 @@ class QueryManager {
151
153
  optimisticResponse: isOptimistic ? optimisticResponse : void 0,
152
154
  }, variables, {}, false)
153
155
  .observable.pipe(validateDidEmitValue(), (0, rxjs_2.mergeMap)((result) => {
154
- const hasErrors = (0, internal_1.graphQLResultHasError)(result);
155
- if (hasErrors && errorPolicy === "none") {
156
- throw new errors_1.CombinedGraphQLErrors(result);
157
- }
158
- if (mutationStoreValue) {
159
- mutationStoreValue.loading = false;
160
- mutationStoreValue.error = null;
161
- }
162
156
  const storeResult = { ...result };
163
- if (typeof refetchQueries === "function") {
164
- refetchQueries = refetchQueries(storeResult);
165
- }
166
- if (errorPolicy === "ignore" && hasErrors) {
167
- delete storeResult.errors;
168
- }
169
157
  return (0, rxjs_2.from)(queryInfo.markMutationResult(storeResult, {
170
158
  document: mutation,
171
159
  variables,
@@ -182,6 +170,17 @@ class QueryManager {
182
170
  onQueryUpdated,
183
171
  keepRootFields,
184
172
  }));
173
+ }))
174
+ .pipe((0, rxjs_2.map)((storeResult) => {
175
+ const hasErrors = (0, internal_1.graphQLResultHasError)(storeResult);
176
+ if (hasErrors && errorPolicy === "none") {
177
+ throw new errors_1.CombinedGraphQLErrors(storeResult);
178
+ }
179
+ if (mutationStoreValue) {
180
+ mutationStoreValue.loading = false;
181
+ mutationStoreValue.error = null;
182
+ }
183
+ return storeResult;
185
184
  }))
186
185
  .subscribe({
187
186
  next: (storeResult) => {
@@ -191,7 +190,7 @@ class QueryManager {
191
190
  // we resolve with a SingleExecutionResult or after the final
192
191
  // ExecutionPatchResult has arrived and we have assembled the
193
192
  // multipart response into a single result.
194
- if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
193
+ if (!queryInfo.hasNext) {
195
194
  const result = {
196
195
  data: this.maskOperation({
197
196
  document: mutation,
@@ -203,7 +202,7 @@ class QueryManager {
203
202
  if ((0, internal_1.graphQLResultHasError)(storeResult)) {
204
203
  result.error = new errors_1.CombinedGraphQLErrors(storeResult);
205
204
  }
206
- if (storeResult.extensions) {
205
+ if (Object.keys(storeResult.extensions || {}).length) {
207
206
  result.extensions = storeResult.extensions;
208
207
  }
209
208
  resolve(result);
@@ -268,6 +267,7 @@ class QueryManager {
268
267
  hasClientExports: (0, internal_1.hasDirectives)(["client", "export"], document, true),
269
268
  hasForcedResolvers: (0, internal_1.hasForcedResolvers)(document),
270
269
  hasNonreactiveDirective: (0, internal_1.hasDirectives)(["nonreactive"], document),
270
+ hasIncrementalDirective: (0, internal_1.hasDirectives)(["defer"], document),
271
271
  nonReactiveQuery: addNonReactiveToNamedFragments(document),
272
272
  clientQuery: (0, internal_1.hasDirectives)(["client"], document) ? document : null,
273
273
  serverQuery: (0, internal_1.removeDirectivesFromDocument)([
@@ -353,7 +353,7 @@ class QueryManager {
353
353
  // depend on values that previously existed in the data portion of the
354
354
  // store. So, we cancel the promises and observers that we have issued
355
355
  // so far and not yet resolved (in the case of queries).
356
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(85));
356
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(87));
357
357
  this.obsQueries.forEach((observableQuery) => {
358
358
  // Set loading to true so listeners don't trigger unless they want
359
359
  // results with partial data.
@@ -423,10 +423,10 @@ class QueryManager {
423
423
  if (!included) {
424
424
  const queryName = queryNames.get(nameOrQueryString);
425
425
  if (queryName) {
426
- __DEV__ && invariant_1.invariant.warn(86, queryName);
426
+ __DEV__ && invariant_1.invariant.warn(88, queryName);
427
427
  }
428
428
  else {
429
- __DEV__ && invariant_1.invariant.warn(87);
429
+ __DEV__ && invariant_1.invariant.warn(89);
430
430
  }
431
431
  }
432
432
  });
@@ -437,8 +437,8 @@ class QueryManager {
437
437
  const observableQueryPromises = [];
438
438
  this.getObservableQueries(includeStandby ? "all" : "active").forEach((observableQuery) => {
439
439
  const { fetchPolicy } = observableQuery.options;
440
- if (includeStandby ||
441
- (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
440
+ if ((includeStandby || fetchPolicy !== "standby") &&
441
+ fetchPolicy !== "cache-only") {
442
442
  observableQueryPromises.push(observableQuery.refetch());
443
443
  }
444
444
  });
@@ -455,7 +455,7 @@ class QueryManager {
455
455
  if (environment_1.__DEV__) {
456
456
  (0, invariant_1.invariant)(
457
457
  !this.getDocumentInfo(query).hasClientExports || this.localState,
458
- 88,
458
+ 90,
459
459
  (0, internal_1.getOperationName)(query, "(anonymous)")
460
460
  );
461
461
  }
@@ -523,81 +523,92 @@ class QueryManager {
523
523
  deduplication = context?.queryDeduplication ??
524
524
  this.queryDeduplication) {
525
525
  let entry = {};
526
- const { serverQuery, clientQuery, operationType } = this.getDocumentInfo(query);
526
+ const { serverQuery, clientQuery, operationType, hasIncrementalDirective } = this.getDocumentInfo(query);
527
527
  const operationName = (0, internal_1.getOperationName)(query);
528
528
  const executeContext = {
529
529
  client: this.client,
530
530
  };
531
531
  if (serverQuery) {
532
532
  const { inFlightLinkObservables, link } = this;
533
- const operation = {
534
- query: serverQuery,
535
- variables,
536
- operationName,
537
- context: {
538
- ...this.defaultContext,
539
- ...context,
540
- queryDeduplication: deduplication,
541
- },
542
- extensions,
543
- };
544
- context = operation.context;
545
- function withRestart(source) {
546
- return new rxjs_1.Observable((observer) => {
547
- function subscribe() {
548
- return source.subscribe({
549
- next: observer.next.bind(observer),
550
- complete: observer.complete.bind(observer),
551
- error: observer.error.bind(observer),
552
- });
553
- }
554
- let subscription = subscribe();
555
- entry.restart ||= () => {
556
- subscription.unsubscribe();
557
- subscription = subscribe();
558
- };
559
- return () => {
560
- subscription.unsubscribe();
561
- entry.restart = undefined;
562
- };
533
+ try {
534
+ const operation = this.incrementalHandler.prepareRequest({
535
+ query: serverQuery,
536
+ variables,
537
+ operationName,
538
+ context: {
539
+ ...this.defaultContext,
540
+ ...context,
541
+ queryDeduplication: deduplication,
542
+ },
543
+ extensions,
563
544
  });
564
- }
565
- if (deduplication) {
566
- const printedServerQuery = (0, utilities_1.print)(serverQuery);
567
- const varJson = (0, cache_1.canonicalStringify)(variables);
568
- entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
569
- if (!entry.observable) {
570
- entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart, (0, rxjs_2.finalize)(() => {
571
- if (inFlightLinkObservables.peek(printedServerQuery, varJson) ===
572
- entry) {
573
- inFlightLinkObservables.remove(printedServerQuery, varJson);
545
+ context = operation.context;
546
+ function withRestart(source) {
547
+ return new rxjs_1.Observable((observer) => {
548
+ function subscribe() {
549
+ return source.subscribe({
550
+ next: observer.next.bind(observer),
551
+ complete: observer.complete.bind(observer),
552
+ error: observer.error.bind(observer),
553
+ });
574
554
  }
575
- }),
576
- // We don't want to replay the last emitted value for
577
- // subscriptions and instead opt to wait to receive updates until
578
- // the subscription emits new values.
579
- operationType === graphql_1.OperationTypeNode.SUBSCRIPTION ?
580
- (0, rxjs_2.share)()
581
- : (0, rxjs_2.shareReplay)({ refCount: true }));
555
+ let subscription = subscribe();
556
+ entry.restart ||= () => {
557
+ subscription.unsubscribe();
558
+ subscription = subscribe();
559
+ };
560
+ return () => {
561
+ subscription.unsubscribe();
562
+ entry.restart = undefined;
563
+ };
564
+ });
565
+ }
566
+ if (deduplication) {
567
+ const printedServerQuery = (0, utilities_1.print)(serverQuery);
568
+ const varJson = (0, cache_1.canonicalStringify)(variables);
569
+ entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
570
+ if (!entry.observable) {
571
+ entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart, (0, rxjs_2.finalize)(() => {
572
+ if (inFlightLinkObservables.peek(printedServerQuery, varJson) ===
573
+ entry) {
574
+ inFlightLinkObservables.remove(printedServerQuery, varJson);
575
+ }
576
+ }),
577
+ // We don't want to replay the last emitted value for
578
+ // subscriptions and instead opt to wait to receive updates until
579
+ // the subscription emits new values.
580
+ operationType === graphql_1.OperationTypeNode.SUBSCRIPTION ?
581
+ (0, rxjs_2.share)()
582
+ : (0, rxjs_2.shareReplay)({ refCount: true }));
583
+ }
584
+ }
585
+ else {
586
+ entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart);
582
587
  }
583
588
  }
584
- else {
585
- entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart);
589
+ catch (error) {
590
+ entry.observable = (0, rxjs_1.throwError)(() => error);
586
591
  }
587
592
  }
588
593
  else {
589
594
  entry.observable = (0, rxjs_2.of)({ data: {} });
590
595
  }
591
596
  if (clientQuery) {
597
+ const { operation } = (0, internal_1.getOperationDefinition)(query);
592
598
  if (environment_1.__DEV__) {
593
- const { operation } = (0, internal_1.getOperationDefinition)(query);
594
599
  (0, invariant_1.invariant)(
595
600
  this.localState,
596
- 89,
601
+ 91,
597
602
  operation[0].toUpperCase() + operation.slice(1),
598
603
  operationName ?? "(anonymous)"
599
604
  );
600
605
  }
606
+ (0, invariant_1.invariant)(
607
+ !hasIncrementalDirective,
608
+ 92,
609
+ operation[0].toUpperCase() + operation.slice(1),
610
+ operationName ?? "(anonymous)"
611
+ );
601
612
  entry.observable = entry.observable.pipe((0, rxjs_2.mergeMap)((result) => {
602
613
  return (0, rxjs_2.from)(this.localState.execute({
603
614
  client: this.client,
@@ -624,30 +635,24 @@ class QueryManager {
624
635
  // missing fragment definitions (for example) before sending this document
625
636
  // through the link chain.
626
637
  const linkDocument = this.cache.transformForLink(options.query);
627
- return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe((0, rxjs_2.map)((result) => {
628
- const graphQLErrors = (0, internal_1.getGraphQLErrorsFromResult)(result);
629
- const hasErrors = graphQLErrors.length > 0;
630
- // If we interrupted this request by calling getResultsFromLink again
631
- // with the same QueryInfo object, we ignore the old results.
632
- if (requestId >= queryInfo.lastRequestId) {
633
- if (hasErrors && errorPolicy === "none") {
634
- queryInfo.resetLastWrite();
635
- observableQuery?.["resetNotifications"]();
636
- // Throwing here effectively calls observer.error.
637
- throw new errors_1.CombinedGraphQLErrors(result);
638
- }
639
- // Use linkDocument rather than queryInfo.document so the
640
- // operation/fragments used to write the result are the same as the
641
- // ones used to obtain it from the link.
642
- queryInfo.markQueryResult(result, {
643
- ...options,
644
- document: linkDocument,
645
- cacheWriteBehavior,
646
- });
638
+ return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe((0, rxjs_2.map)((incoming) => {
639
+ // Use linkDocument rather than queryInfo.document so the
640
+ // operation/fragments used to write the result are the same as the
641
+ // ones used to obtain it from the link.
642
+ const result = queryInfo.markQueryResult(incoming, {
643
+ ...options,
644
+ document: linkDocument,
645
+ cacheWriteBehavior,
646
+ });
647
+ const hasErrors = (0, internal_1.graphQLResultHasError)(result);
648
+ if (hasErrors && errorPolicy === "none") {
649
+ queryInfo.resetLastWrite();
650
+ observableQuery?.["resetNotifications"]();
651
+ throw new errors_1.CombinedGraphQLErrors(result);
647
652
  }
648
653
  const aqr = {
649
654
  data: result.data,
650
- ...((0, internal_1.isExecutionPatchResult)(result) && result.hasNext ?
655
+ ...(queryInfo.hasNext ?
651
656
  {
652
657
  loading: true,
653
658
  networkStatus: networkStatus_js_1.NetworkStatus.streaming,
@@ -665,15 +670,16 @@ class QueryManager {
665
670
  // want to ensure we properly set `data` if we're reporting on an old
666
671
  // result which will not be caught by the conditional above that ends up
667
672
  // throwing the markError result.
668
- if (hasErrors && errorPolicy === "none") {
669
- aqr.data = void 0;
670
- aqr.dataState = "empty";
671
- }
672
- if (hasErrors && errorPolicy !== "ignore") {
673
- aqr.error = new errors_1.CombinedGraphQLErrors(result);
674
- aqr.networkStatus = networkStatus_js_1.NetworkStatus.error;
675
- if (aqr.data) {
676
- aqr.dataState = "complete";
673
+ if (hasErrors) {
674
+ if (errorPolicy === "none") {
675
+ aqr.data = void 0;
676
+ aqr.dataState = "empty";
677
+ }
678
+ if (errorPolicy !== "ignore") {
679
+ aqr.error = new errors_1.CombinedGraphQLErrors(result);
680
+ if (aqr.dataState !== "streaming") {
681
+ aqr.networkStatus = networkStatus_js_1.NetworkStatus.error;
682
+ }
677
683
  }
678
684
  }
679
685
  return aqr;
@@ -768,7 +774,7 @@ class QueryManager {
768
774
  if (environment_1.__DEV__) {
769
775
  (0, invariant_1.invariant)(
770
776
  this.localState,
771
- 90,
777
+ 93,
772
778
  (0, internal_1.getOperationName)(normalized.query, "(anonymous)")
773
779
  );
774
780
  }
@@ -805,6 +811,9 @@ class QueryManager {
805
811
  const includedQueriesByOq = new Map();
806
812
  if (include) {
807
813
  this.getObservableQueries(include).forEach((oq) => {
814
+ if (oq.options.fetchPolicy === "cache-only") {
815
+ return;
816
+ }
808
817
  const current = oq.getCurrentResult();
809
818
  includedQueriesByOq.set(oq, {
810
819
  oq,
@@ -884,7 +893,8 @@ class QueryManager {
884
893
  // onQueryUpdated returns false.
885
894
  return result;
886
895
  }
887
- if (onQueryUpdated !== null) {
896
+ if (onQueryUpdated !== null &&
897
+ oq.options.fetchPolicy !== "cache-only") {
888
898
  // If we don't have an onQueryUpdated function, and onQueryUpdated
889
899
  // was not disabled by passing null, make sure this query is
890
900
  // "included" like any other options.include-specified query.
@@ -940,7 +950,7 @@ class QueryManager {
940
950
  !this.noCacheWarningsByCause.has(cause)) {
941
951
  this.noCacheWarningsByCause.add(cause);
942
952
  __DEV__ && invariant_1.invariant.warn(
943
- 91,
953
+ 94,
944
954
  (0, internal_1.getOperationName)(document, `Unnamed ${operationType ?? "operation"}`)
945
955
  );
946
956
  }
@@ -1002,7 +1012,7 @@ class QueryManager {
1002
1012
  if (environment_1.__DEV__) {
1003
1013
  (0, invariant_1.invariant)(
1004
1014
  this.localState,
1005
- 92,
1015
+ 95,
1006
1016
  (0, internal_1.getOperationName)(query, "(anonymous)")
1007
1017
  );
1008
1018
  }
@@ -1096,7 +1106,7 @@ function validateDidEmitValue() {
1096
1106
  didEmitValue = true;
1097
1107
  },
1098
1108
  complete() {
1099
- (0, invariant_1.invariant)(didEmitValue, 93);
1109
+ (0, invariant_1.invariant)(didEmitValue, 96);
1100
1110
  },
1101
1111
  });
1102
1112
  }