|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +exports.Field = Field; |
| 4 | +const errors_1 = require("../errors"); |
| 5 | +const decorators_1 = require("../helpers/decorators"); |
| 6 | +const findType_1 = require("../helpers/findType"); |
| 7 | +const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); |
| 8 | +function Field(returnTypeFuncOrOptions, maybeOptions) { |
| 9 | + return (prototype, propertyKey, descriptor) => { |
| 10 | + if (typeof propertyKey === "symbol") { |
| 11 | + throw new errors_1.SymbolKeysNotSupportedError(); |
| 12 | + } |
| 13 | + const { options, returnTypeFunc } = (0, decorators_1.getTypeDecoratorParams)(returnTypeFuncOrOptions, maybeOptions); |
| 14 | + const isResolver = Boolean(descriptor); |
| 15 | + const isResolverMethod = Boolean(descriptor && descriptor.value); |
| 16 | + const { getType, typeOptions } = (0, findType_1.findType)({ |
| 17 | + metadataKey: isResolverMethod ? "design:returntype" : "design:type", |
| 18 | + prototype, |
| 19 | + propertyKey, |
| 20 | + returnTypeFunc, |
| 21 | + typeOptions: options, |
| 22 | + }); |
| 23 | + (0, getMetadataStorage_1.getMetadataStorage)().collectClassFieldMetadata({ |
| 24 | + name: propertyKey, |
| 25 | + schemaName: options.name || propertyKey, |
| 26 | + getType, |
| 27 | + typeOptions, |
| 28 | + complexity: options.complexity, |
| 29 | + target: prototype.constructor, |
| 30 | + description: options.description, |
| 31 | + deprecationReason: options.deprecationReason, |
| 32 | + simple: options.simple, |
| 33 | + }); |
| 34 | + if (isResolver) { |
| 35 | + (0, getMetadataStorage_1.getMetadataStorage)().collectFieldResolverMetadata({ |
| 36 | + kind: "internal", |
| 37 | + methodName: propertyKey, |
| 38 | + schemaName: options.name || propertyKey, |
| 39 | + target: prototype.constructor, |
| 40 | + complexity: options.complexity, |
| 41 | + }); |
| 42 | + } |
| 43 | + }; |
| 44 | +} |
0 commit comments