UniqueFragmentNamesRule.js 944 B

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