Skip to content

Commit 645bfdd

Browse files
committed
Improved Test Framework to support promises as returned GraphQL execution
1 parent fccc22b commit 645bfdd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

graphene/test/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from promise import Promise, is_thenable
12
import six
23
from graphql.error import format_error as format_graphql_error
34
from graphql.error import GraphQLError
@@ -31,9 +32,16 @@ def __init__(self, schema, format_error=None, **execute_options):
3132
self.schema = schema
3233
self.execute_options = execute_options
3334
self.format_error = format_error or default_format_error
34-
35-
def execute(self, *args, **kwargs):
35+
36+
def format_result(self, result):
3637
return format_execution_result(
37-
self.schema.execute(*args, **dict(self.execute_options, **kwargs)),
38+
result,
3839
self.format_error
3940
)
41+
42+
def execute(self, *args, **kwargs):
43+
executed = self.schema.execute(*args, **dict(self.execute_options, **kwargs))
44+
if is_thenable(executed):
45+
return Promise.resolve(executed).then(self.format_result)
46+
47+
return self.format_result(executed)

0 commit comments

Comments
 (0)