@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
@@ -1,6 +1,6 @@
1
1
  import { Trie } from "@wry/trie";
2
2
  import { BREAK, Kind, OperationTypeNode, visit } from "graphql";
3
- import { Observable } from "rxjs";
3
+ import { Observable, throwError } from "rxjs";
4
4
  import { catchError, concat, EMPTY, filter, finalize, from, lastValueFrom, map, materialize, mergeMap, of, share, shareReplay, Subject, tap, } from "rxjs";
5
5
  import { canonicalStringify } from "@apollo/client/cache";
6
6
  import { CombinedGraphQLErrors, graphQLResultHasProtocolErrors, registerLinkError, toErrorLike, } from "@apollo/client/errors";
@@ -9,7 +9,7 @@ import { execute } from "@apollo/client/link";
9
9
  import { maskFragment, maskOperation } from "@apollo/client/masking";
10
10
  import { cacheSizes, DocumentTransform, print } from "@apollo/client/utilities";
11
11
  import { __DEV__ } from "@apollo/client/utilities/environment";
12
- import { AutoCleanedWeakCache, checkDocument, filterMap, getDefaultValues, getGraphQLErrorsFromResult, getOperationDefinition, getOperationName, graphQLResultHasError, hasDirectives, hasForcedResolvers, isDocumentNode, isExecutionPatchResult, isNonNullObject, makeUniqueId, removeDirectivesFromDocument, toQueryResult, } from "@apollo/client/utilities/internal";
12
+ import { AutoCleanedWeakCache, checkDocument, filterMap, getDefaultValues, getOperationDefinition, getOperationName, graphQLResultHasError, hasDirectives, hasForcedResolvers, isDocumentNode, isNonNullObject, makeUniqueId, removeDirectivesFromDocument, toQueryResult, } from "@apollo/client/utilities/internal";
13
13
  import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
14
14
  import { isNetworkRequestInFlight, NetworkStatus } from "./networkStatus.js";
15
15
  import { logMissingFieldErrors, ObservableQuery } from "./ObservableQuery.js";
