@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
@@ -191,13 +191,6 @@ class ObservableQuery {
191
191
  const fetchPolicy = this.queryManager.prioritizeCacheValues ?
192
192
  "cache-first"
193
193
  : initialFetchPolicy || this.options.fetchPolicy;
194
- const defaultResult = {
195
- data: undefined,
196
- dataState: "empty",
197
- loading: true,
198
- networkStatus: networkStatus_js_1.NetworkStatus.loading,
199
- partial: true,
200
- };
201
194
  const cacheResult = () => {
202
195
  const diff = this.getCacheDiff();
203
196
  // TODO: queryInfo.getDiff should handle this since cache.diff returns a
@@ -216,7 +209,13 @@ class ObservableQuery {
216
209
  });
217
210
  };
218
211
  switch (fetchPolicy) {
219
- case "cache-only":
212
+ case "cache-only": {
213
+ return {
214
+ ...cacheResult(),
215
+ loading: false,
216
+ networkStatus: networkStatus_js_1.NetworkStatus.ready,
217
+ };
218
+ }
220
219
  case "cache-first":
221
220
  return cacheResult();
222
221
  case "cache-and-network":
@@ -226,13 +225,9 @@ class ObservableQuery {
226
225
  networkStatus: networkStatus_js_1.NetworkStatus.loading,
227
226
  };
228
227
  case "standby":
229
- return {
230
- ...defaultResult,
231
- loading: false,
232
- networkStatus: networkStatus_js_1.NetworkStatus.ready,
233
- };
228
+ return empty;
234
229
  default:
235
- return defaultResult;
230
+ return uninitialized;
236
231
  }
237
232
  }
238
233
  resubscribeCache() {
@@ -335,6 +330,7 @@ class ObservableQuery {
335
330
  * the previous values of those variables will be used.
336
331
  */
337
332
  refetch(variables) {
333
+ const { fetchPolicy } = this.options;
338
334
  const reobserveOptions = {
339
335
  // Always disable polling for refetches.
340
336
  pollInterval: 0,
@@ -342,7 +338,6 @@ class ObservableQuery {
342
338
  // Unless the provided fetchPolicy always consults the network
343
339
  // (no-cache, network-only, or cache-and-network), override it with
344
340
  // network-only to force the refetch for this fetchQuery call.
345
- const { fetchPolicy } = this.options;
346
341
  if (fetchPolicy === "no-cache") {
347
342
  reobserveOptions.fetchPolicy = "no-cache";
348
343
  }
@@ -353,7 +348,7 @@ class ObservableQuery {
353
348
  const queryDef = (0, internal_1.getQueryDefinition)(this.query);
354
349
  const vars = queryDef.variableDefinitions;
355
350
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
356
- __DEV__ && invariant_1.invariant.warn(78, variables, queryDef.name?.value || queryDef);
351
+ __DEV__ && invariant_1.invariant.warn(79, variables, queryDef.name?.value || queryDef);
357
352
  }
358
353
  }
359
354
  if (variables && !(0, equality_1.equal)(this.variables, variables)) {
@@ -369,16 +364,21 @@ class ObservableQuery {
369
364
  /**
370
365
  * 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/).
371
366
  */
372
- fetchMore(fetchMoreOptions) {
367
+ fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
368
+ (0, invariant_1.invariant)(
369
+ this.options.fetchPolicy !== "cache-only",
370
+ 80,
371
+ (0, internal_1.getOperationName)(this.query, "(anonymous)")
372
+ );
373
373
  const combinedOptions = {
374
- ...(fetchMoreOptions.query ? fetchMoreOptions : ({
375
- ...this.options,
376
- query: this.options.query,
377
- ...fetchMoreOptions,
378
- variables: {
379
- ...this.variables,
380
- ...fetchMoreOptions.variables,
381
- },
374
+ ...(0, internal_1.compact)(this.options, { errorPolicy: "none" }, {
375
+ query,
376
+ context,
377
+ errorPolicy,
378
+ }),
379
+ variables: (query ? variables : ({
380
+ ...this.variables,
381
+ ...variables,
382
382
  })),
383
383
  // The fetchMore request goes immediately to the network and does
384
384
  // not automatically write its result to the cache (hence no-cache
@@ -395,14 +395,13 @@ class ObservableQuery {
395
395
  // as well as the document passed in `fetchMoreOptions` to ensure the cache
396
396
  // uses the most up-to-date document which may rely on runtime conditionals.
397
397
  this.lastQuery =
398
- fetchMoreOptions.query ?
398
+ query ?
399
399
  this.transformDocument(this.options.query)
400
400
  : combinedOptions.query;
401
401
  let wasUpdated = false;
402
- const updateQuery = fetchMoreOptions?.updateQuery;
403
402
  const isCached = this.options.fetchPolicy !== "no-cache";
404
403
  if (!isCached) {
405
- (0, invariant_1.invariant)(updateQuery, 79);
404
+ (0, invariant_1.invariant)(updateQuery, 81);
406
405
  }
407
406
  const { finalize, pushNotification } = this.pushOperation(networkStatus_js_1.NetworkStatus.fetchMore);
408
407
  pushNotification({
@@ -426,7 +425,6 @@ class ObservableQuery {
426
425
  // fetchMore cache results back to this ObservableQuery.
427
426
  this.queryManager.cache.batch({
428
427
  update: (cache) => {
429
- const { updateQuery } = fetchMoreOptions;
430
428
  if (updateQuery) {
431
429
  cache.updateQuery({
432
430
  query: this.query,
@@ -535,7 +533,7 @@ class ObservableQuery {
535
533
  onError(error);
536
534
  }
537
535
  else {
538
- __DEV__ && invariant_1.invariant.error(80, error);
536
+ __DEV__ && invariant_1.invariant.error(82, error);
539
537
  }
540
538
  return;
541
539
  }
@@ -559,9 +557,10 @@ class ObservableQuery {
559
557
  *
560
558
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
561
559
  */
562
- silentSetOptions(newOptions) {
560
+ applyOptions(newOptions) {
563
561
  const mergedOptions = (0, internal_1.compact)(this.options, newOptions || {});
564
562
  assign(this.options, mergedOptions);
563
+ this.updatePolling();
565
564
  }
566
565
  /**
567
566
  * Update the variables of this observable query, and fetch the new results
@@ -768,20 +767,28 @@ class ObservableQuery {
768
767
  return { fromLink, subscription, observable };
769
768
  }
770
769
  // Turns polling on or off based on this.options.pollInterval.
770
+ didWarnCacheOnlyPolling = false;
771
771
  updatePolling() {
772
772
  // Avoid polling in SSR mode
773
773
  if (this.queryManager.ssrMode) {
774
774
  return;
775
775
  }
776
- const { pollingInfo, options: { pollInterval }, } = this;
777
- if (!pollInterval || !this.hasObservers()) {
776
+ const { pollingInfo, options: { fetchPolicy, pollInterval }, } = this;
777
+ if (!pollInterval || !this.hasObservers() || fetchPolicy === "cache-only") {
778
+ if (environment_1.__DEV__) {
779
+ if (!this.didWarnCacheOnlyPolling &&
780
+ pollInterval &&
781
+ fetchPolicy === "cache-only") {
782
+ __DEV__ && invariant_1.invariant.warn(83, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
783
+ this.didWarnCacheOnlyPolling = true;
784
+ }
785
+ }
778
786
  this.cancelPolling();
779
787
  return;
780
788
  }
781
- if (pollingInfo && pollingInfo.interval === pollInterval) {
789
+ if (pollingInfo?.interval === pollInterval) {
782
790
  return;
783
791
  }
784
- (0, invariant_1.invariant)(pollInterval, 81);
785
792
  const info = pollingInfo || (this.pollingInfo = {});
786
793
  info.interval = pollInterval;
787
794
  const maybeFetch = () => {
@@ -981,17 +988,14 @@ class ObservableQuery {
981
988
  return this.queryManager.transform(document);
982
989
  }
983
990
  maskResult(result) {
984
- return result && "data" in result ?
985
- {
986
- ...result,
987
- data: this.queryManager.maskOperation({
988
- document: this.query,
989
- data: result.data,
990
- fetchPolicy: this.options.fetchPolicy,
991
- cause: this,
992
- }),
993
- }
994
- : result;
991
+ const masked = this.queryManager.maskOperation({
992
+ document: this.query,
993
+ data: result.data,
994
+ fetchPolicy: this.options.fetchPolicy,
995
+ cause: this,
996
+ });
997
+ // Maintain object identity as much as possible
998
+ return masked === result.data ? result : { ...result, data: masked };
995
999
  }
996
1000
  dirty = false;
997
1001
  notifyTimeout;
@@ -1198,7 +1202,7 @@ class ObservableQuery {
1198
1202
  loading: false,
1199
1203
  }
1200
1204
  : notification.value;
1201
- if (result.error && result.dataState === "streaming") {
1205
+ if (notification.kind === "E" && result.dataState === "streaming") {
1202
1206
  result.dataState = "complete";
1203
1207
  }
1204
1208
  if (result.error) {
@@ -1268,7 +1272,7 @@ class ObservableQuery {
1268
1272
  exports.ObservableQuery = ObservableQuery;
1269
1273
  function logMissingFieldErrors(missing) {
1270
1274
  if (environment_1.__DEV__ && missing) {
1271
- __DEV__ && invariant_1.invariant.debug(82, missing);
1275
+ __DEV__ && invariant_1.invariant.debug(84, missing);
1272
1276
  }
1273
1277
  }
1274
1278
  function isEqualQuery(a, b) {