Skip to content

Commit 3855d79

Browse files
committed
Deprecate get_field_def_fn arg of TypeInfo and move it last
Replicates graphql/graphql-js@825ebd3
1 parent 176d479 commit 3855d79

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/graphql/utilities/type_info.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,15 @@ class TypeInfo:
6666
def __init__(
6767
self,
6868
schema: GraphQLSchema,
69-
get_field_def_fn: Optional[GetFieldDefType] = None,
7069
initial_type: Optional[GraphQLType] = None,
70+
get_field_def_fn: Optional[GetFieldDefType] = None,
7171
) -> None:
7272
"""Initialize the TypeInfo for the given GraphQL schema.
7373
74-
The experimental optional second parameter is only needed in order to support
75-
non-spec-compliant code bases. You should never need to use it. It may disappear
76-
in the future.
77-
7874
Initial type may be provided in rare cases to facilitate traversals beginning
7975
somewhere other than documents.
76+
77+
The optional last parameter is deprecated and will be removed in v3.3.
8078
"""
8179
self._schema = schema
8280
self._type_stack: List[Optional[GraphQLOutputType]] = []

src/graphql/validation/validate.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def validate(
2020
schema: GraphQLSchema,
2121
document_ast: DocumentNode,
2222
rules: Optional[Collection[Type[ASTValidationRule]]] = None,
23-
type_info: Optional[TypeInfo] = None,
2423
max_errors: Optional[int] = None,
24+
type_info: Optional[TypeInfo] = None,
2525
) -> List[GraphQLError]:
2626
"""Implements the "Validation" section of the spec.
2727
@@ -35,8 +35,7 @@ def validate(
3535
a ValidationContext (see the language/visitor API). Visitor methods are expected to
3636
return GraphQLErrors, or lists of GraphQLErrors when invalid.
3737
38-
Optionally a custom TypeInfo instance may be provided. If not provided, one will be
39-
created from the provided schema.
38+
Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
4039
"""
4140
if not document_ast or not isinstance(document_ast, DocumentNode):
4241
raise TypeError("Must provide document.")

tests/utilities/test_type_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def supports_traversal_of_input_values():
308308

309309
complex_input_type = test_schema.get_type("ComplexInput")
310310
assert complex_input_type is not None
311-
type_info = TypeInfo(test_schema, None, complex_input_type)
311+
type_info = TypeInfo(test_schema, complex_input_type)
312312

313313
ast = parse_value('{ stringListField: ["foo"] }')
314314

@@ -357,7 +357,7 @@ def supports_traversal_of_selection_sets():
357357

358358
human_type = test_schema.get_type("Human")
359359
assert human_type is not None
360-
type_info = TypeInfo(test_schema, None, human_type)
360+
type_info = TypeInfo(test_schema, human_type)
361361

362362
ast = parse("{ name, pets { name } }")
363363
operation_node = ast.definitions[0]

tests/validation/test_validation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ def detects_unknown_fields():
7878
{"message": "Cannot query field 'unknown' on type 'QueryRoot'."}
7979
]
8080

81-
# NOTE: experimental
82-
def validates_using_a_custom_type_info():
81+
def deprecated_validates_using_a_custom_type_info():
8382
# This TypeInfo will never return a valid field.
84-
type_info = TypeInfo(test_schema, lambda *args: None)
83+
type_info = TypeInfo(test_schema, None, lambda *args: None)
8584

8685
doc = parse(
8786
"""
@@ -98,7 +97,7 @@ def validates_using_a_custom_type_info():
9897
"""
9998
)
10099

101-
errors = validate(test_schema, doc, None, type_info)
100+
errors = validate(test_schema, doc, None, None, type_info)
102101

103102
assert [error.message for error in errors] == [
104103
"Cannot query field 'catOrDog' on type 'QueryRoot'."

0 commit comments

Comments
 (0)