From 38fdcc7dfef4bd8b804f7d6f1a1bdfc4da62de14 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Mon, 27 Jan 2025 02:22:02 +0100 Subject: [PATCH] Sort elements in node_tree method This should resolve some non-important difference from graphql-core v3.3.0a7 --- gql/utilities/node_tree.py | 5 ++- tests/starwars/test_dsl.py | 86 +++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 43 deletions(-) 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 2aadf92f..32dd1e72 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -1028,11 +1028,10 @@ def test_node_tree_with_loc(ds): node_tree_result = """ DocumentNode - loc: - Location - definitions: OperationDefinitionNode + directives: + empty tuple loc: Location @@ -1043,10 +1042,8 @@ def test_node_tree_with_loc(ds): value: 'GetHeroName' - directives: - empty tuple - variable_definitions: - empty tuple + operation: + selection_set: SelectionSetNode loc: @@ -1054,13 +1051,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: @@ -1068,8 +1067,6 @@ def test_node_tree_with_loc(ds): value: 'hero' - arguments: - empty tuple nullability_assertion: None selection_set: @@ -1079,13 +1076,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: @@ -1093,23 +1092,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 @@ -1120,10 +1119,8 @@ def test_node_tree_with_loc(ds): value: 'GetHeroName' - directives: - empty tuple - variable_definitions: - empty tuple + operation: + selection_set: SelectionSetNode loc: @@ -1131,13 +1128,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: @@ -1145,8 +1144,6 @@ def test_node_tree_with_loc(ds): value: 'hero' - arguments: - empty tuple selection_set: SelectionSetNode loc: @@ -1154,13 +1151,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: @@ -1168,14 +1167,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: