mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
feat_ (#1476)
Previously, installing graphene and trying to do `from graphene.test import Client` as recommended in the docs caused an `ImportError`, as the 'promise' library is imported but only listed as a requirement in the 'test' section of the setup.py file.
This commit is contained in:
parent
0b1bfbf65b
commit
7f6fa16194
|
@ -3,6 +3,7 @@ from pytest import mark
|
|||
from graphene.types import ID, Field, ObjectType, Schema
|
||||
from graphene.types.scalars import String
|
||||
from graphene.relay.mutation import ClientIDMutation
|
||||
from graphene.test import Client
|
||||
|
||||
|
||||
class SharedFields(object):
|
||||
|
@ -61,24 +62,27 @@ class Mutation(ObjectType):
|
|||
|
||||
|
||||
schema = Schema(query=RootQuery, mutation=Mutation)
|
||||
client = Client(schema)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_node_query_promise():
|
||||
executed = await schema.execute_async(
|
||||
executed = await client.execute_async(
|
||||
'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
|
||||
)
|
||||
assert not executed.errors
|
||||
assert executed.data == {"sayPromise": {"phrase": "hello"}}
|
||||
assert isinstance(executed, dict)
|
||||
assert "errors" not in executed
|
||||
assert executed["data"] == {"sayPromise": {"phrase": "hello"}}
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_edge_query():
|
||||
executed = await schema.execute_async(
|
||||
executed = await client.execute_async(
|
||||
'mutation a { other(input: {clientMutationId:"1"}) { clientMutationId, myNodeEdge { cursor node { name }} } }'
|
||||
)
|
||||
assert not executed.errors
|
||||
assert dict(executed.data) == {
|
||||
assert isinstance(executed, dict)
|
||||
assert "errors" not in executed
|
||||
assert executed["data"] == {
|
||||
"other": {
|
||||
"clientMutationId": "1",
|
||||
"myNodeEdge": {"cursor": "1", "node": {"name": "name"}},
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from promise import Promise, is_thenable
|
||||
from graphql.error import GraphQLError
|
||||
|
||||
from graphene.types.schema import Schema
|
||||
|
@ -31,7 +30,10 @@ class Client:
|
|||
|
||||
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)
|
||||
|
||||
async def execute_async(self, *args, **kwargs):
|
||||
executed = await self.schema.execute_async(
|
||||
*args, **dict(self.execute_options, **kwargs)
|
||||
)
|
||||
return self.format_result(executed)
|
||||
|
|
Loading…
Reference in New Issue
Block a user