sangria.validation.rules.KnownFragmentNames.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sangria_2.11 Show documentation
Show all versions of sangria_2.11 Show documentation
Scala GraphQL implementation
package sangria.validation.rules
import sangria.ast
import sangria.ast.AstVisitorCommand
import sangria.validation._
/**
* Known fragment names
*
* A GraphQL document is only valid if all `...Fragment` fragment spreads refer
* to fragments defined in the same document.
*/
class KnownFragmentNames extends ValidationRule {
override def visitor(ctx: ValidationContext) = new AstValidatingVisitor {
override val onEnter: ValidationVisit = {
case ast.FragmentSpread(name, _, _, pos) =>
ctx.doc.fragments.get(name) match {
case None => Left(Vector(UnknownFragmentViolation(name, ctx.sourceMapper, pos.toList)))
case _ => AstVisitorCommand.RightContinue
}
}
}
}