UniqueOperationNamesRule.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.UniqueOperationNamesRule = UniqueOperationNamesRule;
  6. var _GraphQLError = require("../../error/GraphQLError.js");
  7. /**
  8. * Unique operation names
  9. *
  10. * A GraphQL document is only valid if all defined operations have unique names.
  11. */
  12. function UniqueOperationNamesRule(context) {
  13. var knownOperationNames = Object.create(null);
  14. return {
  15. OperationDefinition: function OperationDefinition(node) {
  16. var operationName = node.name;
  17. if (operationName) {
  18. if (knownOperationNames[operationName.value]) {
  19. context.reportError(new _GraphQLError.GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
  20. } else {
  21. knownOperationNames[operationName.value] = operationName;
  22. }
  23. }
  24. return false;
  25. },
  26. FragmentDefinition: function FragmentDefinition() {
  27. return false;
  28. }
  29. };
  30. }