| 1 |
"""graphql.validation.rules package""" |
| 2 |
|
| 3 |
from ...error import GraphQLError |
| 4 |
from ...language.visitor import Visitor |
| 5 |
from ..validation_context import ( |
| 6 |
ASTValidationContext, |
| 7 |
SDLValidationContext, |
| 8 |
ValidationContext, |
| 9 |
) |
| 10 |
|
| 11 |
__all__ = ["ASTValidationRule", "SDLValidationRule", "ValidationRule"] |
| 12 |
|
| 13 |
|
| 14 |
class ASTValidationRule(Visitor): |
| 15 |
"""Visitor for validation of an AST.""" |
| 16 |
|
| 17 |
context: ASTValidationContext |
| 18 |
|
| 19 |
def __init__(self, context: ASTValidationContext): |
| 20 |
super().__init__() |
| 21 |
self.context = context |
| 22 |
|
| 23 |
def report_error(self, error: GraphQLError) -> None: |
| 24 |
self.context.report_error(error) |
| 25 |
|
| 26 |
|
| 27 |
class SDLValidationRule(ASTValidationRule): |
| 28 |
"""Visitor for validation of an SDL AST.""" |
| 29 |
|
| 30 |
context: SDLValidationContext |
| 31 |
|
| 32 |
def __init__(self, context: SDLValidationContext) -> None: |
| 33 |
super().__init__(context) |
| 34 |
|
| 35 |
|
| 36 |
class ValidationRule(ASTValidationRule): |
| 37 |
"""Visitor for validation using a GraphQL schema.""" |
| 38 |
|
| 39 |
context: ValidationContext |
| 40 |
|
| 41 |
def __init__(self, context: ValidationContext) -> None: |
| 42 |
super().__init__(context) |