Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort elements in node_tree method #520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gql/utilities/node_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _node_tree_recursive(
results.append(" " * indent + f"{type(obj).__name__}")

try:
keys = obj.keys
keys = sorted(obj.keys)
except AttributeError:
# If the object has no keys attribute, print its repr and return.
results.append(" " * (indent + 1) + repr(obj))
Expand Down Expand Up @@ -70,6 +70,9 @@ def node_tree(

Useful to debug deep DocumentNode instances created by gql or dsl_gql.

NOTE: from gql version 3.6.0b4 the elements of each node are sorted to ignore
small changes in graphql-core

WARNING: the output of this method is not guaranteed and may change without notice.
"""

Expand Down
86 changes: 44 additions & 42 deletions tests/starwars/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,10 @@ def test_node_tree_with_loc(ds):

node_tree_result = """
DocumentNode
loc:
Location
<Location 0:43>
definitions:
OperationDefinitionNode
directives:
empty tuple
loc:
Location
<Location 0:43>
Expand All @@ -1045,33 +1044,31 @@ def test_node_tree_with_loc(ds):
<Location 6:17>
value:
'GetHeroName'
directives:
empty tuple
variable_definitions:
empty tuple
operation:
<OperationType.QUERY: 'query'>
selection_set:
SelectionSetNode
loc:
Location
<Location 18:43>
selections:
FieldNode
alias:
None
arguments:
empty tuple
directives:
empty tuple
loc:
Location
<Location 22:41>
directives:
empty tuple
alias:
None
name:
NameNode
loc:
Location
<Location 22:26>
value:
'hero'
arguments:
empty tuple
nullability_assertion:
None
selection_set:
Expand All @@ -1081,37 +1078,39 @@ def test_node_tree_with_loc(ds):
<Location 27:41>
selections:
FieldNode
alias:
None
arguments:
empty tuple
directives:
empty tuple
loc:
Location
<Location 33:37>
directives:
empty tuple
alias:
None
name:
NameNode
loc:
Location
<Location 33:37>
value:
'name'
arguments:
empty tuple
nullability_assertion:
None
selection_set:
None
operation:
<OperationType.QUERY: 'query'>
variable_definitions:
empty tuple
loc:
Location
<Location 0:43>
""".strip()

node_tree_result_stable = """
DocumentNode
loc:
Location
<Location 0:43>
definitions:
OperationDefinitionNode
directives:
empty tuple
loc:
Location
<Location 0:43>
Expand All @@ -1122,62 +1121,65 @@ def test_node_tree_with_loc(ds):
<Location 6:17>
value:
'GetHeroName'
directives:
empty tuple
variable_definitions:
empty tuple
operation:
<OperationType.QUERY: 'query'>
selection_set:
SelectionSetNode
loc:
Location
<Location 18:43>
selections:
FieldNode
alias:
None
arguments:
empty tuple
directives:
empty tuple
loc:
Location
<Location 22:41>
directives:
empty tuple
alias:
None
name:
NameNode
loc:
Location
<Location 22:26>
value:
'hero'
arguments:
empty tuple
selection_set:
SelectionSetNode
loc:
Location
<Location 27:41>
selections:
FieldNode
alias:
None
arguments:
empty tuple
directives:
empty tuple
loc:
Location
<Location 33:37>
directives:
empty tuple
alias:
None
name:
NameNode
loc:
Location
<Location 33:37>
value:
'name'
arguments:
empty tuple
selection_set:
None
operation:
<OperationType.QUERY: 'query'>
variable_definitions:
empty tuple
loc:
Location
<Location 0:43>
""".strip()

print(node_tree(document, ignore_loc=False))

try:
assert node_tree(document, ignore_loc=False) == node_tree_result
except AssertionError:
Expand Down
Loading