UNPKG

1.76 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.TypeFieldsAccessor = void 0;
4const tslib_1 = require("tslib");
5const common_1 = require("@nestjs/common");
6const lodash_1 = require("lodash");
7let TypeFieldsAccessor = class TypeFieldsAccessor {
8 extractFromInputType(gqlType) {
9 const fieldsMap = gqlType.getFields();
10 const fieldsConfig = {};
11 for (const key in fieldsMap) {
12 const targetField = fieldsMap[key];
13 fieldsConfig[key] = {
14 type: targetField.type,
15 description: targetField.description,
16 defaultValue: targetField.defaultValue,
17 astNode: targetField.astNode,
18 extensions: targetField.extensions,
19 };
20 }
21 return fieldsConfig;
22 }
23 extractFromInterfaceOrObjectType(type) {
24 const fieldsMap = type.getFields();
25 const fieldsConfig = {};
26 for (const key in fieldsMap) {
27 const targetField = fieldsMap[key];
28 const args = {};
29 targetField.args.forEach((item) => {
30 args[item.name] = (0, lodash_1.omit)(item, 'name');
31 });
32 fieldsConfig[key] = {
33 type: targetField.type,
34 description: targetField.description,
35 deprecationReason: targetField.deprecationReason,
36 extensions: targetField.extensions,
37 astNode: targetField.astNode,
38 resolve: targetField.resolve,
39 args,
40 };
41 }
42 return fieldsConfig;
43 }
44};
45TypeFieldsAccessor = tslib_1.__decorate([
46 (0, common_1.Injectable)()
47], TypeFieldsAccessor);
48exports.TypeFieldsAccessor = TypeFieldsAccessor;