sangria.validation.rules.SingleFieldSubscriptions.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sangria-core_2.13 Show documentation
Show all versions of sangria-core_2.13 Show documentation
Scala GraphQL implementation
The newest version!
package sangria.validation.rules
import sangria.ast
import sangria.ast.OperationType
import sangria.validation._
/** Subscriptions must only include one field.
*
* A GraphQL subscription is valid only if it contains a single root field.
*/
class SingleFieldSubscriptions extends ValidationRule {
override def visitor(ctx: ValidationContext) = new AstValidatingVisitor {
override val onEnter: ValidationVisit = {
case od: ast.OperationDefinition
if od.operationType == OperationType.Subscription && od.selections.size > 1 =>
Left(
Vector(
SubscriptionSingleFieldOnlyViolation(
od.name,
ctx.sourceMapper,
od.selections.tail.flatMap(_.location).toList)))
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy