KnownFragmentNamesRule.mjs 588 B

1234567891011121314151617181920
  1. import { GraphQLError } from "../../error/GraphQLError.mjs";
  2. /**
  3. * Known fragment names
  4. *
  5. * A GraphQL document is only valid if all `...Fragment` fragment spreads refer
  6. * to fragments defined in the same document.
  7. */
  8. export function KnownFragmentNamesRule(context) {
  9. return {
  10. FragmentSpread: function FragmentSpread(node) {
  11. var fragmentName = node.name.value;
  12. var fragment = context.getFragment(fragmentName);
  13. if (!fragment) {
  14. context.reportError(new GraphQLError("Unknown fragment \"".concat(fragmentName, "\"."), node.name));
  15. }
  16. }
  17. };
  18. }