-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reraise method to GraphQLError
- Loading branch information
1 parent
5474674
commit 311b3b9
Showing
6 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
import traceback | ||
|
||
from graphql.execution import execute | ||
from graphql.language.parser import parse | ||
from graphql.type import (GraphQLField, GraphQLObjectType, GraphQLSchema, | ||
GraphQLString) | ||
|
||
|
||
def test_raise(): | ||
ast = parse('query Example { a }') | ||
|
||
def resolver(context, *_): | ||
raise Exception('Failed') | ||
|
||
Type = GraphQLObjectType('Type', { | ||
'a': GraphQLField(GraphQLString, resolver=resolver), | ||
}) | ||
|
||
result = execute(GraphQLSchema(Type), ast) | ||
assert str(result.errors[0]) == 'Failed' | ||
|
||
|
||
def test_reraise(): | ||
ast = parse('query Example { a }') | ||
|
||
def resolver(context, *_): | ||
raise Exception('Failed') | ||
|
||
Type = GraphQLObjectType('Type', { | ||
'a': GraphQLField(GraphQLString, resolver=resolver), | ||
}) | ||
|
||
result = execute(GraphQLSchema(Type), ast) | ||
with pytest.raises(Exception) as exc_info: | ||
result.errors[0].reraise() | ||
|
||
extracted = traceback.extract_tb(exc_info.tb) | ||
formatted_tb = [row[2:] for row in extracted] | ||
if formatted_tb[2][0] == 'reraise': | ||
formatted_tb[2:] = formatted_tb[3:] | ||
|
||
assert formatted_tb == [ | ||
('test_reraise', 'result.errors[0].reraise()'), | ||
('reraise', 'six.reraise(type(self), self, self.stack)'), | ||
# ('reraise', 'raise value.with_traceback(tb)'), | ||
('resolve_or_error', 'return executor.execute(resolve_fn, source, args, context, info)'), | ||
('execute', 'return fn(*args, **kwargs)'), ('resolver', "raise Exception('Failed')") | ||
] | ||
assert str(exc_info.value) == 'Failed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters