UNPKG

1.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getArgumentsWithDirectives = void 0;
4const graphql_1 = require("graphql");
5function isTypeWithFields(t) {
6 return t.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION || t.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION;
7}
8function getArgumentsWithDirectives(documentNode) {
9 const result = {};
10 const allTypes = documentNode.definitions.filter(isTypeWithFields);
11 for (const type of allTypes) {
12 if (type.fields == null) {
13 continue;
14 }
15 for (const field of type.fields) {
16 const argsWithDirectives = field.arguments?.filter(arg => arg.directives?.length);
17 if (!argsWithDirectives?.length) {
18 continue;
19 }
20 const typeFieldResult = (result[`${type.name.value}.${field.name.value}`] = {});
21 for (const arg of argsWithDirectives) {
22 const directives = arg.directives.map(d => ({
23 name: d.name.value,
24 args: (d.arguments || []).reduce((prev, dArg) => ({ ...prev, [dArg.name.value]: (0, graphql_1.valueFromASTUntyped)(dArg.value) }), {}),
25 }));
26 typeFieldResult[arg.name.value] = directives;
27 }
28 }
29 }
30 return result;
31}
32exports.getArgumentsWithDirectives = getArgumentsWithDirectives;