diff --git a/gql/utilities/node_tree.py b/gql/utilities/node_tree.py index c307d937..4313188e 100644 --- a/gql/utilities/node_tree.py +++ b/gql/utilities/node_tree.py @@ -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)) @@ -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. """ diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index 1aa1efa2..098c8aca 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -1030,11 +1030,10 @@ def test_node_tree_with_loc(ds): node_tree_result = """ DocumentNode - loc: - Location - definitions: OperationDefinitionNode + directives: + empty tuple loc: Location @@ -1045,10 +1044,8 @@ def test_node_tree_with_loc(ds): value: 'GetHeroName' - directives: - empty tuple - variable_definitions: - empty tuple + operation: + selection_set: SelectionSetNode loc: @@ -1056,13 +1053,15 @@ def test_node_tree_with_loc(ds): selections: FieldNode + alias: + None + arguments: + empty tuple + directives: + empty tuple loc: Location - directives: - empty tuple - alias: - None name: NameNode loc: @@ -1070,8 +1069,6 @@ def test_node_tree_with_loc(ds): value: 'hero' - arguments: - empty tuple nullability_assertion: None selection_set: @@ -1081,13 +1078,15 @@ def test_node_tree_with_loc(ds): selections: FieldNode + alias: + None + arguments: + empty tuple + directives: + empty tuple loc: Location - directives: - empty tuple - alias: - None name: NameNode loc: @@ -1095,23 +1094,23 @@ def test_node_tree_with_loc(ds): value: 'name' - arguments: - empty tuple nullability_assertion: None selection_set: None - operation: - + variable_definitions: + empty tuple + loc: + Location + """.strip() node_tree_result_stable = """ DocumentNode - loc: - Location - definitions: OperationDefinitionNode + directives: + empty tuple loc: Location @@ -1122,10 +1121,8 @@ def test_node_tree_with_loc(ds): value: 'GetHeroName' - directives: - empty tuple - variable_definitions: - empty tuple + operation: + selection_set: SelectionSetNode loc: @@ -1133,13 +1130,15 @@ def test_node_tree_with_loc(ds): selections: FieldNode + alias: + None + arguments: + empty tuple + directives: + empty tuple loc: Location - directives: - empty tuple - alias: - None name: NameNode loc: @@ -1147,8 +1146,6 @@ def test_node_tree_with_loc(ds): value: 'hero' - arguments: - empty tuple selection_set: SelectionSetNode loc: @@ -1156,13 +1153,15 @@ def test_node_tree_with_loc(ds): selections: FieldNode + alias: + None + arguments: + empty tuple + directives: + empty tuple loc: Location - directives: - empty tuple - alias: - None name: NameNode loc: @@ -1170,14 +1169,17 @@ def test_node_tree_with_loc(ds): value: 'name' - arguments: - empty tuple selection_set: None - operation: - + variable_definitions: + empty tuple + loc: + Location + """.strip() + print(node_tree(document, ignore_loc=False)) + try: assert node_tree(document, ignore_loc=False) == node_tree_result except AssertionError: