mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-29 21:13:58 +03:00
Improved Test Framework to support promises as returned GraphQL execution
This commit is contained in:
parent
fccc22b651
commit
645bfddfe9
|
@ -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
|
||||
|
@ -32,8 +33,15 @@ class Client(object):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user