@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
@@ -71,7 +71,7 @@ class LocalState {
71
71
  addResolvers(resolvers) {
72
72
  this.resolvers = (0, internal_1.mergeDeep)(this.resolvers, resolvers);
73
73
  }
74
- async execute({ document, client, context, remoteResult, variables = {}, onlyRunForcedResolvers = false, returnPartialData = false, }) {
74
+ async execute({ document, client, context, remoteResult, variables = {}, onlyRunForcedResolvers = false, returnPartialData = false, fetchPolicy, }) {
75
75
  if (environment_1.__DEV__) {
76
76
  (0, invariant_1.invariant)((0, internal_1.hasDirectives)(["client"], document), 47);
77
77
  validateCacheImplementation(client.cache);
@@ -85,12 +85,14 @@ class LocalState {
85
85
  }
86
86
  const { selectionsToResolve, exportedVariableDefs, operationDefinition, fragmentMap, } = this.collectQueryDetail(document);
87
87
  const rootValue = remoteResult ? remoteResult.data : {};
88
- const diff = client.cache.diff({
89
- query: toQueryOperation(document),
90
- variables,
91
- returnPartialData: true,
92
- optimistic: false,
93
- });
88
+ const diff = fetchPolicy === "no-cache" ?
89
+ { result: null, complete: false }
90
+ : client.cache.diff({
91
+ query: toQueryOperation(document),
92
+ variables,
93
+ returnPartialData: true,
94
+ optimistic: false,
95
+ });
94
96
  const requestContext = { ...client.defaultContext, ...context };
95
97
  const execContext = {
96
98
  client,
@@ -112,6 +114,7 @@ class LocalState {
112
114
  exportedVariableDefs,
113
115
  diff,
114
116
  returnPartialData,
117
+ fetchPolicy,
115
118
  };
116
119
  const localResult = await this.resolveSelectionSet(operationDefinition.selectionSet, false, rootValue, execContext, []);
117
120
  const errors = (remoteResult?.errors ?? []).concat(execContext.errors);
@@ -248,7 +251,8 @@ class LocalState {
248
251
  return this.resolveSelectionSet(field.selectionSet, false, result, execContext, path);
249
252
  }
250
253
  async resolveClientField(field, isClientFieldDescendant, rootValue, execContext, parentSelectionSet, path) {
251
- const { client, diff, variables, operationDefinition, phase, returnPartialData, onlyRunForcedResolvers, } = execContext;
254
+ const { client, diff, variables, operationDefinition, phase, onlyRunForcedResolvers, fetchPolicy, } = execContext;
255
+ let { returnPartialData } = execContext;
252
256
  const isRootField = parentSelectionSet === operationDefinition.selectionSet;
253
257
  const fieldName = field.name.value;
254
258
  const typename = isRootField ?
@@ -270,7 +274,17 @@ class LocalState {
270
274
  if (fieldFromCache !== undefined) {
271
275
  return fieldFromCache;
272
276
  }
277
+ if (client.cache.resolvesClientField?.(typename, fieldName)) {
278
+ if (fetchPolicy === "no-cache") {
279
+ __DEV__ && invariant_1.invariant.warn(50, resolverName);
280
+ return null;
281
+ }
282
+ // assume the cache will handle returning the correct value
283
+ returnPartialData = true;
284
+ return;
285
+ }
273
286
  if (!returnPartialData) {
287
+ __DEV__ && invariant_1.invariant.warn(51, resolverName);
274
288
  return null;
275
289
  }
276
290
  });
@@ -336,13 +350,13 @@ class LocalState {
336
350
  if (result === undefined && !returnPartialData) {
337
351
  if (environment_1.__DEV__ && phase === "resolve") {
338
352
  if (resolver && !onlyRunForcedResolvers) {
339
- __DEV__ && invariant_1.invariant.warn(50, resolverName);
353
+ __DEV__ && invariant_1.invariant.warn(52, resolverName);
340
354
  }
341
355
  else if (onlyRunForcedResolvers) {
342
- __DEV__ && invariant_1.invariant.warn(51, resolverName);
356
+ __DEV__ && invariant_1.invariant.warn(53, resolverName);
343
357
  }
344
358
  else {
345
- __DEV__ && invariant_1.invariant.warn(52, fieldName, rootValue);
359
+ __DEV__ && invariant_1.invariant.warn(54, fieldName, rootValue);
346
360
  }
347
361
  }
348
362
  result = null;
@@ -354,7 +368,7 @@ class LocalState {
354
368
  return this.resolveSubSelectedArray(field, true, result, execContext, path);
355
369
  }
356
370
  if (phase === "resolve" && !result.__typename) {
357
- this.addError((0, invariant_1.newInvariantError)(53, result, resolverName), path, execContext, { resolver: resolverName });
371
+ this.addError((0, invariant_1.newInvariantError)(55, result, resolverName), path, execContext, { resolver: resolverName });
358
372
  return null;
359
373
  }
360
374
  return this.resolveSelectionSet(field.selectionSet, true, result, execContext, path);
@@ -465,7 +479,7 @@ class LocalState {
465
479
  },
466
480
  FragmentSpread(spread, _, __, ___, ancestors) {
467
481
  const fragment = fragmentMap[spread.name.value];
468
- (0, invariant_1.invariant)(fragment, 54, spread.name.value);
482
+ (0, invariant_1.invariant)(fragment, 56, spread.name.value);
469
483
  const { selectionsToResolve: fragmentSelections } = traverse(fragment);
470
484
  if (fragmentSelections.size > 0) {
471
485
  // Fragment for this spread contains @client directive (either directly or transitively)
@@ -525,7 +539,7 @@ function getExportedVariableName(directive) {
525
539
  }
526
540
  }
527
541
  function validateCacheImplementation(cache) {
528
- (0, invariant_1.invariant)(cache.fragmentMatches, 55);
542
+ (0, invariant_1.invariant)(cache.fragmentMatches, 57);
529
543
  }
530
544
  function getCacheResultAtPath(diff, path) {
531
545
  if (diff.result === null) {