|
| 1 | +from collections import deque |
1 | 2 | from typing import cast, List, Union |
2 | 3 |
|
3 | 4 | from pytest import raises |
@@ -162,6 +163,29 @@ def converts_single_node_to_positions_and_locations(): |
162 | 163 | assert e.positions == [4] |
163 | 164 | assert e.locations == [(2, 3)] |
164 | 165 |
|
| 166 | + def converts_tuple_of_nodes_to_positions_and_locations(): |
| 167 | + operation = parse("{ first second }").definitions[0] |
| 168 | + nodes = cast(OperationDefinitionNode, operation).selection_set.selections |
| 169 | + assert isinstance(nodes, tuple) |
| 170 | + e = GraphQLError("msg", nodes) |
| 171 | + assert e.nodes == list(nodes) |
| 172 | + assert e.positions == [2, 8] |
| 173 | + assert e.locations == [(1, 3), (1, 9)] |
| 174 | + |
| 175 | + def converts_other_collection_of_nodes_to_positions_and_locations(): |
| 176 | + e = GraphQLError("msg", deque([field_node, operation_node])) |
| 177 | + assert e.nodes == [field_node, operation_node] |
| 178 | + assert e.source is source |
| 179 | + assert e.positions == [4, 0] |
| 180 | + assert e.locations == [(2, 3), (1, 1)] |
| 181 | + |
| 182 | + def converts_empty_tuple_of_nodes_to_none(): |
| 183 | + e = GraphQLError("msg", ()) |
| 184 | + assert e.nodes is None |
| 185 | + assert e.source is None |
| 186 | + assert e.positions is None |
| 187 | + assert e.locations is None |
| 188 | + |
165 | 189 | def converts_node_with_loc_start_zero_to_positions_and_locations(): |
166 | 190 | e = GraphQLError("msg", operation_node) |
167 | 191 | assert e.nodes == [operation_node] |
|
0 commit comments