@apollo/client 4.1.0-alpha.0 → 4.1.0-alpha.2

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 (75) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +19 -0
  5. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  6. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/inMemoryCache.cjs +3 -0
  8. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/inMemoryCache.d.cts +1 -0
  10. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  11. package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  12. package/__cjs/cache/inmemory/policies.cjs +4 -4
  13. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  14. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  15. package/__cjs/core/ApolloClient.cjs +14 -13
  16. package/__cjs/core/ApolloClient.cjs.map +1 -1
  17. package/__cjs/core/ApolloClient.d.cts +12 -0
  18. package/__cjs/core/ObservableQuery.cjs +6 -6
  19. package/__cjs/core/QueryManager.cjs +19 -17
  20. package/__cjs/core/QueryManager.cjs.map +1 -1
  21. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +1 -1
  22. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  23. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
  24. package/__cjs/invariantErrorCodes.cjs +72 -62
  25. package/__cjs/link/core/ApolloLink.cjs +3 -3
  26. package/__cjs/link/http/checkFetcher.cjs +1 -1
  27. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  28. package/__cjs/link/persisted-queries/index.cjs +2 -2
  29. package/__cjs/link/ws/index.cjs +1 -1
  30. package/__cjs/local-state/LocalState.cjs +28 -14
  31. package/__cjs/local-state/LocalState.cjs.map +1 -1
  32. package/__cjs/local-state/LocalState.d.cts +3 -2
  33. package/__cjs/react/hooks/useMutation.cjs +7 -1
  34. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  35. package/__cjs/react/hooks/useMutation.d.cts +13 -1
  36. package/__cjs/version.cjs +1 -1
  37. package/cache/core/cache.d.ts +19 -0
  38. package/cache/core/cache.js +1 -1
  39. package/cache/core/cache.js.map +1 -1
  40. package/cache/inmemory/entityStore.js +3 -3
  41. package/cache/inmemory/entityStore.js.map +1 -1
  42. package/cache/inmemory/inMemoryCache.d.ts +1 -0
  43. package/cache/inmemory/inMemoryCache.js +3 -0
  44. package/cache/inmemory/inMemoryCache.js.map +1 -1
  45. package/cache/inmemory/key-extractor.js +1 -1
  46. package/cache/inmemory/key-extractor.js.map +1 -1
  47. package/cache/inmemory/policies.js +4 -4
  48. package/cache/inmemory/readFromStore.js +2 -2
  49. package/cache/inmemory/writeToStore.js +4 -4
  50. package/core/ApolloClient.d.ts +12 -0
  51. package/core/ApolloClient.js +14 -13
  52. package/core/ApolloClient.js.map +1 -1
  53. package/core/ObservableQuery.js +6 -6
  54. package/core/QueryManager.js +19 -17
  55. package/core/QueryManager.js.map +1 -1
  56. package/incremental/handlers/graphql17Alpha9.js +1 -1
  57. package/incremental/handlers/notImplemented.js +1 -1
  58. package/incremental/handlers/notImplemented.js.map +1 -1
  59. package/invariantErrorCodes.js +72 -62
  60. package/link/core/ApolloLink.js +3 -3
  61. package/link/http/checkFetcher.js +1 -1
  62. package/link/http/parseAndCheckHttpResponse.js +1 -1
  63. package/link/persisted-queries/index.js +2 -2
  64. package/link/ws/index.js +1 -1
  65. package/local-state/LocalState.d.ts +3 -2
  66. package/local-state/LocalState.js +28 -14
  67. package/local-state/LocalState.js.map +1 -1
  68. package/package.json +1 -1
  69. package/react/hooks/useMutation.d.ts +13 -1
  70. package/react/hooks/useMutation.js +7 -1
  71. package/react/hooks/useMutation.js.map +1 -1
  72. package/react/hooks-compiled/useMutation.d.ts +13 -1
  73. package/react/hooks-compiled/useMutation.js +5 -1
  74. package/react/hooks-compiled/useMutation.js.map +1 -1
  75. package/version.js +1 -1
@@ -64,7 +64,7 @@ export class LocalState {
64
64
  addResolvers(resolvers) {
65
65
  this.resolvers = mergeDeep(this.resolvers, resolvers);
66
66
  }
67
- async execute({ document, client, context, remoteResult, variables = {}, onlyRunForcedResolvers = false, returnPartialData = false, }) {
67
+ async execute({ document, client, context, remoteResult, variables = {}, onlyRunForcedResolvers = false, returnPartialData = false, fetchPolicy, }) {
68
68
  if (__DEV__) {
69
69
  invariant(hasDirectives(["client"], document), 47);
70
70
  validateCacheImplementation(client.cache);
@@ -78,12 +78,14 @@ export class LocalState {
78
78
  }
79
79
  const { selectionsToResolve, exportedVariableDefs, operationDefinition, fragmentMap, } = this.collectQueryDetail(document);
80
80
  const rootValue = remoteResult ? remoteResult.data : {};
81
- const diff = client.cache.diff({
82
- query: toQueryOperation(document),
83
- variables,
84
- returnPartialData: true,
85
- optimistic: false,
86
- });
81
+ const diff = fetchPolicy === "no-cache" ?
82
+ { result: null, complete: false }
83
+ : client.cache.diff({
84
+ query: toQueryOperation(document),
85
+ variables,
86
+ returnPartialData: true,
87
+ optimistic: false,
88
+ });
87
89
  const requestContext = { ...client.defaultContext, ...context };
88
90
  const execContext = {
89
91
  client,
@@ -105,6 +107,7 @@ export class LocalState {
105
107
  exportedVariableDefs,
106
108
  diff,
107
109
  returnPartialData,
110
+ fetchPolicy,
108
111
  };
109
112
  const localResult = await this.resolveSelectionSet(operationDefinition.selectionSet, false, rootValue, execContext, []);
110
113
  const errors = (remoteResult?.errors ?? []).concat(execContext.errors);
@@ -241,7 +244,8 @@ export class LocalState {
241
244
  return this.resolveSelectionSet(field.selectionSet, false, result, execContext, path);
242
245
  }
243
246
  async resolveClientField(field, isClientFieldDescendant, rootValue, execContext, parentSelectionSet, path) {
244
- const { client, diff, variables, operationDefinition, phase, returnPartialData, onlyRunForcedResolvers, } = execContext;
247
+ const { client, diff, variables, operationDefinition, phase, onlyRunForcedResolvers, fetchPolicy, } = execContext;
248
+ let { returnPartialData } = execContext;
245
249
  const isRootField = parentSelectionSet === operationDefinition.selectionSet;
246
250
  const fieldName = field.name.value;
247
251
  const typename = isRootField ?
@@ -263,7 +267,17 @@ export class LocalState {
263
267
  if (fieldFromCache !== undefined) {
264
268
  return fieldFromCache;
265
269
  }
270
+ if (client.cache.resolvesClientField?.(typename, fieldName)) {
271
+ if (fetchPolicy === "no-cache") {
272
+ __DEV__ && invariant.warn(50, resolverName);
273
+ return null;
274
+ }
275
+ // assume the cache will handle returning the correct value
276
+ returnPartialData = true;
277
+ return;
278
+ }
266
279
  if (!returnPartialData) {
280
+ __DEV__ && invariant.warn(51, resolverName);
267
281
  return null;
268
282
  }
269
283
  });
@@ -329,13 +343,13 @@ export class LocalState {
329
343
  if (result === undefined && !returnPartialData) {
330
344
  if (__DEV__ && phase === "resolve") {
331
345
  if (resolver && !onlyRunForcedResolvers) {
332
- __DEV__ && invariant.warn(50, resolverName);
346
+ __DEV__ && invariant.warn(52, resolverName);
333
347
  }
334
348
  else if (onlyRunForcedResolvers) {
335
- __DEV__ && invariant.warn(51, resolverName);
349
+ __DEV__ && invariant.warn(53, resolverName);
336
350
  }
337
351
  else {
338
- __DEV__ && invariant.warn(52, fieldName, rootValue);
352
+ __DEV__ && invariant.warn(54, fieldName, rootValue);
339
353
  }
340
354
  }
341
355
  result = null;
@@ -347,7 +361,7 @@ export class LocalState {
347
361
  return this.resolveSubSelectedArray(field, true, result, execContext, path);
348
362
  }
349
363
  if (phase === "resolve" && !result.__typename) {
350
- this.addError(newInvariantError(53, result, resolverName), path, execContext, { resolver: resolverName });
364
+ this.addError(newInvariantError(55, result, resolverName), path, execContext, { resolver: resolverName });
351
365
  return null;
352
366
  }
353
367
  return this.resolveSelectionSet(field.selectionSet, true, result, execContext, path);
@@ -458,7 +472,7 @@ export class LocalState {
458
472
  },
459
473
  FragmentSpread(spread, _, __, ___, ancestors) {
460
474
  const fragment = fragmentMap[spread.name.value];
461
- invariant(fragment, 54, spread.name.value);
475
+ invariant(fragment, 56, spread.name.value);
462
476
  const { selectionsToResolve: fragmentSelections } = traverse(fragment);
463
477
  if (fragmentSelections.size > 0) {
464
478
  // Fragment for this spread contains @client directive (either directly or transitively)
@@ -517,7 +531,7 @@ function getExportedVariableName(directive) {
517
531
  }
518
532
  }
519
533
  function validateCacheImplementation(cache) {
520
- invariant(cache.fragmentMatches, 55);
534
+ invariant(cache.fragmentMatches, 57);
521
535
  }
522
536
  function getCacheResultAtPath(diff, path) {
523
537
  if (diff.result === null) {