Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe doesn't await the execution results #10

Closed
dfee opened this issue Sep 21, 2018 · 5 comments
Closed

Subscribe doesn't await the execution results #10

dfee opened this issue Sep 21, 2018 · 5 comments

Comments

@dfee
Copy link
Member

dfee commented Sep 21, 2018

execute returns a MaybeAwaitable but subscribe doesn't await it if it does.

https://github.com/graphql-python/graphql-core-next/blob/3de6454304422b3cd832cb1bb075be202e26616c/graphql/subscription/subscribe.py#L67-L87

@dfee
Copy link
Member Author

dfee commented Sep 21, 2018

I don't know... that doesn't appear to be the problem. Let me give you the symptom:

async def subscribe_count_seconds(
    root: None, info: GraphQLResolveInfo, upTo: int
) -> typing.AsyncIterator[typing.Dict[str, int]]:
    for i in range(upTo):
        yield {"countSeconds": i}
        await asyncio.sleep(1)


async def resolve_count_seconds(  # does not get awaited
    root: int, info: GraphQLResolveInfo, upTo: int
) -> str:
    userid = await authorized_userid(info.context.request)
    return f"you are {userid} and its been {root} seconds"

@Cito
Copy link
Member

Cito commented Sep 21, 2018

Can you post a full test case showing what you do and what you expect to happen?

@dfee
Copy link
Member Author

dfee commented Sep 21, 2018

Sure. I created a pretty robust test case that demonstrates how I'd expect it to work. https://gist.github.com/dfee/02264e4e0ea8f6f38ffbeb5e03356473

I have tests for all of it, and it's kinda the basis of some code I'm writing right now.

Anyway, if you look at (and follow) line 371 (test_subscribe_user), you can see that the subscription returns a MapAsyncIterator instance as expected, and then as that emits, the result is passed to the resolve function (Line 126 / Line 132). Of course, the async resolver doesn't work (which is why I opened this ticket).

Cito added a commit that referenced this issue Sep 26, 2018
@Cito
Copy link
Member

Cito commented Sep 26, 2018

Sorry for coming back to you only now, @dfee. I like your large test case - can I add it to the test suite?

I've already added a unit test to test_subscribe that addresses only your specific issue here, and a small fix that should solve it. Can you confirm that the change above solves your issue?

I also noticed that GraphQL.js has the same issue, so I need to confer with them whether this should be backported.

@dfee
Copy link
Member Author

dfee commented Sep 26, 2018

@Cito of course you can include it. Also, very interesting regarding GraphQL.js's compatibility. I'll follow up later on whether the patch works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants