Skip to content

Commit

Permalink
Add a new useLoadableQuery hook (#11300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 28, 2023
1 parent d9ca4f0 commit a815873
Show file tree
Hide file tree
Showing 25 changed files with 5,553 additions and 95 deletions.
78 changes: 74 additions & 4 deletions .api-reports/api-report-react.md
Expand Up @@ -1018,6 +1018,38 @@ export type LazyQueryResultTuple<TData, TVariables extends OperationVariables> =
// @public (undocumented)
type Listener<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;

// @public (undocumented)
export type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;

// @public (undocumented)
export interface LoadableQueryHookOptions {
// (undocumented)
canonizeResults?: boolean;
// (undocumented)
client?: ApolloClient<any>;
// (undocumented)
context?: Context;
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
errorPolicy?: ErrorPolicy;
// (undocumented)
fetchPolicy?: LoadableQueryHookFetchPolicy;
// (undocumented)
queryKey?: string | number | any[];
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
refetchWritePolicy?: RefetchWritePolicy;
// (undocumented)
returnPartialData?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "OnlyRequiredProperties" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type LoadQueryFunction<TVariables extends OperationVariables> = (...args: [TVariables] extends [never] ? [] : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables] : [variables: TVariables]) => void;

// @public (undocumented)
class LocalState<TCacheShape> {
// Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1119,8 +1151,6 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
awaitRefetchQueries?: boolean;
// (undocumented)
context?: TContext;
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1361,6 +1391,11 @@ export interface OnDataOptions<TData = any> {
data: SubscriptionResult<TData>;
}

// @public (undocumented)
type OnlyRequiredProperties<T> = {
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
};

// @public (undocumented)
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;

Expand Down Expand Up @@ -1800,6 +1835,9 @@ type RequestHandler = (operation: Operation, forward: NextLink) => Observable<Fe
// @public (undocumented)
export const resetApolloContext: typeof getApolloContext;

// @public (undocumented)
type ResetFunction = () => void;

// @public (undocumented)
type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
field: FieldNode;
Expand Down Expand Up @@ -2092,6 +2130,39 @@ export type UseFragmentResult<TData> = {
// @public (undocumented)
export function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): LazyQueryResultTuple<TData, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData, TVariables extends OperationVariables, TOptions extends LoadableQueryHookOptions>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions & TOptions): UseLoadableQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
returnPartialData: true;
errorPolicy: "ignore" | "all";
}): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
errorPolicy: "ignore" | "all";
}): UseLoadableQueryResult<TData | undefined, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
returnPartialData: true;
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;

// @public (undocumented)
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
LoadQueryFunction<TVariables>,
QueryReference<TData> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
reset: ResetFunction;
}
];

// @public (undocumented)
export function useMutation<TData = any, TVariables = OperationVariables, TContext = Context, TCache extends ApolloCache<any> = ApolloCache<any>>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: MutationHookOptions<NoInfer<TData>, NoInfer<TVariables>, TContext, TCache>): MutationTuple<TData, TVariables, TContext, TCache>;

Expand Down Expand Up @@ -2193,8 +2264,6 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
//
// (undocumented)
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
refetchWritePolicy?: RefetchWritePolicy;
}
Expand All @@ -2221,6 +2290,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:26:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:27:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:51:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
82 changes: 78 additions & 4 deletions .api-reports/api-report-react_hooks.md
Expand Up @@ -969,6 +969,40 @@ type LazyQueryResultTuple<TData, TVariables extends OperationVariables> = [LazyQ
// @public (undocumented)
type Listener<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;

// @public (undocumented)
type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;

// @public (undocumented)
interface LoadableQueryHookOptions {
// (undocumented)
canonizeResults?: boolean;
// (undocumented)
client?: ApolloClient<any>;
// (undocumented)
context?: DefaultContext;
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "LoadableQueryHookFetchPolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
fetchPolicy?: LoadableQueryHookFetchPolicy;
// (undocumented)
queryKey?: string | number | any[];
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
refetchWritePolicy?: RefetchWritePolicy;
// (undocumented)
returnPartialData?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "OnlyRequiredProperties" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type LoadQueryFunction<TVariables extends OperationVariables> = (...args: [TVariables] extends [never] ? [] : {} extends OnlyRequiredProperties<TVariables> ? [variables?: TVariables] : [variables: TVariables]) => void;

// @public (undocumented)
class LocalState<TCacheShape> {
// Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1070,8 +1104,6 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
awaitRefetchQueries?: boolean;
// (undocumented)
context?: TContext;
// Warning: (ae-forgotten-export) The symbol "ErrorPolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1310,6 +1342,11 @@ interface OnDataOptions<TData = any> {
data: SubscriptionResult<TData>;
}

// @public (undocumented)
type OnlyRequiredProperties<T> = {
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
};

// @public (undocumented)
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;

Expand Down Expand Up @@ -1696,6 +1733,9 @@ type RefetchWritePolicy = "merge" | "overwrite";
// @public (undocumented)
type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;

// @public (undocumented)
type ResetFunction = () => void;

// @public (undocumented)
type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
field: FieldNode;
Expand Down Expand Up @@ -1979,6 +2019,41 @@ export type UseFragmentResult<TData> = {
// @public (undocumented)
export function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): LazyQueryResultTuple<TData, TVariables>;

// Warning: (ae-forgotten-export) The symbol "LoadableQueryHookOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function useLoadableQuery<TData, TVariables extends OperationVariables, TOptions extends LoadableQueryHookOptions>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions & TOptions): UseLoadableQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
returnPartialData: true;
errorPolicy: "ignore" | "all";
}): UseLoadableQueryResult<DeepPartial<TData> | undefined, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
errorPolicy: "ignore" | "all";
}): UseLoadableQueryResult<TData | undefined, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: LoadableQueryHookOptions & {
returnPartialData: true;
}): UseLoadableQueryResult<DeepPartial<TData>, TVariables>;

// @public (undocumented)
export function useLoadableQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LoadableQueryHookOptions): UseLoadableQueryResult<TData, TVariables>;

// @public (undocumented)
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
LoadQueryFunction<TVariables>,
QueryReference<TData> | null,
{
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
reset: ResetFunction;
}
];

// Warning: (ae-forgotten-export) The symbol "MutationHookOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MutationTuple" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -2087,8 +2162,6 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
//
// (undocumented)
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
// Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
//
// (undocumented)
refetchWritePolicy?: RefetchWritePolicy;
}
Expand All @@ -2115,6 +2188,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:26:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:27:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:51:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
5 changes: 5 additions & 0 deletions .api-reports/api-report-utilities.md
Expand Up @@ -1803,6 +1803,11 @@ export function offsetLimitPagination<T = Reference>(keyArgs?: KeyArgs): FieldPo
// @public (undocumented)
export function omitDeep<T, K extends string>(value: T, key: K): DeepOmit<T, K>;

// @public (undocumented)
export type OnlyRequiredProperties<T> = {
[K in keyof T as {} extends Pick<T, K> ? never : K]: T[K];
};

// @public (undocumented)
type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => boolean | TResult;

Expand Down

0 comments on commit a815873

Please sign in to comment.