1 | import { Kind, valueFromASTUntyped } from 'graphql';
|
2 | function isTypeWithFields(t) {
|
3 | return t.kind === Kind.OBJECT_TYPE_DEFINITION || t.kind === Kind.OBJECT_TYPE_EXTENSION;
|
4 | }
|
5 | export function getArgumentsWithDirectives(documentNode) {
|
6 | var _a;
|
7 | const result = {};
|
8 | const allTypes = documentNode.definitions.filter(isTypeWithFields);
|
9 | for (const type of allTypes) {
|
10 | if (type.fields == null) {
|
11 | continue;
|
12 | }
|
13 | for (const field of type.fields) {
|
14 | const argsWithDirectives = (_a = field.arguments) === null || _a === void 0 ? void 0 : _a.filter(arg => { var _a; return (_a = arg.directives) === null || _a === void 0 ? void 0 : _a.length; });
|
15 | if (!(argsWithDirectives === null || argsWithDirectives === void 0 ? void 0 : argsWithDirectives.length)) {
|
16 | continue;
|
17 | }
|
18 | const typeFieldResult = (result[`${type.name.value}.${field.name.value}`] = {});
|
19 | for (const arg of argsWithDirectives) {
|
20 | const directives = arg.directives.map(d => ({
|
21 | name: d.name.value,
|
22 | args: (d.arguments || []).reduce((prev, dArg) => ({ ...prev, [dArg.name.value]: valueFromASTUntyped(dArg.value) }), {}),
|
23 | }));
|
24 | typeFieldResult[arg.name.value] = directives;
|
25 | }
|
26 | }
|
27 | }
|
28 | return result;
|
29 | }
|