KnownFragmentNames.mjs 676 B

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