import { GraphQLFieldResolver } from 'graphql'; import { GeneContext } from 'graphql-gene/context'; import { FindOptionsHandler, FindOptionsHandlerByType, FindOptionsStateByModel, GraphQLFieldName, GraphqlReturnTypes, GraphqlToTypescript, GraphqlTypeName, GraphQLVarType, InferFields, Narrow, OperatorInputs, Prop, PrototypeOrNot, SomeRequired, TypeOrFunction, ValidGraphqlType } from './types'; import { GENE_RESOLVER_TEMPLATES, QUERY_ORDER_ENUM } from './constants'; type ArgsDefinition = Record | `${GENE_RESOLVER_TEMPLATES}` | undefined; export type StrictArgsDefinition = ArgsDefinition>; export type GeneConfigTypes | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = readonly string[] | (GeneObjectTypeConfig & { geneConfig?: GeneConfig; }); export type GeneObjectTypeConfig | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = Record | GeneTypeConfig>; type FallbackIfInvalid = T extends never ? TFallback : T; type AccurateTypeSource | undefined> = TTypeName extends 'Query' | 'Mutation' ? undefined : TTypeName extends string ? FallbackIfInvalid>, TFallbackSource> : TFallbackSource; export type ExtendedTypes | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = { [typeName in GraphqlTypeName]?: Record, TContext, undefined extends TArgDefs ? ArgsDefinition : TArgDefs, TReturnType extends unknown ? GraphqlReturnTypes : TReturnType>>; }; export type NarrowExtendedTypes>> = { [TypeName in keyof TTypes]?: { [FieldName in keyof TTypes[TypeName]]: ExtendedTypeField; }; }; type ValidReturnTypeOption = Narrow extends GraphqlReturnTypes ? Narrow : never; export type ExtendedTypeField = { [K in keyof T]: K extends 'resolver' ? GeneResolverOption, GeneContext, Prop extends ArgsDefinition ? Prop : never, ValidReturnTypeOption>> : K extends 'returnType' ? ValidReturnTypeOption : K extends 'args' ? T[K] extends StrictArgsDefinition ? Narrow : never : K extends 'findOptions' ? FindOptionsHandlerByType : Narrow; }; export type StrictExtendedTypes | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined> = ExtendedTypes>; export interface GeneConfig | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown, TVarType extends GraphQLVarType = GraphQLVarType> { /** Array of fields to include in the GraphQL type (default: include all). */ include?: (InferFields | RegExp)[]; /** Array of fields to exclude in the GraphQL type (default: ['createdAt', updatedAt']). */ exclude?: (InferFields | RegExp)[]; /** To include the timestamp attributes or not (default: false). */ includeTimestamps?: boolean | ('createdAt' | 'updatedAt')[]; /** The GraphQL variable type to use (default: "type"). */ varType?: TVarType; /** Directives to apply at the type level (also possible at the field level). */ directives?: TypeOrFunction | undefined, TSource extends M ? PrototypeOrNot : TSource>[]>; /** * The values of "aliases" would be nested GeneConfig properties that overwrites the ones se * at a higher level. This is useful for instances with a specific scope include more fields * that the parent model (i.e. `AuthenticatedUser` being an alias of `User`). Note that the * alias needs to be exported from _graphqlTypes.ts_ as well. * * @example * include: ['id', 'username'], * * aliases: { * AuthenticatedUser: { * include: ['id', 'email', 'username', 'role', 'address', 'orders'], * }, * }, * * @example * export { User as AuthenticatedUser } from '../models/User/User.model' */ aliases?: { [modelKey in GraphqlTypeName]?: GeneConfig; }; /** * Extend the Query or Mutation types only. * @deprecated You should import and call `extendTypes` instead. */ types?: ExtendedTypes; findOptions?: FindOptionsHandler>; } export type GeneTypeConfig | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = { directives?: TypeOrFunction | undefined, TSource>[]>; args?: TArgDefs extends undefined ? undefined : TArgDefs; resolver?: GeneResolverOption; returnType: TReturnType extends unknown ? GraphqlReturnTypes : TReturnType; findOptions?: FindOptionsHandler; }; export type FieldConfig | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = GraphqlReturnTypes | SomeRequired, 'resolver'>; type GeneResolverOption | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown> = GeneResolver, TReturnType extends string ? GraphqlToTypescript : unknown> | `${GENE_RESOLVER_TEMPLATES}`; export type GeneResolver | undefined, TContext = GeneContext, TArgs = Record | undefined, TResult = unknown> = (options: { source: Parameters>[0]; args: Parameters>[1]; context: Parameters>[2]; info: Parameters>[3]; }) => TResult | Promise; export type FieldConfigArgsOption = TArgDefs extends `${GENE_RESOLVER_TEMPLATES.default}` ? GeneDefaultResolverArgs> : unknown> : TArgDefs extends undefined ? Record | undefined : { [k in keyof Narrow]: Narrow[k] extends string ? GraphqlToTypescript[k]> : unknown; }; export type ArgsTypeToGraphQL = { [k in keyof Required]: Required[k] extends number ? 'Int' : k extends 'where' | 'order' ? string : Required[k] extends string ? 'String' : Required[k] extends boolean ? 'Boolean' : never; }; export type GeneDefaultResolverArgs = { page: number; perPage: number; locale?: string; id?: string; where: { [k in keyof M]: Exclude extends string | number | bigint | boolean ? OperatorInputs> : never; }; order?: keyof M extends string ? `${keyof M}_${QUERY_ORDER_ENUM}`[] : never; }; export type GeneDirective | undefined, TContext = GeneContext, TArgs = Record | undefined> = TDirectiveArgs extends undefined ? (args?: TDirectiveArgs) => GeneDirectiveConfig : (args: TDirectiveArgs) => GeneDirectiveConfig; export type GeneDirectiveConfig | undefined, TSource = Record | undefined, TContext = GeneContext, TArgs = Record | undefined> = TDirectiveArgs extends undefined ? { name: string; args?: TDirectiveArgs; handler: GeneDirectiveHandler; } : { name: string; args: TDirectiveArgs; handler: GeneDirectiveHandler; }; export type GeneDirectiveHandler | undefined, TContext = GeneContext, TArgs = Record | undefined, TResult = unknown> = (options: { source: Parameters>[0]; args: Parameters>[1]; context: Parameters>[2]; info: Parameters>[3]; field: string; filter: (callback: (value: TValue) => unknown) => void; resolve: () => Promise | TResult; }) => Promise | void; export declare class GeneModel { static geneConfig?: GeneConfig; } /** * Provide typing and default values to GeneConfig. You need to pass the model class as the first * argument to ensure accurate types for "include" and "exclude" options (they only accept regular * expressions or one of the model field name as string). * * @default geneConfig.exclude - ['createdAt', 'updatedAt'] */ export declare function defineGraphqlGeneConfig | undefined, TContext = GeneContext, TArgDefs extends ArgsDefinition = undefined, TReturnType extends string | unknown = unknown, TVarType extends GraphQLVarType = 'type'>(_model: M, options: GeneConfig): GeneConfig; export declare function defineDirective | undefined, TContext = GeneContext, TArgs = Record | undefined>(directive: GeneDirective): GeneDirective | undefined, TContext, TArgs>; /** * @deprecated Field config passed to `extendTypes` don't need to be wrapped with `defineField` * anymore in order to be accurate (they are now even better typed without it). */ export declare function defineField | undefined, TArgDefs extends StrictArgsDefinition, TReturnType extends GraphqlReturnTypes, TContext = GeneContext>(config: Narrow, 'args' | 'returnType'>): FieldConfig; export declare function defineType, TSource, TContext, TArgDefs extends ArgsDefinition, TVarType extends GraphQLVarType>(config: T, geneConfig?: GeneConfig): T; export declare function defineInput, TSource, TContext, TArgDefs extends ArgsDefinition>(config: T): T & { geneConfig: GeneConfig<{}, Record | {} | undefined, GeneContext, undefined, unknown, "input">; }; export declare function defineEnum(values: TValue[]): TValue[]; export declare function defineUnion(unions: TUnion[]): Required>> & { geneConfig: GeneConfig<{}, Record | {} | undefined, GeneContext, undefined, unknown, "union">; }; export {};