@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.
- package/CHANGELOG.md +47 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +19 -0
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +3 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +1 -0
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +14 -13
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +12 -0
- package/__cjs/core/ObservableQuery.cjs +6 -6
- package/__cjs/core/QueryManager.cjs +19 -17
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/invariantErrorCodes.cjs +72 -62
- package/__cjs/link/core/ApolloLink.cjs +3 -3
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/ws/index.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +28 -14
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/local-state/LocalState.d.cts +3 -2
- package/__cjs/react/hooks/useMutation.cjs +7 -1
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +13 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +19 -0
- package/cache/core/cache.js +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +1 -0
- package/cache/inmemory/inMemoryCache.js +3 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +12 -0
- package/core/ApolloClient.js +14 -13
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +6 -6
- package/core/QueryManager.js +19 -17
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.js +1 -1
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/invariantErrorCodes.js +72 -62
- package/link/core/ApolloLink.js +3 -3
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/ws/index.js +1 -1
- package/local-state/LocalState.d.ts +3 -2
- package/local-state/LocalState.js +28 -14
- package/local-state/LocalState.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useMutation.d.ts +13 -1
- package/react/hooks/useMutation.js +7 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +13 -1
- package/react/hooks-compiled/useMutation.js +5 -1
- package/react/hooks-compiled/useMutation.js.map +1 -1
- 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 =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
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(
|
|
346
|
+
__DEV__ && invariant.warn(52, resolverName);
|
|
333
347
|
}
|
|
334
348
|
else if (onlyRunForcedResolvers) {
|
|
335
|
-
__DEV__ && invariant.warn(
|
|
349
|
+
__DEV__ && invariant.warn(53, resolverName);
|
|
336
350
|
}
|
|
337
351
|
else {
|
|
338
|
-
__DEV__ && invariant.warn(
|
|
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(
|
|
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,
|
|
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,
|
|
534
|
+
invariant(cache.fragmentMatches, 57);
|
|
521
535
|
}
|
|
522
536
|
function getCacheResultAtPath(diff, path) {
|
|
523
537
|
if (diff.result === null) {
|