@@ -26,6 +26,7 @@ export class QueryManager {
26
26
  ssrMode;
27
27
  defaultContext;
28
28
  dataMasking;
29
+ incrementalHandler;
29
30
  localState;
30
31
  queryDeduplication;
31
32
  /**
@@ -62,6 +63,7 @@ export class QueryManager {
62
63
  this.assumeImmutableResults = options.assumeImmutableResults;
63
64
  this.dataMasking = options.dataMasking;
64
65
  this.localState = options.localState;
66
+ this.incrementalHandler = options.incrementalHandler;
65
67
  const documentTransform = options.documentTransform;
66
68
  this.documentTransform =
67
69
  documentTransform ?
@@ -90,7 +92,7 @@ export class QueryManager {
90
92
  */
91
93
  stop() {
92
94
  this.obsQueries.forEach((oq) => oq.stop());
93
- this.cancelPendingFetches(newInvariantError(83));
95
+ this.cancelPendingFetches(newInvariantError(85));
94
96
  }
95
97
  cancelPendingFetches(error) {
96
98
  this.fetchCancelFns.forEach((cancel) => cancel(error));
@@ -103,7 +105,7 @@ export class QueryManager {
103
105
  variables = this.getVariables(mutation, variables);
104
106
  if (hasClientExports) {
105
107
  if (__DEV__) {
106
- invariant(this.localState, 84, getOperationName(mutation, "(anonymous)"));
108
+ invariant(this.localState, 86, getOperationName(mutation, "(anonymous)"));
107
109
  }
108
110
  variables = await this.localState.getExportedVariables({
109
111
  client: this.client,
@@ -140,21 +142,7 @@ export class QueryManager {
140
142
  optimisticResponse: isOptimistic ? optimisticResponse : void 0,
141
143
  }, variables, {}, false)
142
144
  .observable.pipe(validateDidEmitValue(), mergeMap((result) => {
143
- const hasErrors = graphQLResultHasError(result);
144
- if (hasErrors && errorPolicy === "none") {
145
- throw new CombinedGraphQLErrors(result);
146
- }
147
- if (mutationStoreValue) {
148
- mutationStoreValue.loading = false;
149
- mutationStoreValue.error = null;
150
- }
151
145
  const storeResult = { ...result };
152
- if (typeof refetchQueries === "function") {
153
- refetchQueries = refetchQueries(storeResult);
154
- }
155
- if (errorPolicy === "ignore" && hasErrors) {
156
- delete storeResult.errors;
157
- }
158
146
  return from(queryInfo.markMutationResult(storeResult, {
159
147
  document: mutation,
160
148
  variables,
@@ -171,6 +159,17 @@ export class QueryManager {
171
159
  onQueryUpdated,
172
160
  keepRootFields,
173
161
  }));
162
+ }))
163
+ .pipe(map((storeResult) => {
164
+ const hasErrors = graphQLResultHasError(storeResult);
165
+ if (hasErrors && errorPolicy === "none") {
166
+ throw new CombinedGraphQLErrors(storeResult);
167
+ }
168
+ if (mutationStoreValue) {
169
+ mutationStoreValue.loading = false;
170
+ mutationStoreValue.error = null;
171
+ }
172
+ return storeResult;
174
173
  }))
175
174
  .subscribe({
176
175
  next: (storeResult) => {
@@ -180,7 +179,7 @@ export class QueryManager {
180
179
  // we resolve with a SingleExecutionResult or after the final
181
180
  // ExecutionPatchResult has arrived and we have assembled the
182
181
  // multipart response into a single result.
183
- if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
182
+ if (!queryInfo.hasNext) {
184
183
  const result = {
185
184
  data: this.maskOperation({
186
185
  document: mutation,
@@ -192,7 +191,7 @@ export class QueryManager {
192
191
  if (graphQLResultHasError(storeResult)) {
193
192
  result.error = new CombinedGraphQLErrors(storeResult);
194
193
  }
195
- if (storeResult.extensions) {
194
+ if (Object.keys(storeResult.extensions || {}).length) {
196
195
  result.extensions = storeResult.extensions;
197
196
  }
198
197
  resolve(result);
@@ -257,6 +256,7 @@ export class QueryManager {
257
256
  hasClientExports: hasDirectives(["client", "export"], document, true),
258
257
  hasForcedResolvers: hasForcedResolvers(document),
259
258
  hasNonreactiveDirective: hasDirectives(["nonreactive"], document),
259
+ hasIncrementalDirective: hasDirectives(["defer"], document),
260
260
  nonReactiveQuery: addNonReactiveToNamedFragments(document),
261
261
  clientQuery: hasDirectives(["client"], document) ? document : null,
262
262
  serverQuery: removeDirectivesFromDocument([
@@ -342,7 +342,7 @@ export class QueryManager {
342
342
  // depend on values that previously existed in the data portion of the
343
343
  // store. So, we cancel the promises and observers that we have issued
344
344
  // so far and not yet resolved (in the case of queries).
345
- this.cancelPendingFetches(newInvariantError(85));
345
+ this.cancelPendingFetches(newInvariantError(87));
346
346
  this.obsQueries.forEach((observableQuery) => {
347
347
  // Set loading to true so listeners don't trigger unless they want
348
348
  // results with partial data.
@@ -412,10 +412,10 @@ export class QueryManager {
412
412
  if (!included) {
413
413
  const queryName = queryNames.get(nameOrQueryString);
414
414
  if (queryName) {
415
- __DEV__ && invariant.warn(86, queryName);
415
+ __DEV__ && invariant.warn(88, queryName);
416
416
  }
417
417
  else {
418
- __DEV__ && invariant.warn(87);
418
+ __DEV__ && invariant.warn(89);
419
419
  }
420
420
  }
421
421
  });
@@ -426,8 +426,8 @@ export class QueryManager {
426
426
  const observableQueryPromises = [];
427
427
  this.getObservableQueries(includeStandby ? "all" : "active").forEach((observableQuery) => {
428
428
  const { fetchPolicy } = observableQuery.options;
429
- if (includeStandby ||
430
- (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
429
+ if ((includeStandby || fetchPolicy !== "standby") &&
430
+ fetchPolicy !== "cache-only") {
431
431
  observableQueryPromises.push(observableQuery.refetch());
432
432
  }
433
433
  });
@@ -444,7 +444,7 @@ export class QueryManager {
444
444
  if (__DEV__) {
445
445
  invariant(
446
446
  !this.getDocumentInfo(query).hasClientExports || this.localState,
447
- 88,
447
+ 90,
448
448
  getOperationName(query, "(anonymous)")
449
449
  );
450
450
  }
@@ -512,81 +512,92 @@ export class QueryManager {
512
512
  deduplication = context?.queryDeduplication ??
513
513
  this.queryDeduplication) {
514
514
  let entry = {};
515
- const { serverQuery, clientQuery, operationType } = this.getDocumentInfo(query);
515
+ const { serverQuery, clientQuery, operationType, hasIncrementalDirective } = this.getDocumentInfo(query);
516
516
  const operationName = getOperationName(query);
517
517
  const executeContext = {
518
518
  client: this.client,
519
519
  };
520
520
  if (serverQuery) {
521
521
  const { inFlightLinkObservables, link } = this;
522
- const operation = {
523
- query: serverQuery,
524
- variables,
525
- operationName,
526
- context: {
527
- ...this.defaultContext,
528
- ...context,
529
- queryDeduplication: deduplication,
530
- },
531
- extensions,
532
- };
533
- context = operation.context;
534
- function withRestart(source) {
535
- return new Observable((observer) => {
536
- function subscribe() {
537
- return source.subscribe({
538
- next: observer.next.bind(observer),
539
- complete: observer.complete.bind(observer),
540
- error: observer.error.bind(observer),
541
- });
542
- }
543
- let subscription = subscribe();
544
- entry.restart ||= () => {
545
- subscription.unsubscribe();
546
- subscription = subscribe();
547
- };
548
- return () => {
549
- subscription.unsubscribe();
550
- entry.restart = undefined;
551
- };
522
+ try {
523
+ const operation = this.incrementalHandler.prepareRequest({
524
+ query: serverQuery,
525
+ variables,
526
+ operationName,
527
+ context: {
528
+ ...this.defaultContext,
529
+ ...context,
530
+ queryDeduplication: deduplication,
531
+ },
532
+ extensions,
552
533
  });
553
- }
554
- if (deduplication) {
555
- const printedServerQuery = print(serverQuery);
556
- const varJson = canonicalStringify(variables);
557
- entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
558
- if (!entry.observable) {
559
- entry.observable = execute(link, operation, executeContext).pipe(withRestart, finalize(() => {
560
- if (inFlightLinkObservables.peek(printedServerQuery, varJson) ===
561
- entry) {
562
- inFlightLinkObservables.remove(printedServerQuery, varJson);
534
+ context = operation.context;
535
+ function withRestart(source) {
536
+ return new Observable((observer) => {
537
+ function subscribe() {
538
+ return source.subscribe({
539
+ next: observer.next.bind(observer),
540
+ complete: observer.complete.bind(observer),
541
+ error: observer.error.bind(observer),
542
+ });
563
543
  }
564
- }),
565
- // We don't want to replay the last emitted value for
566
- // subscriptions and instead opt to wait to receive updates until
567
- // the subscription emits new values.
568
- operationType === OperationTypeNode.SUBSCRIPTION ?
569
- share()
570
- : shareReplay({ refCount: true }));
544
+ let subscription = subscribe();
545
+ entry.restart ||= () => {
546
+ subscription.unsubscribe();
547
+ subscription = subscribe();
548
+ };
549
+ return () => {
550
+ subscription.unsubscribe();
551
+ entry.restart = undefined;
552
+ };
553
+ });
554
+ }
555
+ if (deduplication) {
556
+ const printedServerQuery = print(serverQuery);
557
+ const varJson = canonicalStringify(variables);
558
+ entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
559
+ if (!entry.observable) {
560
+ entry.observable = execute(link, operation, executeContext).pipe(withRestart, finalize(() => {
561
+ if (inFlightLinkObservables.peek(printedServerQuery, varJson) ===
562
+ entry) {
563
+ inFlightLinkObservables.remove(printedServerQuery, varJson);
564
+ }
565
+ }),
566
+ // We don't want to replay the last emitted value for
567
+ // subscriptions and instead opt to wait to receive updates until
568
+ // the subscription emits new values.
569
+ operationType === OperationTypeNode.SUBSCRIPTION ?
570
+ share()
571
+ : shareReplay({ refCount: true }));
572
+ }
573
+ }
574
+ else {
575
+ entry.observable = execute(link, operation, executeContext).pipe(withRestart);
571
576
  }
572
577
  }
573
- else {
574
- entry.observable = execute(link, operation, executeContext).pipe(withRestart);
578
+ catch (error) {
579
+ entry.observable = throwError(() => error);
575
580
  }
576
581
  }
577
582
  else {
578
583
  entry.observable = of({ data: {} });
579
584
  }
580
585
  if (clientQuery) {
586
+ const { operation } = getOperationDefinition(query);
581
587
  if (__DEV__) {
582
- const { operation } = getOperationDefinition(query);
583
588
  invariant(
584
589
  this.localState,
585
- 89,
590
+ 91,
586
591
  operation[0].toUpperCase() + operation.slice(1),
587
592
  operationName ?? "(anonymous)"
588
593
  );
589
594
  }
595
+ invariant(
596
+ !hasIncrementalDirective,
597
+ 92,
598
+ operation[0].toUpperCase() + operation.slice(1),
599
+ operationName ?? "(anonymous)"
600
+ );
590
601
  entry.observable = entry.observable.pipe(mergeMap((result) => {
591
602
  return from(this.localState.execute({
592
603
  client: this.client,
@@ -613,30 +624,24 @@ export class QueryManager {
613
624
  // missing fragment definitions (for example) before sending this document
614
625
  // through the link chain.
615
626
  const linkDocument = this.cache.transformForLink(options.query);
616
- return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe(map((result) => {
617
- const graphQLErrors = getGraphQLErrorsFromResult(result);
618
- const hasErrors = graphQLErrors.length > 0;
619
- // If we interrupted this request by calling getResultsFromLink again
620
- // with the same QueryInfo object, we ignore the old results.
621
- if (requestId >= queryInfo.lastRequestId) {
622
- if (hasErrors && errorPolicy === "none") {
623
- queryInfo.resetLastWrite();
624
- observableQuery?.["resetNotifications"]();
625
- // Throwing here effectively calls observer.error.
626
- throw new CombinedGraphQLErrors(result);
627
- }
628
- // Use linkDocument rather than queryInfo.document so the
629
- // operation/fragments used to write the result are the same as the
630
- // ones used to obtain it from the link.
631
- queryInfo.markQueryResult(result, {
632
- ...options,
633
- document: linkDocument,
634
- cacheWriteBehavior,
635
- });
627
+ return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe(map((incoming) => {
628
+ // Use linkDocument rather than queryInfo.document so the
629
+ // operation/fragments used to write the result are the same as the
630
+ // ones used to obtain it from the link.
631
+ const result = queryInfo.markQueryResult(incoming, {
632
+ ...options,
633
+ document: linkDocument,
634
+ cacheWriteBehavior,
635
+ });
636
+ const hasErrors = graphQLResultHasError(result);
637
+ if (hasErrors && errorPolicy === "none") {
638
+ queryInfo.resetLastWrite();
639
+ observableQuery?.["resetNotifications"]();
640
+ throw new CombinedGraphQLErrors(result);
636
641
  }
637
642
  const aqr = {
638
643
  data: result.data,
639
- ...(isExecutionPatchResult(result) && result.hasNext ?
644
+ ...(queryInfo.hasNext ?
640
645
  {
641
646
  loading: true,
642
647
  networkStatus: NetworkStatus.streaming,
@@ -654,15 +659,16 @@ export class QueryManager {
654
659
  // want to ensure we properly set `data` if we're reporting on an old
655
660
  // result which will not be caught by the conditional above that ends up
656
661
  // throwing the markError result.
657
- if (hasErrors && errorPolicy === "none") {
658
- aqr.data = void 0;
659
- aqr.dataState = "empty";
660
- }
661
- if (hasErrors && errorPolicy !== "ignore") {
662
- aqr.error = new CombinedGraphQLErrors(result);
663
- aqr.networkStatus = NetworkStatus.error;
664
- if (aqr.data) {
665
- aqr.dataState = "complete";
662
+ if (hasErrors) {
663
+ if (errorPolicy === "none") {
664
+ aqr.data = void 0;
665
+ aqr.dataState = "empty";
666
+ }
667
+ if (errorPolicy !== "ignore") {
668
+ aqr.error = new CombinedGraphQLErrors(result);
669
+ if (aqr.dataState !== "streaming") {
670
+ aqr.networkStatus = NetworkStatus.error;
671
+ }
666
672
  }
667
673
  }
668
674
  return aqr;
@@ -755,7 +761,7 @@ export class QueryManager {
755
761
  // we deprecated and removed LocalState.
756
762
  if (this.getDocumentInfo(normalized.query).hasClientExports) {
757
763
  if (__DEV__) {
758
- invariant(this.localState, 90, getOperationName(normalized.query, "(anonymous)"));
764
+ invariant(this.localState, 93, getOperationName(normalized.query, "(anonymous)"));
759
765
  }
760
766
  observable = from(this.localState.getExportedVariables({
761
767
  client: this.client,
@@ -790,6 +796,9 @@ export class QueryManager {
790
796
  const includedQueriesByOq = new Map();
791
797
  if (include) {
792
798
  this.getObservableQueries(include).forEach((oq) => {
799
+ if (oq.options.fetchPolicy === "cache-only") {
800
+ return;
801
+ }
793
802
  const current = oq.getCurrentResult();
794
803
  includedQueriesByOq.set(oq, {
795
804
  oq,
@@ -869,7 +878,8 @@ export class QueryManager {
869
878
  // onQueryUpdated returns false.
870
879
  return result;
871
880
  }
872
- if (onQueryUpdated !== null) {
881
+ if (onQueryUpdated !== null &&
882
+ oq.options.fetchPolicy !== "cache-only") {
873
883
  // If we don't have an onQueryUpdated function, and onQueryUpdated
874
884
  // was not disabled by passing null, make sure this query is
875
885
  // "included" like any other options.include-specified query.
@@ -924,7 +934,7 @@ export class QueryManager {
924
934
  !isFullyUnmaskedOperation(document) &&
925
935
  !this.noCacheWarningsByCause.has(cause)) {
926
936
  this.noCacheWarningsByCause.add(cause);
927
- __DEV__ && invariant.warn(91, getOperationName(document, `Unnamed ${operationType ?? "operation"}`));
937
+ __DEV__ && invariant.warn(94, getOperationName(document, `Unnamed ${operationType ?? "operation"}`));
928
938
  }
929
939
  }
930
940
  return (this.dataMasking ?
@@ -982,7 +992,7 @@ export class QueryManager {
982
992
  (diff.complete || returnPartialData) &&
983
993
  this.getDocumentInfo(query).hasForcedResolvers) {
984
994
  if (__DEV__) {
985
- invariant(this.localState, 92, getOperationName(query, "(anonymous)"));
995
+ invariant(this.localState, 95, getOperationName(query, "(anonymous)"));
986
996
  }
987
997
  onCacheHit();
988
998
  return from(this.localState.execute({
@@ -1073,7 +1083,7 @@ function validateDidEmitValue() {
1073
1083
  didEmitValue = true;
1074
1084
  },
1075
1085
  complete() {
1076
- invariant(didEmitValue, 93);
1086
+ invariant(didEmitValue, 96);
1077
1087
  },
1078
1088
  });
1079
1089
  }