Improved Test Framework to support promises as returned GraphQL execution

This commit is contained in:
Syrus Akbary 2017-06-16 11:09:36 -07:00
parent fccc22b651
commit 645bfddfe9

View File

@ -1,3 +1,4 @@
from promise import Promise, is_thenable
import six
from graphql.error import format_error as format_graphql_error
from graphql.error import GraphQLError
@ -31,9 +32,16 @@ class Client(object):
self.schema = schema
self.execute_options = execute_options
self.format_error = format_error or default_format_error
def execute(self, *args, **kwargs):
def format_result(self, result):
return format_execution_result(
self.schema.execute(*args, **dict(self.execute_options, **kwargs)),
result,
self.format_error
)
def execute(self, *args, **kwargs):
executed = self.schema.execute(*args, **dict(self.execute_options, **kwargs))
if is_thenable(executed):
return Promise.resolve(executed).then(self.format_result)
return self.format_result(executed)