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