import { ClassType } from "type-graphql"; import { findType, getMetadataStorage } from "../metadata"; import { ReturnTypeFunc } from "@nestjs/graphql"; export function Filterable( returnTypeFunc?: ReturnTypeFunc, option?: FilterableOption ): Function { return function (prototype: any, propertyKey: string): any { const { getType } = findType({ metadataKey: "design:type", prototype, propertyKey, returnTypeFunc, // @ts-ignore typeOptions: option, }); getMetadataStorage().collectClassFieldMetadata({ name: propertyKey, fieldType: option?.type ?? propertyKey, getType, typeOptions: null, target: prototype.constructor, objectType: prototype.constructor.name, methodName: propertyKey, }); }; } interface FilterableOption { type: ClassType | any; isEnum: boolean; }