Skip to content

Commit 2d90cc1

Browse files
committed
Remove deprecated type_info argument of validate() function
Replicates graphql/graphql-js@b4ad128
1 parent 6495cbf commit 2d90cc1

File tree

2 files changed

+3
-48
lines changed

2 files changed

+3
-48
lines changed

src/graphql/validation/validate.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ..error import GraphQLError
44
from ..language import DocumentNode, ParallelVisitor, visit
5-
from ..pyutils import inspect, is_collection
5+
from ..pyutils import is_collection
66
from ..type import GraphQLSchema, assert_valid_schema
77
from ..utilities import TypeInfo, TypeInfoVisitor
88
from .rules import ASTValidationRule
@@ -22,7 +22,6 @@ def validate(
2222
document_ast: DocumentNode,
2323
rules: Optional[Collection[Type[ASTValidationRule]]] = None,
2424
max_errors: Optional[int] = None,
25-
type_info: Optional[TypeInfo] = None,
2625
) -> List[GraphQLError]:
2726
"""Implements the "Validation" section of the spec.
2827
@@ -39,8 +38,6 @@ def validate(
3938
Validate will stop validation after a ``max_errors`` limit has been reached.
4039
Attackers can send pathologically invalid queries to induce a DoS attack,
4140
so by default ``max_errors`` set to 100 errors.
42-
43-
Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
4441
"""
4542
if not document_ast or not isinstance(document_ast, DocumentNode):
4643
raise TypeError("Must provide document.")
@@ -50,10 +47,6 @@ def validate(
5047
max_errors = 100
5148
elif not isinstance(max_errors, int):
5249
raise TypeError("The maximum number of errors must be passed as an int.")
53-
if type_info is None:
54-
type_info = TypeInfo(schema)
55-
elif not isinstance(type_info, TypeInfo):
56-
raise TypeError(f"Not a TypeInfo object: {inspect(type_info)}.")
5750
if rules is None:
5851
rules = specified_rules
5952
elif not is_collection(rules) or not all(
@@ -76,6 +69,7 @@ def on_error(error: GraphQLError) -> None:
7669
raise ValidationAbortedError
7770
errors.append(error)
7871

72+
type_info = TypeInfo(schema)
7973
context = ValidationContext(schema, document_ast, type_info, on_error)
8074

8175
# This uses a specialized visitor which runs multiple visitors in parallel,

tests/validation/test_validation.py

+1-40
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from graphql.error import GraphQLError
44
from graphql.language import parse
5-
from graphql.utilities import TypeInfo, build_schema
5+
from graphql.utilities import build_schema
66
from graphql.validation import ValidationRule, validate
77

88
from .harness import test_schema
@@ -15,14 +15,6 @@ def rejects_invalid_documents():
1515
assert validate(test_schema, None) # type: ignore
1616
assert str(exc_info.value) == "Must provide document."
1717

18-
def rejects_invalid_type_info():
19-
with raises(TypeError) as exc_info:
20-
# noinspection PyTypeChecker
21-
assert validate(
22-
test_schema, parse("query { name }"), type_info={} # type: ignore
23-
)
24-
assert str(exc_info.value) == "Not a TypeInfo object: {}."
25-
2618
def rejects_invalid_rules():
2719
with raises(TypeError) as exc_info:
2820
# noinspection PyTypeChecker
@@ -80,37 +72,6 @@ def detects_unknown_fields():
8072
{"message": "Cannot query field 'unknown' on type 'QueryRoot'."}
8173
]
8274

83-
def deprecated_validates_using_a_custom_type_info():
84-
# This TypeInfo will never return a valid field.
85-
type_info = TypeInfo(test_schema, None, lambda *args: None)
86-
87-
doc = parse(
88-
"""
89-
query {
90-
human {
91-
pets {
92-
... on Cat {
93-
meowsVolume
94-
}
95-
... on Dog {
96-
barkVolume
97-
}
98-
}
99-
}
100-
}
101-
"""
102-
)
103-
104-
errors = validate(test_schema, doc, None, None, type_info)
105-
106-
assert [error.message for error in errors] == [
107-
"Cannot query field 'human' on type 'QueryRoot'. Did you mean 'human'?",
108-
"Cannot query field 'meowsVolume' on type 'Cat'."
109-
" Did you mean 'meowsVolume'?",
110-
"Cannot query field 'barkVolume' on type 'Dog'."
111-
" Did you mean 'barkVolume'?",
112-
]
113-
11475
def validates_using_a_custom_rule():
11576
schema = build_schema(
11677
"""

0 commit comments

Comments
 (0)