UniqueArgumentNamesRule.js 977 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.UniqueArgumentNamesRule = UniqueArgumentNamesRule;
  6. var _GraphQLError = require("../../error/GraphQLError.js");
  7. /**
  8. * Unique argument names
  9. *
  10. * A GraphQL field or directive is only valid if all supplied arguments are
  11. * uniquely named.
  12. */
  13. function UniqueArgumentNamesRule(context) {
  14. var knownArgNames = Object.create(null);
  15. return {
  16. Field: function Field() {
  17. knownArgNames = Object.create(null);
  18. },
  19. Directive: function Directive() {
  20. knownArgNames = Object.create(null);
  21. },
  22. Argument: function Argument(node) {
  23. var argName = node.name.value;
  24. if (knownArgNames[argName]) {
  25. context.reportError(new _GraphQLError.GraphQLError("There can be only one argument named \"".concat(argName, "\"."), [knownArgNames[argName], node.name]));
  26. } else {
  27. knownArgNames[argName] = node.name;
  28. }
  29. return false;
  30. }
  31. };
  32. }