|
1 | 1 | from graphql import graphql_sync |
| 2 | +from graphql.error import GraphQLError |
| 3 | +from graphql.language import SourceLocation |
2 | 4 | from graphql.type import ( |
3 | 5 | GraphQLArgument, |
4 | 6 | GraphQLField, |
@@ -165,3 +167,29 @@ def transforms_arguments_with_inputs_using_out_names(): |
165 | 167 | }, |
166 | 168 | None, |
167 | 169 | ) |
| 170 | + |
| 171 | + def pass_error_from_resolver_wrapped_as_located_graphql_error(): |
| 172 | + def resolve(_obj, _info): |
| 173 | + raise ValueError("Some error") |
| 174 | + |
| 175 | + schema = _test_schema(GraphQLField(GraphQLString, resolve=resolve)) |
| 176 | + result = graphql_sync(schema, "{ test }") |
| 177 | + |
| 178 | + assert result == ( |
| 179 | + {"test": None}, |
| 180 | + [{"message": "Some error", "locations": [(1, 3)], "path": ["test"]}], |
| 181 | + ) |
| 182 | + |
| 183 | + assert result.errors is not None |
| 184 | + error = result.errors[0] |
| 185 | + assert isinstance(error, GraphQLError) |
| 186 | + assert str(error) == "Some error\n\nGraphQL request:1:3\n1 | { test }\n | ^" |
| 187 | + assert error.positions == [2] |
| 188 | + locations = error.locations |
| 189 | + assert locations == [(1, 3)] |
| 190 | + location = locations[0] |
| 191 | + assert isinstance(location, SourceLocation) |
| 192 | + assert location == SourceLocation(1, 3) |
| 193 | + original_error = error.original_error |
| 194 | + assert isinstance(original_error, ValueError) |
| 195 | + assert str(original_error) == "Some error" |
0 commit comments