KnownFragmentNamesRule.js 732 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.KnownFragmentNamesRule = KnownFragmentNamesRule;
  6. var _GraphQLError = require("../../error/GraphQLError.js");
  7. /**
  8. * Known fragment names
  9. *
  10. * A GraphQL document is only valid if all `...Fragment` fragment spreads refer
  11. * to fragments defined in the same document.
  12. */
  13. function KnownFragmentNamesRule(context) {
  14. return {
  15. FragmentSpread: function FragmentSpread(node) {
  16. var fragmentName = node.name.value;
  17. var fragment = context.getFragment(fragmentName);
  18. if (!fragment) {
  19. context.reportError(new _GraphQLError.GraphQLError("Unknown fragment \"".concat(fragmentName, "\"."), node.name));
  20. }
  21. }
  22. };
  23. }