@apollo/client 4.3.0-alpha.4 → 4.3.0-alpha.6
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 +116 -0
- package/README.md +3 -7
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +5 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/inMemoryCache.cjs +0 -4
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -4
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +28 -6
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +71 -54
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.d.cts +1 -1
- package/__cjs/cache/inmemory/types.d.cts +1 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +21 -22
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +44 -10
- package/__cjs/core/ObservableQuery.cjs +56 -14
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +13 -2
- package/__cjs/core/QueryInfo.cjs +175 -161
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +15 -5
- package/__cjs/core/QueryManager.cjs +63 -38
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/core/dataStateErrorCache.cjs +12 -0
- package/__cjs/core/dataStateErrorCache.cjs.map +1 -0
- package/__cjs/core/dataStateErrorCache.d.cts +3 -0
- package/__cjs/core/types.d.cts +2 -0
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +34 -11
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +26 -3
- package/__cjs/incremental/types.d.cts +41 -3
- package/__cjs/invariantErrorCodes.cjs +56 -32
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +26 -20
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +10 -7
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +74 -32
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/types.d.cts +14 -3
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
- package/__cjs/testing/core/mocking/mockLink.cjs +21 -1
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
- package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
- package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
- package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
- package/__cjs/utilities/internal/index.cjs +8 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -0
- package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
- package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
- package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +5 -1
- 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/inMemoryCache.d.ts +3 -4
- package/cache/inmemory/inMemoryCache.js +1 -5
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +28 -6
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +1 -1
- package/cache/inmemory/readFromStore.js +72 -55
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +1 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +44 -10
- package/core/ApolloClient.js +21 -22
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +13 -2
- package/core/ObservableQuery.js +57 -15
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +15 -5
- package/core/QueryInfo.js +171 -161
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +63 -38
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.js +3 -3
- package/core/dataStateErrorCache.d.ts +3 -0
- package/core/dataStateErrorCache.js +9 -0
- package/core/dataStateErrorCache.js.map +1 -0
- package/core/types.d.ts +2 -0
- package/core/types.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +26 -3
- package/incremental/handlers/graphql17Alpha9.js +35 -12
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/types.d.ts +41 -3
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +56 -32
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +100 -47
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +26 -20
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +23 -15
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +10 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +74 -32
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +83 -34
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +26 -20
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +10 -7
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +74 -32
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/types.d.ts +15 -4
- package/react/internal/types.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +20 -5
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +1 -2
- package/testing/core/mocking/mockLink.js +21 -1
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
- package/utilities/internal/addDeferFragmentLabels.js +30 -0
- package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
- package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
- package/utilities/internal/getDirectiveArgValue.js +16 -0
- package/utilities/internal/getDirectiveArgValue.js.map +1 -0
- package/utilities/internal/index.d.ts +3 -0
- package/utilities/internal/index.js +3 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/toDiffWithDataState.d.ts +8 -0
- package/utilities/internal/toDiffWithDataState.js +17 -0
- package/utilities/internal/toDiffWithDataState.js.map +1 -0
- package/version.js +1 -1
|
@@ -349,7 +349,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
349
349
|
*/
|
|
350
350
|
getCacheDiff({ optimistic }?: {
|
|
351
351
|
optimistic?: boolean | undefined;
|
|
352
|
-
}): Cache.
|
|
352
|
+
}): Cache.InternalDiffResultWithDataState<TData>;
|
|
353
353
|
private getInitialResult;
|
|
354
354
|
private resubscribeCache;
|
|
355
355
|
private stableLastResult?;
|
|
@@ -372,7 +372,18 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
372
372
|
/**
|
|
373
373
|
* 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/).
|
|
374
374
|
*/
|
|
375
|
-
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>
|
|
375
|
+
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables, TErrorPolicy extends ErrorPolicy = "none">(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars> & {
|
|
376
|
+
/**
|
|
377
|
+
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
|
378
|
+
*
|
|
379
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
380
|
+
*
|
|
381
|
+
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
382
|
+
*
|
|
383
|
+
* @docGroup 1. Operation options
|
|
384
|
+
*/
|
|
385
|
+
errorPolicy?: TErrorPolicy;
|
|
386
|
+
}): Promise<ApolloClient.QueryResult<TFetchData, TErrorPolicy>>;
|
|
376
387
|
/**
|
|
377
388
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
378
389
|
*
|
package/core/ObservableQuery.js
CHANGED
|
@@ -2,8 +2,9 @@ import { equal } from "@wry/equality";
|
|
|
2
2
|
import { BehaviorSubject, filter, Observable, share, Subject, tap } from "rxjs";
|
|
3
3
|
import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/client/utilities";
|
|
4
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
-
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, handleIncrementalSymbol, preventUnhandledRejection, toDiffWithDataState, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
7
|
+
import { dataStateErrorCache } from "./dataStateErrorCache.js";
|
|
7
8
|
import { NetworkStatus } from "./networkStatus.js";
|
|
8
9
|
const { assign, hasOwnProperty } = Object;
|
|
9
10
|
const uninitialized = {
|
|
@@ -205,12 +206,13 @@ export class ObservableQuery {
|
|
|
205
206
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
206
207
|
*/
|
|
207
208
|
getCacheDiff({ optimistic = true } = {}) {
|
|
208
|
-
return this.cache.diff({
|
|
209
|
+
return toDiffWithDataState(this.cache.diff({
|
|
209
210
|
query: this.query,
|
|
210
211
|
variables: this.variables,
|
|
211
212
|
returnPartialData: true,
|
|
212
213
|
optimistic,
|
|
213
|
-
|
|
214
|
+
[handleIncrementalSymbol]: undefined,
|
|
215
|
+
}));
|
|
214
216
|
}
|
|
215
217
|
getInitialResult(initialFetchPolicy) {
|
|
216
218
|
let fetchPolicy = initialFetchPolicy || this.options.fetchPolicy;
|
|
@@ -220,16 +222,18 @@ export class ObservableQuery {
|
|
|
220
222
|
}
|
|
221
223
|
const cacheResult = () => {
|
|
222
224
|
const diff = this.getCacheDiff();
|
|
225
|
+
let { dataState } = diff;
|
|
223
226
|
// TODO: queryInfo.getDiff should handle this since cache.diff returns a
|
|
224
227
|
// null when returnPartialData is false
|
|
225
228
|
const data = this.options.returnPartialData || diff.complete ?
|
|
226
229
|
diff.result ?? undefined
|
|
227
230
|
: undefined;
|
|
231
|
+
if (data === undefined) {
|
|
232
|
+
dataState = "empty";
|
|
233
|
+
}
|
|
228
234
|
return this.maskResult({
|
|
229
235
|
data,
|
|
230
|
-
dataState
|
|
231
|
-
: data === undefined ? "empty"
|
|
232
|
-
: "partial",
|
|
236
|
+
dataState,
|
|
233
237
|
loading: !diff.complete,
|
|
234
238
|
networkStatus: diff.complete ? NetworkStatus.ready : NetworkStatus.loading,
|
|
235
239
|
partial: !diff.complete,
|
|
@@ -878,6 +882,7 @@ export class ObservableQuery {
|
|
|
878
882
|
if (this.pollingInfo) {
|
|
879
883
|
if (!isNetworkRequestInFlight(this.networkStatus) &&
|
|
880
884
|
!this.options.skipPollAttempt?.()) {
|
|
885
|
+
this._lastWrite = undefined;
|
|
881
886
|
this._reobserve({
|
|
882
887
|
// Most fetchPolicy options don't make sense to use in a polling context, as
|
|
883
888
|
// users wouldn't want to be polling the cache directly. However, network-only and
|
|
@@ -1154,9 +1159,7 @@ export class ObservableQuery {
|
|
|
1154
1159
|
kind: "N",
|
|
1155
1160
|
value: {
|
|
1156
1161
|
data: diff.result,
|
|
1157
|
-
dataState: diff.
|
|
1158
|
-
: diff.result ? "partial"
|
|
1159
|
-
: "empty",
|
|
1162
|
+
dataState: diff.dataState,
|
|
1160
1163
|
networkStatus: NetworkStatus.ready,
|
|
1161
1164
|
loading: false,
|
|
1162
1165
|
error: undefined,
|
|
@@ -1252,19 +1255,55 @@ export class ObservableQuery {
|
|
|
1252
1255
|
});
|
|
1253
1256
|
}
|
|
1254
1257
|
operator = filterMap((notification) => {
|
|
1255
|
-
const { query,
|
|
1258
|
+
const { query, meta } = notification;
|
|
1256
1259
|
if (notification.source === "setResult") {
|
|
1257
|
-
return {
|
|
1260
|
+
return {
|
|
1261
|
+
query,
|
|
1262
|
+
variables: this.variables,
|
|
1263
|
+
result: notification.value,
|
|
1264
|
+
meta,
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
if (notification.kind === "C") {
|
|
1268
|
+
return;
|
|
1258
1269
|
}
|
|
1259
|
-
|
|
1270
|
+
const resolvedVariables = "resolvedVariables" in notification ?
|
|
1271
|
+
notification.resolvedVariables
|
|
1272
|
+
: undefined;
|
|
1273
|
+
// Usually we prefer to drop notifications that don't match this query
|
|
1274
|
+
// but this breaks when used with `@export` queries that resolve variables
|
|
1275
|
+
// after the request is initiated. `notification.resolvedVariables` gives us
|
|
1276
|
+
// the variables the query actually resolved with during evaluation in
|
|
1277
|
+
// QueryManager (which is the variables value after `@export` variables have
|
|
1278
|
+
// been applied), but we need to update this query with those resolved
|
|
1279
|
+
// variables maybe in the middle of a request (updating is handled below).
|
|
1280
|
+
// When we update this.variables to the resolved variables, this causes
|
|
1281
|
+
// isEqualQuery(notification, this) to fail for future notifications since
|
|
1282
|
+
// the notification.variables holds the stale variables value. In this case,
|
|
1283
|
+
// we want to allow the notification through only if the current variables
|
|
1284
|
+
// value matches the resolved variables.
|
|
1285
|
+
//
|
|
1286
|
+
// Note: the check for matching resolved variables typically kicks in for
|
|
1287
|
+
// multi-emission fetches (such as defer, or cache-and-network, etc).
|
|
1288
|
+
if (notification.query !== this.query) {
|
|
1260
1289
|
return;
|
|
1261
1290
|
}
|
|
1291
|
+
if (!equal(resolvedVariables, this.variables)) {
|
|
1292
|
+
if (!equal(notification.variables, this.variables)) {
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
if (resolvedVariables) {
|
|
1296
|
+
this.options.variables = resolvedVariables;
|
|
1297
|
+
this.resubscribeCache();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const variables = this.variables;
|
|
1262
1301
|
let result;
|
|
1263
1302
|
const previous = this.subject.getValue();
|
|
1264
1303
|
if (notification.source === "cache") {
|
|
1265
1304
|
result = notification.value;
|
|
1266
1305
|
if (result.networkStatus === NetworkStatus.ready &&
|
|
1267
|
-
result.partial &&
|
|
1306
|
+
result.dataState === "partial" &&
|
|
1268
1307
|
(!this.options.returnPartialData ||
|
|
1269
1308
|
previous.result.networkStatus === NetworkStatus.error) &&
|
|
1270
1309
|
this.options.fetchPolicy !== "cache-only") {
|
|
@@ -1279,7 +1318,9 @@ export class ObservableQuery {
|
|
|
1279
1318
|
result =
|
|
1280
1319
|
notification.kind === "E" ?
|
|
1281
1320
|
{
|
|
1282
|
-
...(isEqualQuery(previous, notification)
|
|
1321
|
+
...((isEqualQuery(previous, notification) ||
|
|
1322
|
+
(resolvedVariables &&
|
|
1323
|
+
equal(resolvedVariables, previous.variables))) ?
|
|
1283
1324
|
previous.result
|
|
1284
1325
|
: { data: undefined, dataState: "empty", partial: true }),
|
|
1285
1326
|
error: notification.error,
|
|
@@ -1288,7 +1329,8 @@ export class ObservableQuery {
|
|
|
1288
1329
|
}
|
|
1289
1330
|
: notification.value;
|
|
1290
1331
|
if (notification.kind === "E" && result.dataState === "streaming") {
|
|
1291
|
-
result.dataState =
|
|
1332
|
+
result.dataState =
|
|
1333
|
+
dataStateErrorCache.get(notification.error) ?? "complete";
|
|
1292
1334
|
}
|
|
1293
1335
|
if (result.error) {
|
|
1294
1336
|
meta.shouldEmit = 1 /* EmitBehavior.force */;
|