import { Complexity, FieldOptions } from '@nestjs/graphql'; import { Class } from '@ptc-org/nestjs-query-core'; import { AuthorizerOptions } from '../../auth'; import { DTONamesOpts } from '../../common'; import { ResolverMethodOpts } from '../../decorators'; import { ResolverRelationMethodOpts } from '../../decorators/resolver-method.decorator'; import { ConnectionOptions, QueryArgsTypeOpts } from '../../types'; export type ReferencesKeys = { [F in keyof Reference]?: keyof DTO; }; export interface ResolverRelationReference extends DTONamesOpts, ResolverMethodOpts { /** * The class type of the relation. */ DTO: Class; /** * Keys */ keys: ReferencesKeys; /** * Set to true if the relation is nullable */ nullable?: boolean; complexity?: Complexity; } export type ResolverRelation = { /** * The class type of the relation. */ DTO: Class; /** * The name of the relation to use when fetching from the QueryService */ relationName?: string; /** * Set to true if the relation is nullable */ nullable?: boolean; /** * Disable read relation graphql endpoints */ disableRead?: boolean; /** * Enable look ahead mode, will join and select the relation when queried. */ enableLookAhead?: boolean; /** * Indicates if soft-deleted rows should be included in relation result. */ withDeleted?: boolean; /** * Set to true if you should be able to filter on this relation. * * This will only work with relations defined through an ORM (typeorm or sequelize). */ allowFiltering?: boolean; /** * Description of the relation. */ description?: string; update?: Pick, 'description'> & ResolverRelationMethodOpts; remove?: Pick, 'description'> & ResolverRelationMethodOpts; /** * Enable aggregation queries. */ enableAggregate?: boolean; aggregate?: Pick, 'description'> & ResolverRelationMethodOpts; auth?: AuthorizerOptions; } & DTONamesOpts & ResolverMethodOpts & QueryArgsTypeOpts & Pick & Omit; export type RelationTypeMap = Record; export type ResolverOneRelation = Omit, 'disableFilter' | 'disableSort' | 'enableAggregate' | 'aggregate'>; export type ResolverManyRelation = Omit, 'enableLookAhead'>; export type RelationsOpts = { /** * All relations that are a single record */ one?: RelationTypeMap>; /** * All relations that have multiple records */ many?: RelationTypeMap>; }; export type ReferencesOpts = RelationTypeMap>;