Skip to content

Commit 917dc16

Browse files
committed
Fixed format_error
1 parent b369ccf commit 917dc16

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

graphene/test/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from graphene.types.schema import Schema
22

3-
from graphql.error import format_error
3+
from graphql.error import format_error as format_graphql_error
4+
from graphql.error import GraphQLError
45

56

6-
def format_execution_result(execution_result):
7+
def default_format_error(error):
8+
if isinstance(error, GraphQLError):
9+
return format_graphql_error(error)
10+
11+
return {'message': six.text_type(error)}
12+
13+
14+
def format_execution_result(execution_result, format_error):
715
if execution_result:
816
response = {}
917

@@ -17,12 +25,14 @@ def format_execution_result(execution_result):
1725

1826

1927
class Client(object):
20-
def __init__(self, schema, **execute_options):
28+
def __init__(self, schema, format_error=None, **execute_options):
2129
assert isinstance(schema, Schema)
2230
self.schema = schema
2331
self.execute_options = execute_options
32+
self.format_error = format_error or default_format_error
2433

2534
def execute(self, *args, **kwargs):
2635
return format_execution_result(
27-
self.schema.execute(*args, **dict(self.execute_options, **kwargs))
36+
self.schema.execute(*args, **dict(self.execute_options, **kwargs)),
37+
self.format_error
2838
)

0 commit comments

Comments
 (0)