UNPKG

2.12 kBJavaScriptView Raw
1"use strict";
2/**
3 * The API surface of this module has been heavily inspired by the "type-graphql" library (https://github.com/MichalLytek/type-graphql), originally designed & released by Michal Lytek.
4 * In the v6 major release of NestJS, we introduced the code-first approach as a compatibility layer between this package and the `@nestjs/graphql` module.
5 * Eventually, our team decided to reimplement all the features from scratch due to a lack of flexibility.
6 * To avoid numerous breaking changes, the public API is backward-compatible and may resemble "type-graphql".
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.InterfaceType = void 0;
10const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
11const class_type_enum_1 = require("../enums/class-type.enum");
12const lazy_metadata_storage_1 = require("../schema-builder/storages/lazy-metadata.storage");
13const type_metadata_storage_1 = require("../schema-builder/storages/type-metadata.storage");
14const add_class_type_metadata_util_1 = require("../utils/add-class-type-metadata.util");
15/**
16 * Decorator that marks a class as a GraphQL interface type.
17 */
18function InterfaceType(nameOrOptions, interfaceOptions) {
19 const [name, options = {}] = (0, shared_utils_1.isString)(nameOrOptions)
20 ? [nameOrOptions, interfaceOptions]
21 : [undefined, nameOrOptions];
22 return (target) => {
23 const addInterfaceMetadata = () => {
24 const metadata = {
25 name: name || target.name,
26 target,
27 ...options,
28 interfaces: options.implements,
29 };
30 type_metadata_storage_1.TypeMetadataStorage.addInterfaceMetadata(metadata);
31 };
32 // This function must be called eagerly to allow resolvers
33 // accessing the "name" property
34 addInterfaceMetadata();
35 lazy_metadata_storage_1.LazyMetadataStorage.store(() => addInterfaceMetadata());
36 (0, add_class_type_metadata_util_1.addClassTypeMetadata)(target, class_type_enum_1.ClassType.INTERFACE);
37 };
38}
39exports.InterfaceType = InterfaceType;