Skip to content

Commit

Permalink
Remove unnecessary dependency on 'promise' library
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mike-roberts-healx authored and erikwrede committed Nov 16, 2022
1 parent 0b1bfbf commit 09d65cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 10 additions & 6 deletions graphene/relay/tests/test_mutation_async.py
Expand Up @@ -3,6 +3,7 @@
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):
Expand Down Expand Up @@ -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"}},
Expand Down
8 changes: 5 additions & 3 deletions graphene/test/__init__.py
@@ -1,4 +1,3 @@
from promise import Promise, is_thenable
from graphql.error import GraphQLError

from graphene.types.schema import Schema
Expand Down Expand Up @@ -31,7 +30,10 @@ def format_result(self, result):

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)
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -52,7 +52,6 @@ def run_tests(self):
"pytest-asyncio>=0.16,<2",
"snapshottest>=0.6,<1",
"coveralls>=3.3,<4",
"promise>=2.3,<3",
"mock>=4,<5",
"pytz==2022.1",
"iso8601>=1,<2",
Expand Down

0 comments on commit 09d65cb

Please sign in to comment.