get-arguments-with-directives.js 1.5 KB

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