1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Query = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | require("reflect-metadata");
|
6 | const resolver_enum_1 = require("../enums/resolver.enum");
|
7 | const undefined_return_type_error_1 = require("../schema-builder/errors/undefined-return-type.error");
|
8 | const lazy_metadata_storage_1 = require("../schema-builder/storages/lazy-metadata.storage");
|
9 | const type_metadata_storage_1 = require("../schema-builder/storages/type-metadata.storage");
|
10 | const reflection_utilts_1 = require("../utils/reflection.utilts");
|
11 | const resolvers_utils_1 = require("./resolvers.utils");
|
12 |
|
13 |
|
14 |
|
15 | function Query(nameOrType, options = {}) {
|
16 | return (target, key, descriptor) => {
|
17 | const name = (0, shared_utils_1.isString)(nameOrType)
|
18 | ? nameOrType
|
19 | : (options && options.name) || undefined;
|
20 | (0, resolvers_utils_1.addResolverMetadata)(resolver_enum_1.Resolver.QUERY, name, target, key, descriptor);
|
21 | lazy_metadata_storage_1.LazyMetadataStorage.store(target.constructor, () => {
|
22 | if (!nameOrType || (0, shared_utils_1.isString)(nameOrType)) {
|
23 | throw new undefined_return_type_error_1.UndefinedReturnTypeError(Query.name, key);
|
24 | }
|
25 | const { typeFn, options: typeOptions } = (0, reflection_utilts_1.reflectTypeFromMetadata)({
|
26 | metadataKey: 'design:returntype',
|
27 | prototype: target,
|
28 | propertyKey: key,
|
29 | explicitTypeFn: nameOrType,
|
30 | typeOptions: options || {},
|
31 | });
|
32 | const metadata = {
|
33 | methodName: key,
|
34 | schemaName: options.name || key,
|
35 | target: target.constructor,
|
36 | typeFn,
|
37 | returnTypeOptions: typeOptions,
|
38 | description: options.description,
|
39 | deprecationReason: options.deprecationReason,
|
40 | complexity: options.complexity,
|
41 | };
|
42 | type_metadata_storage_1.TypeMetadataStorage.addQueryMetadata(metadata);
|
43 | });
|
44 | };
|
45 | }
|
46 | exports.Query = Query;
|