All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sangria.validation.rules.KnownFragmentNames.scala Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
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
         }
     }
   }
 }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy