UniqueArgumentNames.js 1.1 KB

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