From 645bfddfe955e5a51b13a7d2e58714cdbb7166ab Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 16 Jun 2017 11:09:36 -0700 Subject: [PATCH] Improved Test Framework to support promises as returned GraphQL execution --- graphene/test/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/graphene/test/__init__.py b/graphene/test/__init__.py index 98c8547c..6d46bd57 100644 --- a/graphene/test/__init__.py +++ b/graphene/test/__init__.py @@ -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)