Sync graphql validate() with graphql-core
from asyncio import ensure_future
from inspect import isawaitable
-from typing import Any, AsyncGenerator, Awaitable, List, Optional, Sequence, Type, cast
+from typing import Any, AsyncGenerator, Awaitable, Collection, List, Optional, Sequence, Type, cast
from graphql import (
DocumentNode,
@@ -30,8 +30,6 @@ from .types import (
)
from .validation.introspection_disabled import IntrospectionDisabledRule
-RuleType = Type[ASTValidationRule]
-
async def graphql(
schema: GraphQLSchema,
@@ -63,7 +61,7 @@ async def graphql(
if callable(validation_rules):
validation_rules = cast(
- Optional[Sequence[RuleType]],
+ Optional[Collection[Type[ASTValidationRule]]],
validation_rules(context_value, document, data),
)
@@ -146,7 +144,7 @@ def graphql_sync(
if callable(validation_rules):
validation_rules = cast(
- Optional[Sequence[RuleType]],
+ Optional[Collection[Type[ASTValidationRule]]],
validation_rules(context_value, document, data),
)
@@ -231,7 +229,7 @@ async def subscribe(
if callable(validation_rules):
validation_rules = cast(
- Optional[Sequence[RuleType]],
+ Optional[Collection[Type[ASTValidationRule]]],
validation_rules(context_value, document, data),
)
@@ -326,7 +324,8 @@ def add_extensions_to_response(extension_manager: ExtensionManager, response: di
def validate_query(
schema: GraphQLSchema,
document_ast: DocumentNode,
- rules: Optional[Sequence[RuleType]] = None,
+ rules: Optional[Collection[Type[ASTValidationRule]]] = None,
+ max_errors: Optional[int] = None,
type_info: Optional[TypeInfo] = None,
enable_introspection: bool = True,
) -> List[GraphQLError]:
@@ -343,6 +342,7 @@ def validate_query(
schema,
document_ast,
rules=supplemented_rules,
+ max_errors=max_errors,
type_info=type_info,
)
# run validation using spec rules only
