UNPKG

1.57 kBTypeScriptView Raw
1import { FieldNode, GraphQLSchema } from 'graphql';
2import DataLoader from 'dataloader';
3import { IDelegateToSchemaOptions, SubschemaConfig } from '@graphql-tools/delegate';
4export declare type DataLoaderCache<K = any, V = any, C = K> = WeakMap<ReadonlyArray<FieldNode>, WeakMap<GraphQLSchema | SubschemaConfig, DataLoader<K, V, C>>>;
5export declare type BatchDelegateFn<TContext = Record<string, any>, K = any> = (batchDelegateOptions: BatchDelegateOptions<TContext, K>) => any;
6export declare type BatchDelegateOptionsFn<TContext = Record<string, any>, K = any> = (batchDelegateOptions: BatchDelegateOptions<TContext, K>) => IDelegateToSchemaOptions<TContext>;
7export interface BatchDelegateOptions<TContext = Record<string, any>, K = any, V = any, C = K> extends Omit<IDelegateToSchemaOptions<TContext>, 'args'> {
8 dataLoaderOptions?: DataLoader.Options<K, V, C>;
9 key: K;
10 argsFromKeys?: (keys: ReadonlyArray<K>) => Record<string, any>;
11 valuesFromResults?: (results: any, keys: ReadonlyArray<K>) => Array<V>;
12 lazyOptionsFn?: BatchDelegateOptionsFn;
13}
14export interface CreateBatchDelegateFnOptions<TContext = Record<string, any>, K = any, V = any, C = K> extends Partial<Omit<IDelegateToSchemaOptions<TContext>, 'args' | 'info'>> {
15 dataLoaderOptions?: DataLoader.Options<K, V, C>;
16 argsFromKeys?: (keys: ReadonlyArray<K>) => Record<string, any>;
17 valuesFromResults?: (results: any, keys: ReadonlyArray<K>) => Array<V>;
18 lazyOptionsFn?: (batchDelegateOptions: BatchDelegateOptions<TContext, K>) => IDelegateToSchemaOptions<TContext>;
19}