diff --git a/graphene/relay/tests/test_mutation.py b/graphene/relay/tests/test_mutation.py index b58a3ddf..96ddcf0c 100644 --- a/graphene/relay/tests/test_mutation.py +++ b/graphene/relay/tests/test_mutation.py @@ -1,5 +1,4 @@ -import pytest -from promise import Promise +from pytest import mark, raises from ...types import ( ID, @@ -55,15 +54,15 @@ class SaySomethingFixed(ClientIDMutation): return FixedSaySomething(phrase=str(what)) -class SaySomethingPromise(ClientIDMutation): +class SaySomethingAsync(ClientIDMutation): class Input: what = String() phrase = String() @staticmethod - def mutate_and_get_payload(self, info, what, client_mutation_id=None): - return Promise.resolve(SaySomething(phrase=str(what))) + async def mutate_and_get_payload(self, info, what, client_mutation_id=None): + return SaySomething(phrase=str(what)) # MyEdge = MyNode.Connection.Edge @@ -97,7 +96,7 @@ class RootQuery(ObjectType): class Mutation(ObjectType): say = SaySomething.Field() say_fixed = SaySomethingFixed.Field() - say_promise = SaySomethingPromise.Field() + say_async = SaySomethingAsync.Field() other = OtherMutation.Field() @@ -105,7 +104,7 @@ schema = Schema(query=RootQuery, mutation=Mutation) def test_no_mutate_and_get_payload(): - with pytest.raises(AssertionError) as excinfo: + with raises(AssertionError) as excinfo: class MyMutation(ClientIDMutation): pass @@ -185,12 +184,13 @@ def test_node_query_fixed(): ) -def test_node_query_promise(): - executed = schema.execute( - 'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }' +@mark.asyncio +async def test_node_query_async(): + executed = await schema.execute_async( + 'mutation a { sayAsync(input: {what:"hello", clientMutationId:"1"}) { phrase } }' ) assert not executed.errors - assert executed.data == {"sayPromise": {"phrase": "hello"}} + assert executed.data == {"sayAsync": {"phrase": "hello"}} def test_edge_query(): diff --git a/graphene/types/schema.py b/graphene/types/schema.py index be40bd6a..1d84dea0 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -454,13 +454,13 @@ class Schema: def lazy(self, _type): return lambda: self.get_type(_type) - async def async_execute(self, *args, **kwargs): - return graphql(self.graphql_schema, *args, **normalize_execute_kwargs(kwargs)) + async def execute_async(self, *args, **kwargs): + kwargs = normalize_execute_kwargs(kwargs) + return await graphql(self.graphql_schema, *args, **kwargs) def execute(self, *args, **kwargs): - return graphql_sync( - self.graphql_schema, *args, **normalize_execute_kwargs(kwargs) - ) + kwargs = normalize_execute_kwargs(kwargs) + return graphql_sync(self.graphql_schema, *args, **kwargs) def introspect(self): introspection = self.execute(introspection_query) diff --git a/tests_asyncio/test_relay_mutation.py b/tests_asyncio/test_relay_mutation.py index 42ea5fc7..f63ae193 100644 --- a/tests_asyncio/test_relay_mutation.py +++ b/tests_asyncio/test_relay_mutation.py @@ -1,5 +1,4 @@ -import pytest -from graphql.execution.executors.asyncio import AsyncioExecutor +from pytest import mark from graphene.types import ID, Field, ObjectType, Schema from graphene.types.scalars import String @@ -64,23 +63,19 @@ class Mutation(ObjectType): schema = Schema(query=RootQuery, mutation=Mutation) -@pytest.mark.asyncio +@mark.asyncio async def test_node_query_promise(): - executed = await schema.execute( + executed = await schema.execute_async( 'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }', - executor=AsyncioExecutor(), - return_promise=True, ) assert not executed.errors assert executed.data == {"sayPromise": {"phrase": "hello"}} -@pytest.mark.asyncio +@mark.asyncio async def test_edge_query(): - executed = await schema.execute( + executed = await schema.execute_async( 'mutation a { other(input: {clientMutationId:"1"}) { clientMutationId, myNodeEdge { cursor node { name }} } }', - executor=AsyncioExecutor(), - return_promise=True, ) assert not executed.errors assert dict(executed.data) == {