grafast
Version:
Cutting edge GraphQL planning and execution engine
85 lines • 4.86 kB
TypeScript
import type { ExecutionDetails } from "../index.js";
import type { GrafastResultsList, Maybe, PromiseOrDirect, Thunk } from "../interfaces.js";
import type { Multistep, UnwrapMultistep } from "../multistep.js";
import { Step } from "../step.js";
import type { IOEquivalence } from "./_loadCommon.js";
export interface LoadOneInfo<TItem, TParams extends Record<string, any>, TShared = never> {
shared: TShared;
attributes: ReadonlyArray<keyof TItem>;
params: Partial<TParams>;
/** @deprecated Please use 'shared' instead. It's simply renamed */
unary: TShared;
}
export type LoadOneCallback<TSpec, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, TUnarySpec = never> = {
(specs: ReadonlyArray<TSpec>, info: LoadOneInfo<TItem, TParams, TUnarySpec>): PromiseOrDirect<ReadonlyArray<TData>>;
displayName?: string;
};
/**
* A TypeScript Identity Function to help you strongly type your
* LoadOneCallback.
*/
export declare function loadOneCallback<TSpec, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, TUnarySpec = never>(load: LoadOneCallback<TSpec, TItem, TData, TParams, TUnarySpec>): LoadOneCallback<TSpec, TItem, TData, TParams, TUnarySpec>;
/**
* A TypeScript Identity Function to help you strongly type your
* LoadOneLoader.
*/
export declare function loadOneLoader<TSpec, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, TShared extends Multistep = never>(load: LoadOneLoader<TSpec, TItem, TData, TParams, TShared>): LoadOneLoader<TSpec, TItem, TData, TParams, TShared>;
export declare class LoadOneStep<const TLookup extends Multistep, TItem, TData extends Maybe<TItem>, TParams extends Record<string, any>, const TShared extends Multistep = never> extends Step<TData> {
static $$export: {
moduleName: string;
exportName: string;
};
isSyncAndSafe: boolean;
loadInfo: Omit<LoadOneInfo<TItem, TParams, UnwrapMultistep<TShared>>, "shared" | "unary" | "params"> | null;
loadInfoKey: string;
attributes: Set<keyof TItem>;
paramDepIdByKey: {
[TKey in keyof TParams]: number;
};
sharedDepId: number | null;
private ioEquivalence;
private load;
private name;
constructor(lookup: TLookup, loader: LoadOneLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>);
toStringMeta(): string | null;
private _accessMap;
private getAccessMap;
setParam<TParamKey extends keyof TParams>(paramKey: TParamKey, value: TParams[TParamKey] | Step<TParams[TParamKey]>): void;
addAttributes(attributes: Set<keyof TItem>): void;
deduplicate(peers: readonly LoadOneStep<any, any, any, any, any>[]): LoadOneStep<any, any, any, any, any>[];
deduplicatedWith(replacement: LoadOneStep<any, any, any, any, any>): void;
_paramSig?: string;
getParamSignature(): string;
finalize(): void;
execute(details: ExecutionDetails): PromiseOrDirect<GrafastResultsList<TData>>;
get(attr: keyof TItem & (string | number)): Step<any>;
private _getInner;
}
export interface LoadOneLoader<TSpec, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, TShared extends Multistep = never> {
/**
* The function that actually loads data from the backend
*/
load: LoadOneCallback<TSpec, TItem, TData, TParams, UnwrapMultistep<TShared>>;
/** Name your function (for plan diagrams/debugging) */
name?: string;
/**
* Details of anything your `load` function will need access to, for example
* database connections, API clients, etc.
*/
shared?: Thunk<TShared>;
/**
* Details of which attributes on the output are equivalent to those on the
* input (if any), useful for reducing unnecessary fetches (e.g. load the
* friends of a user by their id without ever loading the user).
*/
ioEquivalence?: IOEquivalence<TSpec>;
}
/**
* Loads an individual record identified by the `lookup` using the `loader`.
*
* @param lookup - A step/multistep representing the value to look up - could be an
* identifier or combination of identifiers.
* @param loader - The function to load this, or a LoadManyLoader object containing such a function
*/
export declare function loadOne<const TLookup extends Multistep, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, const TShared extends Multistep = never>(lookup: TLookup, loader: LoadOneCallback<UnwrapMultistep<TLookup>, TItem, TData, TParams, never> | LoadOneLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>): LoadOneStep<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>;
//# sourceMappingURL=loadOne.d.ts.map