|
1 | 1 | from collections import ChainMap |
2 | 2 |
|
3 | 3 | from graphql import graphql_sync |
| 4 | +from graphql.error import GraphQLError |
| 5 | +from graphql.language import SourceLocation |
4 | 6 | from graphql.type import ( |
5 | 7 | GraphQLArgument, |
6 | 8 | GraphQLField, |
@@ -192,3 +194,29 @@ def execute(source, root_value=None): |
192 | 194 | }, |
193 | 195 | None, |
194 | 196 | ) |
| 197 | + |
| 198 | + def pass_error_from_resolver_wrapped_as_located_graphql_error(): |
| 199 | + def resolve(_obj, _info): |
| 200 | + raise ValueError("Some error") |
| 201 | + |
| 202 | + schema = _test_schema(GraphQLField(GraphQLString, resolve=resolve)) |
| 203 | + result = graphql_sync(schema, "{ test }") |
| 204 | + |
| 205 | + assert result == ( |
| 206 | + {"test": None}, |
| 207 | + [{"message": "Some error", "locations": [(1, 3)], "path": ["test"]}], |
| 208 | + ) |
| 209 | + |
| 210 | + assert result.errors is not None |
| 211 | + error = result.errors[0] |
| 212 | + assert isinstance(error, GraphQLError) |
| 213 | + assert str(error) == "Some error\n\nGraphQL request:1:3\n1 | { test }\n | ^" |
| 214 | + assert error.positions == [2] |
| 215 | + locations = error.locations |
| 216 | + assert locations == [(1, 3)] |
| 217 | + location = locations[0] |
| 218 | + assert isinstance(location, SourceLocation) |
| 219 | + assert location == SourceLocation(1, 3) |
| 220 | + original_error = error.original_error |
| 221 | + assert isinstance(original_error, ValueError) |
| 222 | + assert str(original_error) == "Some error" |
0 commit comments