1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getFieldsWithDirectives = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | function getFieldsWithDirectives(documentNode, options = {}) {
|
6 | const result = {};
|
7 | let selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
|
8 | if (options.includeInputTypes) {
|
9 | selected = [...selected, 'InputObjectTypeDefinition', 'InputObjectTypeExtension'];
|
10 | }
|
11 | const allTypes = documentNode.definitions.filter(obj => selected.includes(obj.kind));
|
12 | for (const type of allTypes) {
|
13 | const typeName = type.name.value;
|
14 | if (type.fields == null) {
|
15 | continue;
|
16 | }
|
17 | for (const field of type.fields) {
|
18 | if (field.directives && field.directives.length > 0) {
|
19 | const fieldName = field.name.value;
|
20 | const key = `${typeName}.${fieldName}`;
|
21 | const directives = field.directives.map(d => ({
|
22 | name: d.name.value,
|
23 | args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]: (0, graphql_1.valueFromASTUntyped)(arg.value) }), {}),
|
24 | }));
|
25 | result[key] = directives;
|
26 | }
|
27 | }
|
28 | }
|
29 | return result;
|
30 | }
|
31 | exports.getFieldsWithDirectives = getFieldsWithDirectives;
|