UNPKG

1.87 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.NestedFields = exports.Fields = void 0;
4var graphqlFields = require("graphql-fields");
5var type_graphql_1 = require("type-graphql");
6function Fields() {
7 return type_graphql_1.createParamDecorator(function (_a) {
8 var info = _a.info;
9 // This object will be of the form:
10 // rawFields {
11 // baseField: {},
12 // association: { subField: "foo"}
13 // }
14 // We need to pull out items with subFields
15 var rawFields = graphqlFields(info);
16 var scalars = Object.keys(rawFields).filter(function (item) {
17 return Object.keys(rawFields[item]).length === 0 && !item.startsWith('__');
18 });
19 return scalars;
20 });
21}
22exports.Fields = Fields;
23function NestedFields() {
24 return type_graphql_1.createParamDecorator(function (_a) {
25 var info = _a.info;
26 // This object will be of the form:
27 // rawFields {
28 // baseField: {},
29 // association: { subField: "foo"}
30 // }
31 // We need to pull out items with subFields
32 var rawFields = graphqlFields(info);
33 var output = { scalars: [] };
34 var _loop_1 = function (fieldKey) {
35 if (Object.keys(rawFields[fieldKey]).length === 0) {
36 output.scalars.push(fieldKey);
37 }
38 else {
39 var subFields_1 = rawFields[fieldKey];
40 output[fieldKey] = Object.keys(subFields_1).filter(function (subKey) {
41 return Object.keys(subFields_1[subKey]).length === 0;
42 });
43 }
44 };
45 for (var fieldKey in rawFields) {
46 _loop_1(fieldKey);
47 }
48 return output;
49 });
50}
51exports.NestedFields = NestedFields;
52//# sourceMappingURL=Fields.js.map
\No newline at end of file