@apollo/client 4.0.0-rc.4 → 4.0.0-rc.5
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 +45 -0
- package/__cjs/cache/core/cache.cjs +2 -6
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +42 -13
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +1 -1
- package/__cjs/core/ApolloClient.cjs +45 -7
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +17 -4
- package/__cjs/core/ObservableQuery.cjs +40 -10
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +73 -9
- package/__cjs/core/types.d.cts +87 -10
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +11 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +4 -0
- package/__cjs/react/hooks/useFragment.cjs +4 -9
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +5 -1
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +209 -10
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +270 -246
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +4 -0
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +79 -62
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +185 -161
- package/__cjs/react/index.cjs +1 -3
- package/__cjs/react/index.cjs.map +1 -1
- package/__cjs/react/index.d.cts +0 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs +1 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/types/types.documentation.d.cts +12 -1
- package/__cjs/utilities/internal/getStoreKeyName.cjs +8 -5
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +4 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +2 -0
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs +14 -0
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs.map +1 -0
- package/__cjs/utilities/internal/removeFragmentSpreads.d.cts +3 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.cjs +3 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.cjs.map +1 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +82 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +42 -13
- package/cache/core/cache.js +2 -6
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +1 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/types.d.ts +1 -1
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +17 -4
- package/core/ApolloClient.js +46 -8
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +73 -9
- package/core/ObservableQuery.js +40 -10
- package/core/ObservableQuery.js.map +1 -1
- package/core/types.d.ts +87 -10
- package/core/types.js.map +1 -1
- package/link/http/HttpLink.d.ts +11 -1
- package/link/http/HttpLink.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +4 -0
- package/react/hooks/useFragment.js +4 -9
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +5 -1
- package/react/hooks/useLoadableQuery.d.ts +209 -10
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +270 -246
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +4 -0
- package/react/hooks/useSubscription.d.ts +79 -62
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +185 -161
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +4 -0
- package/react/hooks-compiled/useFragment.js +4 -9
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +5 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +209 -10
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +270 -246
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +4 -0
- package/react/hooks-compiled/useSubscription.d.ts +79 -62
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +185 -161
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/index.compiled.d.ts +0 -1
- package/react/index.compiled.js +0 -1
- package/react/index.compiled.js.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.js +0 -1
- package/react/index.js.map +1 -1
- package/react/internal/cache/FragmentReference.js +1 -1
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/types/types.documentation.d.ts +12 -1
- package/react/types/types.documentation.js.map +1 -1
- package/utilities/internal/getStoreKeyName.js +8 -5
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/index.d.ts +2 -0
- package/utilities/internal/index.js +1 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/removeFragmentSpreads.d.ts +3 -0
- package/utilities/internal/removeFragmentSpreads.js +11 -0
- package/utilities/internal/removeFragmentSpreads.js.map +1 -0
- package/utilities/internal/types/DocumentationTypes.d.ts +82 -0
- package/utilities/internal/types/DocumentationTypes.js +2 -0
- package/utilities/internal/types/DocumentationTypes.js.map +1 -0
- package/version.js +1 -1
package/core/types.d.ts
CHANGED
|
@@ -181,43 +181,120 @@ export type InternalRefetchQueriesMap<TResult> = Map<ObservableQuery<any>, Inter
|
|
|
181
181
|
export type OperationVariables = Record<string, any>;
|
|
182
182
|
export type ApolloQueryResult<TData, TStates extends DataState<TData>["dataState"] = DataState<TData>["dataState"]> = {
|
|
183
183
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
* A single ErrorLike object describing the error that occured during the latest query execution.
|
|
185
|
+
*
|
|
186
|
+
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
187
|
+
*
|
|
188
|
+
* @docGroup
|
|
189
|
+
*
|
|
190
|
+
* 1. Operation data
|
|
191
|
+
*/
|
|
188
192
|
error?: ErrorLike;
|
|
193
|
+
/**
|
|
194
|
+
* If `true`, the query is still in flight and results have not yet been returned.
|
|
195
|
+
*
|
|
196
|
+
* @docGroup
|
|
197
|
+
*
|
|
198
|
+
* 2. Network info
|
|
199
|
+
*/
|
|
189
200
|
loading: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* A number indicating the current network state of the query's associated request. [See possible values.](https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/core/networkStatus.ts#L4)
|
|
203
|
+
*
|
|
204
|
+
* Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option.
|
|
205
|
+
*
|
|
206
|
+
* @docGroup
|
|
207
|
+
*
|
|
208
|
+
* 2. Network info
|
|
209
|
+
*/
|
|
190
210
|
networkStatus: NetworkStatus;
|
|
191
211
|
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
212
|
+
* Describes whether `data` is a complete or partial result. This flag is only set when `returnPartialData` is `true` in query options.
|
|
213
|
+
*
|
|
214
|
+
* @deprecated
|
|
215
|
+
*
|
|
216
|
+
* This field will be removed in a future version of Apollo Client.
|
|
217
|
+
*
|
|
218
|
+
* @docGroup
|
|
219
|
+
*
|
|
220
|
+
* 1. Operation data
|
|
221
|
+
*/
|
|
197
222
|
partial: boolean;
|
|
198
223
|
} & GetDataState<TData, TStates>;
|
|
199
224
|
export type DataState<TData> = {
|
|
225
|
+
/**
|
|
226
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
227
|
+
*
|
|
228
|
+
* This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
|
|
229
|
+
*
|
|
230
|
+
* @docGroup
|
|
231
|
+
*
|
|
232
|
+
* 1. Operation data
|
|
233
|
+
*/
|
|
200
234
|
data: DataValue.Complete<TData>;
|
|
201
235
|
/**
|
|
202
236
|
* Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
|
|
237
|
+
*
|
|
238
|
+
* @docGroup
|
|
239
|
+
*
|
|
240
|
+
* 1. Operation data
|
|
203
241
|
*/
|
|
204
242
|
dataState: "complete";
|
|
205
243
|
} | {
|
|
244
|
+
/**
|
|
245
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
246
|
+
*
|
|
247
|
+
* This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
|
|
248
|
+
*
|
|
249
|
+
* @docGroup
|
|
250
|
+
*
|
|
251
|
+
* 1. Operation data
|
|
252
|
+
*/
|
|
206
253
|
data: DataValue.Streaming<TData>;
|
|
207
254
|
/**
|
|
208
255
|
* Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
|
|
256
|
+
*
|
|
257
|
+
* @docGroup
|
|
258
|
+
*
|
|
259
|
+
* 1. Operation data
|
|
209
260
|
*/
|
|
210
261
|
dataState: "streaming";
|
|
211
262
|
} | {
|
|
263
|
+
/**
|
|
264
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
265
|
+
*
|
|
266
|
+
* This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
|
|
267
|
+
*
|
|
268
|
+
* @docGroup
|
|
269
|
+
*
|
|
270
|
+
* 1. Operation data
|
|
271
|
+
*/
|
|
212
272
|
data: DataValue.Partial<TData>;
|
|
213
273
|
/**
|
|
214
274
|
* Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
|
|
275
|
+
*
|
|
276
|
+
* @docGroup
|
|
277
|
+
*
|
|
278
|
+
* 1. Operation data
|
|
215
279
|
*/
|
|
216
280
|
dataState: "partial";
|
|
217
281
|
} | {
|
|
282
|
+
/**
|
|
283
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
284
|
+
*
|
|
285
|
+
* This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
|
|
286
|
+
*
|
|
287
|
+
* @docGroup
|
|
288
|
+
*
|
|
289
|
+
* 1. Operation data
|
|
290
|
+
*/
|
|
218
291
|
data: undefined;
|
|
219
292
|
/**
|
|
220
293
|
* Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
|
|
294
|
+
*
|
|
295
|
+
* @docGroup
|
|
296
|
+
*
|
|
297
|
+
* 1. Operation data
|
|
221
298
|
*/
|
|
222
299
|
dataState: "empty";
|
|
223
300
|
};
|
|
@@ -288,7 +365,7 @@ export interface QueryResult<TData = unknown> {
|
|
|
288
365
|
*/
|
|
289
366
|
data: TData | undefined;
|
|
290
367
|
/**
|
|
291
|
-
*
|
|
368
|
+
* A single ErrorLike object describing the error that occured during the latest query execution.
|
|
292
369
|
*
|
|
293
370
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
294
371
|
*
|
package/core/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FormattedExecutionResult } from \"graphql\";\nimport type {\n NextNotification,\n Observable,\n ObservableNotification,\n} from \"rxjs\";\n\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport type { Cache } from \"@apollo/client/cache\";\nimport type { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { DeepPartial, HKT } from \"@apollo/client/utilities\";\nimport type {\n ApplyHKTImplementationWithDefault,\n IsAny,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { NetworkStatus } from \"./networkStatus.js\";\nimport type { ObservableQuery } from \"./ObservableQuery.js\";\nimport type { QueryOptions } from \"./watchQueryOptions.js\";\n\nexport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nexport type MethodKeys<T> = {\n [P in keyof T]: T[P] extends Function ? P : never;\n}[keyof T];\n\nexport interface TypeOverrides {}\n\nnamespace OverridableTypes {\n export interface Defaults {\n Complete: Complete;\n Streaming: Streaming;\n Partial: Partial;\n }\n\n interface Complete extends HKT {\n arg1: unknown; // TData\n return: this[\"arg1\"];\n }\n\n interface Streaming extends HKT {\n arg1: unknown; // TData\n return: this[\"arg1\"];\n }\n\n interface Partial extends HKT {\n arg1: unknown; // TData\n return: DeepPartial<this[\"arg1\"]>;\n }\n}\n\nexport declare namespace DataValue {\n /**\n * Returns a representation of `TData` in it's \"complete\" state.\n *\n * @defaultValue `TData` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type CompleteOverride<TData> = TData extends { _complete?: infer _Complete } ? _Complete : TData;\n *\n * interface CompleteOverrideHKT extends HKT {\n * return: CompleteOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Complete: CompleteOverrideHKT;\n * }\n * }\n * ```\n */\n export type Complete<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Complete\",\n OverridableTypes.Defaults,\n TData\n >;\n\n /**\n * Returns a representation of `TData` while it is streaming.\n *\n * @defaultValue `TData` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type StreamingOverride<TData> = DeepPartial<TData>;\n *\n * interface StreamingOverrideHKT extends HKT {\n * return: StreamingOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Streaming: StreamingOverrideHKT;\n * }\n * }\n * ```\n */\n export type Streaming<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Streaming\",\n OverridableTypes.Defaults,\n TData\n >;\n\n /**\n * Returns a representation of `TData` while it is partial.\n *\n * @defaultValue `DeepPartial<TData>` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type PartialOverride<TData> = DeepPartial<Complete<TData>>;\n *\n * interface PartialOverrideHKT extends HKT {\n * return: PartialOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Partial: PartialOverrideHKT;\n * }\n * }\n * ```\n */\n export type Partial<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Partial\",\n OverridableTypes.Defaults,\n TData\n >;\n}\nexport interface DefaultContext extends Record<string, any> {\n /**\n * Indicates whether `queryDeduplication` was enabled for the request.\n */\n queryDeduplication?: boolean;\n clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;\n}\n\n/**\n * Represents an `Error` type, but used throughout Apollo Client to represent\n * errors that may otherwise fail `instanceof` checks if they are cross-realm\n * Error instances (see the [`Error.isError` proposal](https://github.com/tc39/proposal-is-error) for more details).\n *\n * Apollo Client uses several types of errors throughout the client which can be\n * narrowed using `instanceof`:\n * - `CombinedGraphQLErrors` - `errors` returned from a GraphQL result\n * - `CombinedProtocolErrors` - Transport-level errors from multipart subscriptions.\n * - `ServerParseError` - A JSON-parse error when parsing the server response.\n * - `ServerError` - A non-200 server response.\n *\n * @example\n * ```ts\n * import { CombinedGraphQLErrors } from \"@apollo/client\";\n *\n * try {\n * await client.query({ query });\n * } catch (error) {\n * // Use `instanceof` to check for more specific types of errors.\n * if (error instanceof CombinedGraphQLErrors) {\n * error.errors.map(graphQLError => console.log(graphQLError.message));\n * } else {\n * console.error(errors);\n * }\n * }\n * ```\n */\nexport interface ErrorLike {\n message: string;\n name: string;\n stack?: string;\n}\n\nexport type OnQueryUpdated<TResult> = (\n observableQuery: ObservableQuery<any>,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined\n) => boolean | TResult;\n\nexport type RefetchQueryDescriptor = string | DocumentNode;\nexport type InternalRefetchQueryDescriptor =\n | RefetchQueryDescriptor\n | QueryOptions;\n\ntype RefetchQueriesIncludeShorthand = \"all\" | \"active\";\n\nexport type RefetchQueriesInclude =\n | RefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\nexport type InternalRefetchQueriesInclude =\n | InternalRefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\n// Used by ApolloClient[\"refetchQueries\"]\n// TODO Improve documentation comments for this public type.\nexport interface RefetchQueriesOptions<TCache extends ApolloCache, TResult> {\n updateCache?: (cache: TCache) => void;\n // The client.refetchQueries method discourages passing QueryOptions, by\n // restricting the public type of options.include to exclude QueryOptions as\n // an available array element type (see InternalRefetchQueriesInclude for a\n // version of RefetchQueriesInclude that allows legacy QueryOptions objects).\n include?: RefetchQueriesInclude;\n optimistic?: boolean;\n // If no onQueryUpdated function is provided, any queries affected by the\n // updateCache function or included in the options.include array will be\n // refetched by default. Passing null instead of undefined disables this\n // default refetching behavior for affected queries, though included queries\n // will still be refetched.\n onQueryUpdated?: OnQueryUpdated<TResult> | null;\n}\n\n// The client.refetchQueries method returns a thenable (PromiseLike) object\n// whose result is an array of Promise.resolve'd TResult values, where TResult\n// is whatever type the (optional) onQueryUpdated function returns. When no\n// onQueryUpdated function is given, TResult defaults to ApolloQueryResult<any>\n// (thanks to default type parameters for client.refetchQueries).\nexport type RefetchQueriesPromiseResults<TResult> =\n // If onQueryUpdated returns any, all bets are off, so the results array must\n // be a generic any[] array, which is much less confusing than the union type\n // we get if we don't check for any. I hoped `any extends TResult` would do\n // the trick here, instead of IsStrictlyAny, but you can see for yourself what\n // fails in the refetchQueries tests if you try making that simplification.\n IsAny<TResult> extends true ? any[]\n : // If the onQueryUpdated function passed to client.refetchQueries returns true\n // or false, that means either to refetch the query (true) or to skip the\n // query (false). Since refetching produces an ApolloQueryResult<any>, and\n // skipping produces nothing, the fully-resolved array of all results produced\n // will be an ApolloQueryResult<any>[], when TResult extends boolean.\n TResult extends boolean ? QueryResult<any>[]\n : // If onQueryUpdated returns a PromiseLike<U>, that thenable will be passed as\n // an array element to Promise.all, so we infer/unwrap the array type U here.\n TResult extends PromiseLike<infer U> ? U[]\n : // All other onQueryUpdated results end up in the final Promise.all array as\n // themselves, with their original TResult type. Note that TResult will\n // default to ApolloQueryResult<any> if no onQueryUpdated function is passed\n // to client.refetchQueries.\n TResult[];\n\n// The result of client.refetchQueries is thenable/awaitable, if you just want\n// an array of fully resolved results, but you can also access the raw results\n// immediately by examining the additional { queries, results } properties of\n// the RefetchQueriesResult<TResult> object.\nexport interface RefetchQueriesResult<TResult>\n extends Promise<RefetchQueriesPromiseResults<TResult>> {\n // An array of ObservableQuery objects corresponding 1:1 to TResult values\n // in the results arrays (both the TResult[] array below, and the results\n // array resolved by the Promise above).\n queries: ObservableQuery<any>[];\n // These are the raw TResult values returned by any onQueryUpdated functions\n // that were invoked by client.refetchQueries.\n results: InternalRefetchQueriesResult<TResult>[];\n}\n\n// Used by QueryManager[\"refetchQueries\"]\nexport interface InternalRefetchQueriesOptions<\n TCache extends ApolloCache,\n TResult,\n> extends Omit<RefetchQueriesOptions<TCache, TResult>, \"include\"> {\n // Just like the refetchQueries option for a mutation, an array of strings,\n // DocumentNode objects, and/or QueryOptions objects, or one of the shorthand\n // strings \"all\" or \"active\", to select every (active) query.\n include?: InternalRefetchQueriesInclude;\n // This part of the API is a (useful) implementation detail, but need not be\n // exposed in the public client.refetchQueries API (above).\n removeOptimistic?: string;\n}\n\nexport type InternalRefetchQueriesResult<TResult> =\n // If onQueryUpdated returns a boolean, that's equivalent to refetching the\n // query when the boolean is true and skipping the query when false, so the\n // internal type of refetched results is Promise<ApolloQueryResult<any>>.\n TResult extends boolean ? Promise<QueryResult<any>>\n : // Otherwise, onQueryUpdated returns whatever it returns. If onQueryUpdated is\n // not provided, TResult defaults to Promise<ApolloQueryResult<any>> (see the\n // generic type parameters of client.refetchQueries).\n TResult;\n\nexport type InternalRefetchQueriesMap<TResult> = Map<\n ObservableQuery<any>,\n InternalRefetchQueriesResult<TResult>\n>;\n\nexport type OperationVariables = Record<string, any>;\n\nexport type ApolloQueryResult<\n TData,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n> = {\n /**\n * The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.\n * This will contain both a NetworkError field and any GraphQLErrors.\n * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.\n */\n error?: ErrorLike;\n loading: boolean;\n networkStatus: NetworkStatus;\n /**\n * Describes whether `data` is a complete or partial result. This flag is only\n * set when `returnPartialData` is `true` in query options.\n *\n * @deprecated This field will be removed in a future version of Apollo Client.\n */\n partial: boolean;\n} & GetDataState<TData, TStates>;\n\nexport type DataState<TData> =\n | {\n data: DataValue.Complete<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"complete\";\n }\n | {\n data: DataValue.Streaming<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"streaming\";\n }\n | {\n data: DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n }\n | {\n data: undefined;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"empty\";\n };\n\nexport type GetDataState<\n TData,\n TState extends DataState<TData>[\"dataState\"],\n> = Extract<DataState<TData>, { dataState: TState }>;\n\n/**\n * Represents a result that might be complete or still streaming and\n * has been normalized into a plain GraphQL result. When the result is\n * still `streaming`, some fields might not yet be available.\n */\nexport type NormalizedExecutionResult<\n TData = Record<string, unknown>,\n TExtensions = Record<string, unknown>,\n> = Omit<FormattedExecutionResult<TData, TExtensions>, \"data\"> &\n GetDataState<TData, \"streaming\" | \"complete\">;\n\n// This is part of the public API, people write these functions in `updateQueries`.\nexport type MutationQueryReducer<T> = (\n previousResult: Record<string, any>,\n options: {\n mutationResult: NormalizedExecutionResult<Unmasked<T>>;\n queryName: string | undefined;\n queryVariables: Record<string, any>;\n }\n) => Record<string, any>;\n\nexport type MutationQueryReducersMap<T = { [key: string]: any }> = {\n [queryName: string]: MutationQueryReducer<T>;\n};\n\nexport type MutationUpdaterFunction<\n TData,\n TVariables,\n TCache extends ApolloCache,\n> = (\n cache: TCache,\n result: FormattedExecutionResult<Unmasked<TData>>,\n options: {\n context?: DefaultContext;\n variables?: TVariables;\n }\n) => void;\n\nexport interface MutateResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error?: ErrorLike;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#extensions:member} */\n extensions?: Record<string, unknown>;\n}\n\nexport interface SubscribeResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error?: ErrorLike;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#extensions:member} */\n extensions?: Record<string, unknown>;\n}\n\nexport interface QueryResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#error:member} */\n error?: ErrorLike;\n}\n\nexport declare namespace QueryNotification {\n type NewNetworkStatus<TData> = NextNotification<{\n resetError?: boolean;\n }> & {\n source: \"newNetworkStatus\";\n };\n\n type SetResult<TData> = NextNotification<ApolloQueryResult<TData>> & {\n source: \"setResult\";\n };\n\n type FromNetwork<TData> = ObservableNotification<ApolloQueryResult<TData>> & {\n source: \"network\";\n };\n\n type FromCache<TData> = NextNotification<ApolloQueryResult<TData>> & {\n source: \"cache\";\n };\n\n type Value<TData> =\n | FromCache<TData>\n | FromNetwork<TData>\n | NewNetworkStatus<TData>\n | SetResult<TData>;\n}\n\n/** Observable created by initiating a subscription operation. */\nexport interface SubscriptionObservable<T> extends Observable<T> {\n /**\n * Used to restart the connection to the link chain. Calling this on a\n * deduplicated subscription will restart the connection for all observables\n * that share the request.\n *\n * @example\n *\n * ```ts\n * const observable = client.subscribe({ query: subscription });\n * observable.subscribe((value) => {\n * // ...\n * });\n *\n * observable.restart();\n * ```\n */\n restart: () => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FormattedExecutionResult } from \"graphql\";\nimport type {\n NextNotification,\n Observable,\n ObservableNotification,\n} from \"rxjs\";\n\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport type { Cache } from \"@apollo/client/cache\";\nimport type { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { DeepPartial, HKT } from \"@apollo/client/utilities\";\nimport type {\n ApplyHKTImplementationWithDefault,\n IsAny,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { NetworkStatus } from \"./networkStatus.js\";\nimport type { ObservableQuery } from \"./ObservableQuery.js\";\nimport type { QueryOptions } from \"./watchQueryOptions.js\";\n\nexport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nexport type MethodKeys<T> = {\n [P in keyof T]: T[P] extends Function ? P : never;\n}[keyof T];\n\nexport interface TypeOverrides {}\n\nnamespace OverridableTypes {\n export interface Defaults {\n Complete: Complete;\n Streaming: Streaming;\n Partial: Partial;\n }\n\n interface Complete extends HKT {\n arg1: unknown; // TData\n return: this[\"arg1\"];\n }\n\n interface Streaming extends HKT {\n arg1: unknown; // TData\n return: this[\"arg1\"];\n }\n\n interface Partial extends HKT {\n arg1: unknown; // TData\n return: DeepPartial<this[\"arg1\"]>;\n }\n}\n\nexport declare namespace DataValue {\n /**\n * Returns a representation of `TData` in it's \"complete\" state.\n *\n * @defaultValue `TData` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type CompleteOverride<TData> = TData extends { _complete?: infer _Complete } ? _Complete : TData;\n *\n * interface CompleteOverrideHKT extends HKT {\n * return: CompleteOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Complete: CompleteOverrideHKT;\n * }\n * }\n * ```\n */\n export type Complete<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Complete\",\n OverridableTypes.Defaults,\n TData\n >;\n\n /**\n * Returns a representation of `TData` while it is streaming.\n *\n * @defaultValue `TData` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type StreamingOverride<TData> = DeepPartial<TData>;\n *\n * interface StreamingOverrideHKT extends HKT {\n * return: StreamingOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Streaming: StreamingOverrideHKT;\n * }\n * }\n * ```\n */\n export type Streaming<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Streaming\",\n OverridableTypes.Defaults,\n TData\n >;\n\n /**\n * Returns a representation of `TData` while it is partial.\n *\n * @defaultValue `DeepPartial<TData>` if no overrides are provided.\n *\n * @example\n * You can override this type globally - this example shows how to override it\n * with `DeepPartial<TData>`:\n *\n * ```ts\n * import { HKT, DeepPartial } from \"@apollo/client/utilities\";\n *\n * type PartialOverride<TData> = DeepPartial<Complete<TData>>;\n *\n * interface PartialOverrideHKT extends HKT {\n * return: PartialOverride<this[\"arg1\"]>;\n * }\n *\n * declare module \"@apollo/client\" {\n * export interface TypeOverrides {\n * Partial: PartialOverrideHKT;\n * }\n * }\n * ```\n */\n export type Partial<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Partial\",\n OverridableTypes.Defaults,\n TData\n >;\n}\nexport interface DefaultContext extends Record<string, any> {\n /**\n * Indicates whether `queryDeduplication` was enabled for the request.\n */\n queryDeduplication?: boolean;\n clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;\n}\n\n/**\n * Represents an `Error` type, but used throughout Apollo Client to represent\n * errors that may otherwise fail `instanceof` checks if they are cross-realm\n * Error instances (see the [`Error.isError` proposal](https://github.com/tc39/proposal-is-error) for more details).\n *\n * Apollo Client uses several types of errors throughout the client which can be\n * narrowed using `instanceof`:\n * - `CombinedGraphQLErrors` - `errors` returned from a GraphQL result\n * - `CombinedProtocolErrors` - Transport-level errors from multipart subscriptions.\n * - `ServerParseError` - A JSON-parse error when parsing the server response.\n * - `ServerError` - A non-200 server response.\n *\n * @example\n * ```ts\n * import { CombinedGraphQLErrors } from \"@apollo/client\";\n *\n * try {\n * await client.query({ query });\n * } catch (error) {\n * // Use `instanceof` to check for more specific types of errors.\n * if (error instanceof CombinedGraphQLErrors) {\n * error.errors.map(graphQLError => console.log(graphQLError.message));\n * } else {\n * console.error(errors);\n * }\n * }\n * ```\n */\nexport interface ErrorLike {\n message: string;\n name: string;\n stack?: string;\n}\n\nexport type OnQueryUpdated<TResult> = (\n observableQuery: ObservableQuery<any>,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined\n) => boolean | TResult;\n\nexport type RefetchQueryDescriptor = string | DocumentNode;\nexport type InternalRefetchQueryDescriptor =\n | RefetchQueryDescriptor\n | QueryOptions;\n\ntype RefetchQueriesIncludeShorthand = \"all\" | \"active\";\n\nexport type RefetchQueriesInclude =\n | RefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\nexport type InternalRefetchQueriesInclude =\n | InternalRefetchQueryDescriptor[]\n | RefetchQueriesIncludeShorthand;\n\n// Used by ApolloClient[\"refetchQueries\"]\n// TODO Improve documentation comments for this public type.\nexport interface RefetchQueriesOptions<TCache extends ApolloCache, TResult> {\n updateCache?: (cache: TCache) => void;\n // The client.refetchQueries method discourages passing QueryOptions, by\n // restricting the public type of options.include to exclude QueryOptions as\n // an available array element type (see InternalRefetchQueriesInclude for a\n // version of RefetchQueriesInclude that allows legacy QueryOptions objects).\n include?: RefetchQueriesInclude;\n optimistic?: boolean;\n // If no onQueryUpdated function is provided, any queries affected by the\n // updateCache function or included in the options.include array will be\n // refetched by default. Passing null instead of undefined disables this\n // default refetching behavior for affected queries, though included queries\n // will still be refetched.\n onQueryUpdated?: OnQueryUpdated<TResult> | null;\n}\n\n// The client.refetchQueries method returns a thenable (PromiseLike) object\n// whose result is an array of Promise.resolve'd TResult values, where TResult\n// is whatever type the (optional) onQueryUpdated function returns. When no\n// onQueryUpdated function is given, TResult defaults to ApolloQueryResult<any>\n// (thanks to default type parameters for client.refetchQueries).\nexport type RefetchQueriesPromiseResults<TResult> =\n // If onQueryUpdated returns any, all bets are off, so the results array must\n // be a generic any[] array, which is much less confusing than the union type\n // we get if we don't check for any. I hoped `any extends TResult` would do\n // the trick here, instead of IsStrictlyAny, but you can see for yourself what\n // fails in the refetchQueries tests if you try making that simplification.\n IsAny<TResult> extends true ? any[]\n : // If the onQueryUpdated function passed to client.refetchQueries returns true\n // or false, that means either to refetch the query (true) or to skip the\n // query (false). Since refetching produces an ApolloQueryResult<any>, and\n // skipping produces nothing, the fully-resolved array of all results produced\n // will be an ApolloQueryResult<any>[], when TResult extends boolean.\n TResult extends boolean ? QueryResult<any>[]\n : // If onQueryUpdated returns a PromiseLike<U>, that thenable will be passed as\n // an array element to Promise.all, so we infer/unwrap the array type U here.\n TResult extends PromiseLike<infer U> ? U[]\n : // All other onQueryUpdated results end up in the final Promise.all array as\n // themselves, with their original TResult type. Note that TResult will\n // default to ApolloQueryResult<any> if no onQueryUpdated function is passed\n // to client.refetchQueries.\n TResult[];\n\n// The result of client.refetchQueries is thenable/awaitable, if you just want\n// an array of fully resolved results, but you can also access the raw results\n// immediately by examining the additional { queries, results } properties of\n// the RefetchQueriesResult<TResult> object.\nexport interface RefetchQueriesResult<TResult>\n extends Promise<RefetchQueriesPromiseResults<TResult>> {\n // An array of ObservableQuery objects corresponding 1:1 to TResult values\n // in the results arrays (both the TResult[] array below, and the results\n // array resolved by the Promise above).\n queries: ObservableQuery<any>[];\n // These are the raw TResult values returned by any onQueryUpdated functions\n // that were invoked by client.refetchQueries.\n results: InternalRefetchQueriesResult<TResult>[];\n}\n\n// Used by QueryManager[\"refetchQueries\"]\nexport interface InternalRefetchQueriesOptions<\n TCache extends ApolloCache,\n TResult,\n> extends Omit<RefetchQueriesOptions<TCache, TResult>, \"include\"> {\n // Just like the refetchQueries option for a mutation, an array of strings,\n // DocumentNode objects, and/or QueryOptions objects, or one of the shorthand\n // strings \"all\" or \"active\", to select every (active) query.\n include?: InternalRefetchQueriesInclude;\n // This part of the API is a (useful) implementation detail, but need not be\n // exposed in the public client.refetchQueries API (above).\n removeOptimistic?: string;\n}\n\nexport type InternalRefetchQueriesResult<TResult> =\n // If onQueryUpdated returns a boolean, that's equivalent to refetching the\n // query when the boolean is true and skipping the query when false, so the\n // internal type of refetched results is Promise<ApolloQueryResult<any>>.\n TResult extends boolean ? Promise<QueryResult<any>>\n : // Otherwise, onQueryUpdated returns whatever it returns. If onQueryUpdated is\n // not provided, TResult defaults to Promise<ApolloQueryResult<any>> (see the\n // generic type parameters of client.refetchQueries).\n TResult;\n\nexport type InternalRefetchQueriesMap<TResult> = Map<\n ObservableQuery<any>,\n InternalRefetchQueriesResult<TResult>\n>;\n\nexport type OperationVariables = Record<string, any>;\n\nexport type ApolloQueryResult<\n TData,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n> = {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#error:member} */\n error?: ErrorLike;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#loading:member} */\n loading: boolean;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#networkStatus:member} */\n networkStatus: NetworkStatus;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#partial:member} */\n partial: boolean;\n} & GetDataState<TData, TStates>;\n\nexport type DataState<TData> =\n | {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: DataValue.Complete<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"complete\";\n }\n | {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: DataValue.Streaming<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"streaming\";\n }\n | {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n }\n | {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: undefined;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"empty\";\n };\n\nexport type GetDataState<\n TData,\n TState extends DataState<TData>[\"dataState\"],\n> = Extract<DataState<TData>, { dataState: TState }>;\n\n/**\n * Represents a result that might be complete or still streaming and\n * has been normalized into a plain GraphQL result. When the result is\n * still `streaming`, some fields might not yet be available.\n */\nexport type NormalizedExecutionResult<\n TData = Record<string, unknown>,\n TExtensions = Record<string, unknown>,\n> = Omit<FormattedExecutionResult<TData, TExtensions>, \"data\"> &\n GetDataState<TData, \"streaming\" | \"complete\">;\n\n// This is part of the public API, people write these functions in `updateQueries`.\nexport type MutationQueryReducer<T> = (\n previousResult: Record<string, any>,\n options: {\n mutationResult: NormalizedExecutionResult<Unmasked<T>>;\n queryName: string | undefined;\n queryVariables: Record<string, any>;\n }\n) => Record<string, any>;\n\nexport type MutationQueryReducersMap<T = { [key: string]: any }> = {\n [queryName: string]: MutationQueryReducer<T>;\n};\n\nexport type MutationUpdaterFunction<\n TData,\n TVariables,\n TCache extends ApolloCache,\n> = (\n cache: TCache,\n result: FormattedExecutionResult<Unmasked<TData>>,\n options: {\n context?: DefaultContext;\n variables?: TVariables;\n }\n) => void;\n\nexport interface MutateResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error?: ErrorLike;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#extensions:member} */\n extensions?: Record<string, unknown>;\n}\n\nexport interface SubscribeResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error?: ErrorLike;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#extensions:member} */\n extensions?: Record<string, unknown>;\n}\n\nexport interface QueryResult<TData = unknown> {\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData | undefined;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#error:member} */\n error?: ErrorLike;\n}\n\nexport declare namespace QueryNotification {\n type NewNetworkStatus<TData> = NextNotification<{\n resetError?: boolean;\n }> & {\n source: \"newNetworkStatus\";\n };\n\n type SetResult<TData> = NextNotification<ApolloQueryResult<TData>> & {\n source: \"setResult\";\n };\n\n type FromNetwork<TData> = ObservableNotification<ApolloQueryResult<TData>> & {\n source: \"network\";\n };\n\n type FromCache<TData> = NextNotification<ApolloQueryResult<TData>> & {\n source: \"cache\";\n };\n\n type Value<TData> =\n | FromCache<TData>\n | FromNetwork<TData>\n | NewNetworkStatus<TData>\n | SetResult<TData>;\n}\n\n/** Observable created by initiating a subscription operation. */\nexport interface SubscriptionObservable<T> extends Observable<T> {\n /**\n * Used to restart the connection to the link chain. Calling this on a\n * deduplicated subscription will restart the connection for all observables\n * that share the request.\n *\n * @example\n *\n * ```ts\n * const observable = client.subscribe({ query: subscription });\n * observable.subscribe((value) => {\n * // ...\n * });\n *\n * observable.restart();\n * ```\n */\n restart: () => void;\n}\n"]}
|
package/link/http/HttpLink.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { ApolloLink } from "@apollo/client/link";
|
|
|
4
4
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
5
5
|
import type { print } from "@apollo/client/utilities";
|
|
6
6
|
export declare namespace HttpLink {
|
|
7
|
+
/**
|
|
8
|
+
* Options passed to `HttpLink` through request context.
|
|
9
|
+
*/
|
|
7
10
|
interface ContextOptions {
|
|
8
11
|
/**
|
|
9
12
|
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
@@ -34,8 +37,12 @@ export declare namespace HttpLink {
|
|
|
34
37
|
* An object that configures advanced `HttpLink` functionality, such as
|
|
35
38
|
* support for persisted queries.
|
|
36
39
|
*/
|
|
37
|
-
http?: HttpOptions;
|
|
40
|
+
http?: HttpLink.HttpOptions;
|
|
38
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Options passed to `HttpLink` through the `http` constructor option
|
|
44
|
+
* or the `http` property of a request context.
|
|
45
|
+
*/
|
|
39
46
|
interface HttpOptions {
|
|
40
47
|
/**
|
|
41
48
|
* If `true`, includes the `extensions` field in operations sent to your
|
|
@@ -71,6 +78,9 @@ export declare namespace HttpLink {
|
|
|
71
78
|
*/
|
|
72
79
|
accept?: string[];
|
|
73
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for the `HttpLink` constructor.
|
|
83
|
+
*/
|
|
74
84
|
interface Options {
|
|
75
85
|
/**
|
|
76
86
|
* The URI to use when fetching operations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpLink.js","sourceRoot":"","sources":["../../../src/link/http/HttpLink.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAG3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"HttpLink.js","sourceRoot":"","sources":["../../../src/link/http/HttpLink.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAG3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAsKjD,MAAM,OAAO,QAAS,SAAQ,UAAU;IACtC,YAAY,UAA0D,EAAE;QACtE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,MAAM,CAChD,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAChC,IAAI,YAAY,CAAC,OAAO,CAAC,CAC1B,CAAC;QACF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,cAA8D,EAAE,EAChE,EAAE,CAAC,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import type { ASTNode } from \"graphql\";\n\nimport type { Operation } from \"@apollo/client/link\";\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { print } from \"@apollo/client/utilities\";\n\nimport { BaseHttpLink } from \"./BaseHttpLink.js\";\n\nexport declare namespace HttpLink {\n /**\n * Options passed to `HttpLink` through request context.\n */\n interface ContextOptions {\n /**\n * The URL of the GraphQL endpoint to send requests to. Can also be a\n * function that accepts an `Operation` object and returns the string URL to\n * use for that operation.\n */\n uri?: string | UriFunction;\n\n /**\n * An object representing headers to include in the HTTP request, such as\n * `{Authorization: 'Bearer abc123'}`.\n */\n headers?: Record<string, string>;\n\n /**\n * The credentials policy to use for this fetch call. Can be `omit`, `include`,\n * or `same-origin`.\n */\n credentials?: RequestCredentials;\n\n /**\n * An object containing options to use for this call to `fetch`. If a\n * particular option is not included in this object, the default value of\n * that option is used.\n *\n * Note that if you set `fetchOptions.method` to `GET`, `HttpLink` follows\n * [standard GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).\n */\n fetchOptions?: RequestInit;\n\n /**\n * An object that configures advanced `HttpLink` functionality, such as\n * support for persisted queries.\n */\n http?: HttpLink.HttpOptions;\n }\n\n /**\n * Options passed to `HttpLink` through the `http` constructor option\n * or the `http` property of a request context.\n */\n export interface HttpOptions {\n /**\n * If `true`, includes the `extensions` field in operations sent to your\n * GraphQL endpoint.\n *\n * @defaultValue true\n */\n includeExtensions?: boolean;\n\n /**\n * If `false`, the GraphQL query string is not included in the request. Set\n * this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).\n *\n * @defaultValue true\n */\n includeQuery?: boolean;\n\n /**\n * If set to true, header names won't be automatically normalized to\n * lowercase. This allows for non-http-spec-compliant servers that might\n * expect capitalized header names.\n *\n * @defaultValue false\n */\n preserveHeaderCase?: boolean;\n\n /**\n * A list of additional `accept` headers to include in the request,\n * as defined in\n * https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2\n *\n * @example\n * ```javascript\n * [\"application/custom+json;q=1.0\"]\n * ```\n */\n accept?: string[];\n }\n\n /**\n * Options for the `HttpLink` constructor.\n */\n export interface Options {\n /**\n * The URI to use when fetching operations.\n *\n * Defaults to '/graphql'.\n */\n uri?: string | UriFunction;\n\n /**\n * Passes the extensions field to your graphql server.\n *\n * Defaults to true.\n */\n includeExtensions?: boolean;\n\n /**\n * A `fetch`-compatible API to use when making requests.\n */\n fetch?: typeof fetch;\n\n /**\n * An object representing values to be sent as headers on the request.\n */\n headers?: Record<string, string>;\n\n /**\n * If set to true, header names won't be automatically normalized to\n * lowercase. This allows for non-http-spec-compliant servers that might\n * expect capitalized header names.\n */\n preserveHeaderCase?: boolean;\n\n /**\n * The credentials policy you want to use for the fetch call.\n */\n credentials?: string;\n\n /**\n * Any overrides of the fetch options argument to pass to the fetch call.\n */\n fetchOptions?: any;\n\n /**\n * If set to true, use the HTTP GET method for query operations. Mutations\n * will still use the method specified in fetchOptions.method (which defaults\n * to POST).\n */\n useGETForQueries?: boolean;\n\n /**\n * If set to true, the default behavior of stripping unused variables\n * from the request will be disabled.\n *\n * Unused variables are likely to trigger server-side validation errors,\n * per https://spec.graphql.org/draft/#sec-All-Variables-Used, but this\n * includeUnusedVariables option can be useful if your server deviates\n * from the GraphQL specification by not strictly enforcing that rule.\n */\n includeUnusedVariables?: boolean;\n /**\n * A function to substitute for the default query print function. Can be\n * used to apply changes to the results of the print function.\n */\n print?: Printer;\n }\n\n interface Body {\n query?: string;\n operationName?: string;\n variables?: Record<string, any>;\n extensions?: Record<string, any>;\n }\n\n type Printer = (node: ASTNode, originalPrint: typeof print) => string;\n type UriFunction = (operation: Operation) => string;\n}\n\nexport class HttpLink extends ApolloLink {\n constructor(options: HttpLink.Options & ClientAwarenessLink.Options = {}) {\n const { left, right, request } = ApolloLink.concat(\n new ClientAwarenessLink(options),\n new BaseHttpLink(options)\n );\n super(request);\n Object.assign(this, { left, right });\n }\n}\n\n/**\n * @deprecated\n * Use `HttpLink` from `@apollo/client/link/http` instead.\n */\nexport const createHttpLink = (\n linkOptions: HttpLink.Options & ClientAwarenessLink.Options = {}\n) => new HttpLink(linkOptions);\n"]}
|
package/package.json
CHANGED
|
@@ -113,6 +113,10 @@ export declare namespace useBackgroundQuery {
|
|
|
113
113
|
/**
|
|
114
114
|
* Update the variables of this observable query, and fetch the new results. This method should be preferred over `setVariables` in most use cases.
|
|
115
115
|
*
|
|
116
|
+
* Returns a `ResultPromise` with an additional `.retain()` method. Calling `.retain()` keeps the network operation running even if the `ObservableQuery` no longer requires the result.
|
|
117
|
+
*
|
|
118
|
+
* Note: `refetch()` guarantees that a value will be emitted from the observable, even if the result is deep equal to the previous value.
|
|
119
|
+
*
|
|
116
120
|
* @param variables - The new set of variables. If there are missing variables, the previous values of those variables will be used.
|
|
117
121
|
*/
|
|
118
122
|
refetch: RefetchFunction<TData, TVariables>;
|
|
@@ -38,7 +38,7 @@ function useFragment_(options) {
|
|
|
38
38
|
...stableOptions,
|
|
39
39
|
returnPartialData: true,
|
|
40
40
|
id: from,
|
|
41
|
-
query: cache["getFragmentDoc"](fragment, fragmentName),
|
|
41
|
+
query: cache["getFragmentDoc"](client["transform"](fragment), fragmentName),
|
|
42
42
|
optimistic,
|
|
43
43
|
});
|
|
44
44
|
return {
|
|
@@ -62,17 +62,12 @@ function useFragment_(options) {
|
|
|
62
62
|
null
|
|
63
63
|
: client.watchFragment(stableOptions).subscribe({
|
|
64
64
|
next: (result) => {
|
|
65
|
-
//
|
|
66
|
-
// unnecessarily rerendering this hook for the initial result
|
|
65
|
+
// Avoid unnecessarily rerendering this hook for the initial result
|
|
67
66
|
// emitted from watchFragment which should be equal to
|
|
68
67
|
// `diff.result`.
|
|
69
|
-
|
|
70
|
-
...result,
|
|
71
|
-
dataState: result.complete ? "complete" : "partial",
|
|
72
|
-
};
|
|
73
|
-
if (equal(resultWithDataState, diff.result))
|
|
68
|
+
if (equal(result, diff.result))
|
|
74
69
|
return;
|
|
75
|
-
diff.result =
|
|
70
|
+
diff.result = result;
|
|
76
71
|
// If we get another update before we've re-rendered, bail out of
|
|
77
72
|
// the update and try again. This ensures that the relative timing
|
|
78
73
|
// between useQuery and useFragment stays roughly the same as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAgEjE,MAAM,UAAU,WAAW,CAGzB,OAA+C;IAC/C,a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QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;qBACvB,CAAC;oBAC/B,IAAI,KAAK,CAAC,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC;wBAAE,OAAO;oBACpD,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC;oBAClC,iEAAiE;oBACjE,kEAAkE;oBAClE,6DAA6D;oBAC7D,qEAAqE;oBACrE,YAAY,CAAC,WAAW,CAAC,CAAC;oBAC1B,WAAW,GAAG,UAAU,CAAC,WAAW,CAAQ,CAAC;gBAC/C,CAAC;aACF,CAAC,CAAC;QACP,OAAO,GAAG,EAAE;YACV,YAAY,EAAE,WAAW,EAAE,CAAC;YAC5B,YAAY,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAC9B,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;QACzB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;KACrB,CAAC,CAAC,uDAAuD;IAEvF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import equal from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloClient,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type {\n Cache,\n MissingTree,\n Reference,\n StoreObject,\n} from \"@apollo/client/cache\";\nimport type { FragmentType, MaybeMasked } from \"@apollo/client/masking\";\nimport type { NoInfer } from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n export interface Options<TData, TVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: NoInfer<TVariables>;\n\n from:\n | StoreObject\n | Reference\n | FragmentType<NoInfer<TData>>\n | string\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n complete: true;\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | ({\n complete: false;\n missing?: MissingTree;\n } & GetDataState<MaybeMasked<TData>, \"partial\">);\n}\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> {\n const client = useApolloClient(options.client);\n const { cache } = client;\n const { from, ...rest } = options;\n\n // We calculate the cache id seperately from `stableOptions` because we don't\n // want changes to non key fields in the `from` property to affect\n // `stableOptions` and retrigger our subscription. If the cache identifier\n // stays the same between renders, we want to reuse the existing subscription.\n const id = React.useMemo(\n () =>\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from),\n [cache, from]\n );\n\n const stableOptions = useDeepMemo(() => ({ ...rest, from: id! }), [rest, id]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n const diff = React.useMemo(() => {\n const { fragment, fragmentName, from, optimistic = true } = stableOptions;\n\n if (from === null) {\n return {\n result: diffToResult({\n result: {},\n complete: false,\n } as Cache.DiffResult<TData>),\n };\n }\n\n const { cache } = client;\n const diff = cache.diff<TData, TVariables>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n });\n\n return {\n result: diffToResult<TData>({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n // TODO: Revert to `diff.result` once `useFragment` supports `null` as\n // valid return value\n data: diff.result === null ? {} : diff.result,\n }) as any,\n }),\n };\n }, [client, stableOptions]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => diff.result, [diff]);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n\n const subscription =\n stableOptions.from === null ?\n null\n : client.watchFragment(stableOptions).subscribe({\n next: (result) => {\n // Since `next` is called async by zen-observable, we want to avoid\n // unnecessarily rerendering this hook for the initial result\n // emitted from watchFragment which should be equal to\n // `diff.result`.\n const resultWithDataState = {\n ...result,\n dataState: result.complete ? \"complete\" : \"partial\",\n } as useFragment.Result<TData>;\n if (equal(resultWithDataState, diff.result)) return;\n diff.result = resultWithDataState;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n });\n return () => {\n subscription?.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [client, stableOptions, diff]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): useFragment.Result<TData> {\n const result = {\n data: diff.result,\n complete: !!diff.complete,\n dataState: diff.complete ? \"complete\" : \"partial\",\n } as useFragment.Result<TData>; // TODO: Remove assertion once useFragment returns null\n\n if (diff.missing) {\n result.missing = diff.missing.missing;\n }\n\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAgEjE,MAAM,UAAU,WAAW,CAGzB,OAA+C;IAC/C,aAAa,CAAC;IACd,OAAO,QAAQ,CACb,aAAa;IACb,yDAAyD;IACzD,YAAY,EACZ,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAChC,CAAC,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CACnB,OAA+C;IAE/C,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAElC,6EAA6E;IAC7E,kEAAkE;IAClE,0EAA0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,IAAI,CAAC,CAC9B,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;QACzB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;KACrB,CAAC,CAAC,uDAAuD;IAEvF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import equal from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloClient,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type {\n Cache,\n MissingTree,\n Reference,\n StoreObject,\n} from \"@apollo/client/cache\";\nimport type { FragmentType, MaybeMasked } from \"@apollo/client/masking\";\nimport type { NoInfer } from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n export interface Options<TData, TVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: NoInfer<TVariables>;\n\n from:\n | StoreObject\n | Reference\n | FragmentType<NoInfer<TData>>\n | string\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n complete: true;\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | ({\n complete: false;\n missing?: MissingTree;\n } & GetDataState<MaybeMasked<TData>, \"partial\">);\n}\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> {\n const client = useApolloClient(options.client);\n const { cache } = client;\n const { from, ...rest } = options;\n\n // We calculate the cache id seperately from `stableOptions` because we don't\n // want changes to non key fields in the `from` property to affect\n // `stableOptions` and retrigger our subscription. If the cache identifier\n // stays the same between renders, we want to reuse the existing subscription.\n const id = React.useMemo(\n () =>\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from),\n [cache, from]\n );\n\n const stableOptions = useDeepMemo(() => ({ ...rest, from: id! }), [rest, id]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n const diff = React.useMemo(() => {\n const { fragment, fragmentName, from, optimistic = true } = stableOptions;\n\n if (from === null) {\n return {\n result: diffToResult({\n result: {},\n complete: false,\n } as Cache.DiffResult<TData>),\n };\n }\n\n const { cache } = client;\n const diff = cache.diff<TData, TVariables>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](\n client[\"transform\"](fragment),\n fragmentName\n ),\n optimistic,\n });\n\n return {\n result: diffToResult<TData>({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n // TODO: Revert to `diff.result` once `useFragment` supports `null` as\n // valid return value\n data: diff.result === null ? {} : diff.result,\n }) as any,\n }),\n };\n }, [client, stableOptions]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => diff.result, [diff]);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n\n const subscription =\n stableOptions.from === null ?\n null\n : client.watchFragment(stableOptions).subscribe({\n next: (result) => {\n // Avoid unnecessarily rerendering this hook for the initial result\n // emitted from watchFragment which should be equal to\n // `diff.result`.\n if (equal(result, diff.result)) return;\n diff.result = result;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n });\n return () => {\n subscription?.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [client, stableOptions, diff]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): useFragment.Result<TData> {\n const result = {\n data: diff.result,\n complete: !!diff.complete,\n dataState: diff.complete ? \"complete\" : \"partial\",\n } as useFragment.Result<TData>; // TODO: Remove assertion once useFragment returns null\n\n if (diff.missing) {\n result.missing = diff.missing.missing;\n }\n\n return result;\n}\n"]}
|
|
@@ -180,7 +180,7 @@ export declare namespace useLazyQuery {
|
|
|
180
180
|
*/
|
|
181
181
|
previousData?: MaybeMasked<TData>;
|
|
182
182
|
/**
|
|
183
|
-
*
|
|
183
|
+
* A single ErrorLike object describing the error that occured during the latest query execution.
|
|
184
184
|
*
|
|
185
185
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
186
186
|
*
|
|
@@ -249,6 +249,10 @@ export declare namespace useLazyQuery {
|
|
|
249
249
|
data: undefined;
|
|
250
250
|
/**
|
|
251
251
|
* Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
|
|
252
|
+
*
|
|
253
|
+
* @docGroup
|
|
254
|
+
*
|
|
255
|
+
* 1. Operation data
|
|
252
256
|
*/
|
|
253
257
|
dataState: "empty";
|
|
254
258
|
});
|