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

Subscriptions do not work in the getting started example #67

Closed
jamessmith-decisionlab opened this issue Nov 20, 2019 · 16 comments
Closed

Comments

@jamessmith-decisionlab
Copy link

tartiflette-aiohttp = "^0.8.4"

Python version is 3.7.4

I've copied the code from the getting started example on the website line for line, but the subscriptions aren't working. The default subscription resolver on line 145 of the factory.py file is being invoked rather than the one defined in the application.

Please can you check?

@tsunammis
Copy link
Contributor

Hello @jamessmith-decisionlab .

Thank you for this bug report, we will take a look of it.

@tsunammis tsunammis transferred this issue from tartiflette/tartiflette Nov 21, 2019
@tsunammis
Copy link
Contributor

I transferred this issue to tartiflette-aiohttp as the subscription part is implemented into it.

@jamessmith-decisionlab
Copy link
Author

Thanks!

@Maximilien-R
Copy link
Member

Maximilien-R commented Nov 21, 2019

Hi @jamessmith-decisionlab,

tartiflette-aiohttp==0.8.4 have tartiflette<0.13.0,>=0.12.0 as dependency. I suggest you to move to tartiflette-aiohttp>=1 to be up-to-date with all the features and fixes provided with tartiflette>=1.

If you prefer (or need) to stay with the tartiflette-aiohttp==0.8.4 version, you should probably follow the getting started tutorial related to tartiflette==0.12.5 (cf. https://tartiflette.io/docs/0.12.5/tutorial/getting-started)

To fix your subscription, I think you have to unwrap the yield response from your subscribe_subscription_launch_and_wait_cooking_timer function to directly returns the response instead of the launchAndWaitCookingTimer wrapped response.

This is a break changes from tartiflette>=1 which is documented in the migration guide (cf. https://tartiflette.io/docs/migration-guides/migration-guide-0-0-to-1-0#subscriptions-no-longer-have-a-specific-default-resolver).

@jamessmith-decisionlab
Copy link
Author

Good morning.

I cannot upgrade, unfortunately, because of this issue:

tartiflette/tartiflette#331

I would be very grateful if you could provide any wisdom on this.

@jamessmith-decisionlab
Copy link
Author

jamessmith-decisionlab commented Nov 21, 2019

Hi. I now have tartiflette and tartiflette-aiohttp up to version 1.1.1 locally. Copying the schema and example code directly, I still get a null response.

My schema:

enum CookingStatus {
  COOKING
  COOKED
}

type CookingTimer {
  remainingTime: Int!
  status: CookingStatus!
}

type Subscription {
  launchAndWaitCookingTimer(id: Int!): CookingTimer
}

The resolver:

from tartiflette import Subscription


@Subscription("Subscription.launchAndWaitCookingTimer")
async def subscribe_subscription_launch_and_wait_cooking_timer(
    parent, args, ctx, info
):
    yield {"launchAndWaitCookingTimer": {"remainingTime": 0, "status": "COOKED"}}

The query:

subscription {
  launchAndWaitCookingTimer(id: 1) {
    remainingTime
    status
  }
}

And the response:

{
  "data": {
    "launchAndWaitCookingTimer": null
  }
}

If I add a breakpoint at the yield, it is not being hit.

@Maximilien-R
Copy link
Member

I started a new project and followed each step of the tutorial and everything works fine on my side.

When looking at your SDL & code, I don't see anything which could explain your isssue.

However, here are extra steps which if not done, could explain your issue:

  1. Did you properly filled in the subscription_ws_endpoint parameter on the register_graphql_handlers function (at recipes_manager/app.py) as described at this step (cf. https://tartiflette.io/docs/tutorial/add-subscription#how-can-we-use-it)
  2. Did you properly relaunch your GraphQL server with python -m recipes_manager to take those changes into account?
  3. Did you refresh the page to load extra JS libraries which handles websockets & GraphQL subscriptions?

@jamessmith-decisionlab
Copy link
Author

jamessmith-decisionlab commented Nov 21, 2019

Yes to all of those, I'm afraid. What I could do is build the application from scratch again, but my hunch is it won't make any difference.

@Maximilien-R
Copy link
Member

Could you try to clone the tartiflette-aiohttp-tutorial (cf. https://github.com/tartiflette/tartiflette-aiohttp-tutorial) project and try to run the code from it?

If subscriptions are working properly with it, maybe you should check if you find differences between the code from it and your own. If it doesn't work neither I really don't know what's happening here 😢

@jamessmith-decisionlab
Copy link
Author

Happy to give it a go!

@jamessmith-decisionlab
Copy link
Author

jamessmith-decisionlab commented Nov 21, 2019

I'm afraid I get the same problem. This query...

subscription {
  launchAndWaitCookingTimer (id:1) {
    remainingTime
    status
  }
}

...gives me this response:

{
  "data": {
    "launchAndWaitCookingTimer": null
  }
}

@Maximilien-R
Copy link
Member

@jamessmith-decisionlab if you encounter the same behaviour with tartiflette-aiohttp-tutorial its probably not a code related issue.

Also, if you are on tartiflette>=1 & tartiflette-aiohttp>=1 I don't see neither what could lead to this issue.

You could probably try to create a brand new virtualenv and re-install tartiflette-aiohttp>=1 to use a clean new install of both tartiflette-aiohttp & tartiflette but I don't think this will fix anything 😞.

Did you try to run this through Docker? At least to test if you have the same issue. Also, did you check on the network tab on the developer tools of your browser to check if there is any error when executing your subscription request?

@jamessmith-decisionlab
Copy link
Author

I agree. It's most likely a platform issue if it's working for you and not for me. I'm on a Mac, I'm guessing you are on Linux or inside Docker which would also be on Linux?

I've already tried a clean install for the tutorial so I agree that won't make a difference.

I think if I tried this through Docker and it worked, it wouldn't help a whole lot except perhaps in adding more weight to the belief that it is a platform issue.

I'm using Insomnia so I don't have network tools but a 200 OK is being returned. I agree that it could be that the websockets part is failing, however.

The only thing I can offer to assist is that I debugged the application and the user defined subscription resolver is not being invoked. An instance of the Subscription class is being created for the user defined resolver and it's bake() method is being called, which sets the subscribe property of the relevant field to the _implementation property of the aforementioned class instance. However, there seems to be something amiss with the internal plumbing, because, as I've already mentioned, the user defined resolver is never being called. Instead, the internal default subscription resolver is called. It is my guess that this is why null is being returned.

I'm using tartiflette as part of a work project and that project has now finished, so I have no more time allocated to this, I'm afraid. However, I am happy to answer questions if you feel like digging in to this further.

@Maximilien-R
Copy link
Member

My bad, I was presuming you were using the GraphiQL interface provided by the tartiflette-aiohttp implementation.

As far as I know, Insomnia doesn't support websockets. I tried to run the subscription request on Insomnia and I reproduce your issue. I suggest you to use the /graphiql interface which is built-in with tartiflette-aiohttp.

If you re-launch the tutorial from tartiflette-aiohttp-tutorial you should go to the GraphiQL interface and run the subscription request. Everything should works fine 👍

@jamessmith-decisionlab
Copy link
Author

jamessmith-decisionlab commented Nov 25, 2019

Ah, right! Let me quickly give that a go.

@jamessmith-decisionlab
Copy link
Author

Boom! Worked. Many thanks!

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

3 participants