Skip to content

Commit 1a42027

Browse files
committed
Resolve import cycle by moving TypeInfoVisitor to utilities
Replicates graphql/graphql-js@61a07b1
1 parent b634fa2 commit 1a42027

File tree

13 files changed

+275
-253
lines changed

13 files changed

+275
-253
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current stable version 3.0.1 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.5.8.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 2039 unit tests.
19+
of currently 2040 unit tests.
2020

2121

2222
## Documentation

docs/modules/language.rst

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Visitor
9898
.. autofunction:: visit
9999
.. autoclass:: Visitor
100100
.. autoclass:: ParallelVisitor
101-
.. autoclass:: TypeInfoVisitor
102101

103102
The module also exports the following special symbols which can be used as
104103
return values in the :class:`Visitor` methods to signal particular actions:

docs/modules/utilities.rst

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ A helper to use within recursive-descent visitors which need to be aware of the
6565
type system:
6666

6767
.. autoclass:: TypeInfo
68+
.. autoclass:: TypeInfoVisitor
6869

6970
Coerce a Python value to a GraphQL type, or produce errors:
7071

src/graphql/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
# Visit
180180
visit,
181181
ParallelVisitor,
182-
TypeInfoVisitor,
183182
Visitor,
184183
BREAK,
185184
SKIP,
@@ -362,6 +361,7 @@
362361
# A helper to use within recursive-descent visitors which need to be aware of the
363362
# GraphQL type system.
364363
TypeInfo,
364+
TypeInfoVisitor,
365365
# Coerce a Python value to a GraphQL type, or produce errors.
366366
coerce_input_value,
367367
# Concatenates multiple ASTs together.

src/graphql/language/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
visit,
2323
Visitor,
2424
ParallelVisitor,
25-
TypeInfoVisitor,
2625
BREAK,
2726
SKIP,
2827
REMOVE,
@@ -116,7 +115,6 @@
116115
"visit",
117116
"Visitor",
118117
"ParallelVisitor",
119-
"TypeInfoVisitor",
120118
"BREAK",
121119
"SKIP",
122120
"REMOVE",

src/graphql/language/visitor.py

-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from copy import copy
22
from typing import (
3-
TYPE_CHECKING,
43
Any,
54
Callable,
65
Collection,
@@ -16,13 +15,9 @@
1615

1716
from .ast import Node
1817

19-
if TYPE_CHECKING: # pragma: no cover
20-
from ..utilities import TypeInfo # noqa: F401
21-
2218
__all__ = [
2319
"Visitor",
2420
"ParallelVisitor",
25-
"TypeInfoVisitor",
2621
"visit",
2722
"BREAK",
2823
"SKIP",
@@ -378,28 +373,3 @@ def leave(self, node, *args):
378373
return result
379374
elif skipping[i] is node:
380375
skipping[i] = None
381-
382-
383-
class TypeInfoVisitor(Visitor):
384-
"""A visitor which maintains a provided TypeInfo."""
385-
386-
def __init__(self, type_info: "TypeInfo", visitor: Visitor) -> None:
387-
self.type_info = type_info
388-
self.visitor = visitor
389-
390-
def enter(self, node, *args):
391-
self.type_info.enter(node)
392-
fn = self.visitor.get_visit_fn(node.kind)
393-
if fn:
394-
result = fn(self.visitor, node, *args)
395-
if result is not None:
396-
self.type_info.leave(node)
397-
if isinstance(result, ast.Node):
398-
self.type_info.enter(result)
399-
return result
400-
401-
def leave(self, node, *args):
402-
fn = self.visitor.get_visit_fn(node.kind, is_leaving=True)
403-
result = fn(self.visitor, node, *args) if fn else None
404-
self.type_info.leave(node)
405-
return result

src/graphql/utilities/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
# A helper to use within recursive-descent visitors which need to be aware of
5252
# the GraphQL type system
53-
from .type_info import TypeInfo
53+
from .type_info import TypeInfo, TypeInfoVisitor
5454

5555
# Coerce a Python value to a GraphQL type, or produce errors.
5656
from .coerce_input_value import coerce_input_value
@@ -90,6 +90,7 @@
9090
"DangerousChange",
9191
"DangerousChangeType",
9292
"TypeInfo",
93+
"TypeInfoVisitor",
9394
"assert_valid_name",
9495
"ast_from_value",
9596
"build_ast_schema",

src/graphql/utilities/find_deprecated_usages.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import List
22

33
from ..error import GraphQLError
4-
from ..language import DocumentNode, TypeInfoVisitor, Visitor, visit
4+
from ..language import DocumentNode, Visitor, visit
55
from ..type import GraphQLSchema, get_named_type
6-
from .type_info import TypeInfo
6+
from .type_info import TypeInfo, TypeInfoVisitor
77

88

99
__all__ = ["find_deprecated_usages"]

src/graphql/utilities/type_info.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
OperationType,
1515
SelectionSetNode,
1616
VariableDefinitionNode,
17+
Visitor,
1718
)
1819
from ..type import (
1920
GraphQLArgument,
@@ -43,7 +44,7 @@
4344
)
4445
from .type_from_ast import type_from_ast
4546

46-
__all__ = ["TypeInfo"]
47+
__all__ = ["TypeInfo", "TypeInfoVisitor"]
4748

4849

4950
GetFieldDefType = Callable[
@@ -282,3 +283,28 @@ def get_field_def(
282283
parent_type = cast(Union[GraphQLObjectType, GraphQLInterfaceType], parent_type)
283284
return parent_type.fields.get(name)
284285
return None
286+
287+
288+
class TypeInfoVisitor(Visitor):
289+
"""A visitor which maintains a provided TypeInfo."""
290+
291+
def __init__(self, type_info: "TypeInfo", visitor: Visitor) -> None:
292+
self.type_info = type_info
293+
self.visitor = visitor
294+
295+
def enter(self, node, *args):
296+
self.type_info.enter(node)
297+
fn = self.visitor.get_visit_fn(node.kind)
298+
if fn:
299+
result = fn(self.visitor, node, *args)
300+
if result is not None:
301+
self.type_info.leave(node)
302+
if isinstance(result, Node):
303+
self.type_info.enter(result)
304+
return result
305+
306+
def leave(self, node, *args):
307+
fn = self.visitor.get_visit_fn(node.kind, is_leaving=True)
308+
result = fn(self.visitor, node, *args) if fn else None
309+
self.type_info.leave(node)
310+
return result

src/graphql/validation/validate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Collection, List
22

33
from ..error import GraphQLError
4-
from ..language import DocumentNode, ParallelVisitor, TypeInfoVisitor, visit
4+
from ..language import DocumentNode, ParallelVisitor, visit
55
from ..type import GraphQLSchema, assert_valid_schema
66
from ..pyutils import inspect
7-
from ..utilities import TypeInfo
7+
from ..utilities import TypeInfo, TypeInfoVisitor
88
from .rules import RuleType
99
from .specified_rules import specified_rules, specified_sdl_rules
1010
from .validation_context import SDLValidationContext, ValidationContext

src/graphql/validation/validation_context.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
FragmentSpreadNode,
88
OperationDefinitionNode,
99
SelectionSetNode,
10-
TypeInfoVisitor,
1110
VariableNode,
1211
Visitor,
1312
visit,
1413
)
1514
from ..type import GraphQLSchema, GraphQLInputType
16-
from ..utilities import TypeInfo
15+
from ..utilities import TypeInfo, TypeInfoVisitor
1716

1817
__all__ = [
1918
"ASTValidationContext",

0 commit comments

Comments
 (0)