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