KnownFragmentNames.js 865 B

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