Hotchocolate: Subscriptions will not work if query sent to route ending in "/" and server is not configured on "/" ending route

Created on 26 Apr 2020  路  3Comments  路  Source: ChilliCream/hotchocolate

Describe the bug
Subscription performance depends on graphql url definition. If configured url is not ending in / executing subscription from playground query will return an error.

To Reproduce
Steps to reproduce the behavior:

  1. Run StarWarz example
  2. Run simple subscription query in Playground
    subscription{ onReview(episode:EMPIRE){ commentary stars } }
  3. You will get and error:
    { "error": "Could not connect to websocket endpoint ws://localhost:5000/graphql/playground/... Please check if the endpoint url is correct." }

Expected behavior
Playground should say Listening..

Desktop (please complete the following information):

  • OS: WIN 10, Chrome Version 81.0.4044.122 (Official Build) (64-bit)
  • Git commit 2d724adcf2f8b45fe268ca0598bd5798b320291f

Additional context
Problem seems to be in combination of how url Playground in using to execute queries and how path comparation is implemented in SubscriptionMiddleware.IsValidPath method. Playground will always add / at the end of url. If server is configured with .UseGraphQL("/graphql"), SubscriptionMiddleware.IsValidPath will return false as "/graphql" and "/graphql/" are not equal. Interesting is that with same configuration of server url queries will executing if you send the both to /graphql and /graphql/ routes.

bug 馃尪 hot chocolate 馃惥 duplicate

Most helpful comment

I got same issue: https://github.com/ChilliCream/hotchocolate/issues/1712 with details why
Track this one: https://github.com/ChilliCream/hotchocolate/issues/1630

For now workaround is:

app.UseWebSockets()
    .UseGraphQL(new QueryMiddlewareOptions
    {
        Path = "/graphql",
        SubscriptionPath = "/graphql/"
    })
    .UseGraphiQL("/graphql")

All 3 comments

I got same issue: https://github.com/ChilliCream/hotchocolate/issues/1712 with details why
Track this one: https://github.com/ChilliCream/hotchocolate/issues/1630

For now workaround is:

app.UseWebSockets()
    .UseGraphQL(new QueryMiddlewareOptions
    {
        Path = "/graphql",
        SubscriptionPath = "/graphql/"
    })
    .UseGraphiQL("/graphql")

Since as @sergeyshaykhullin pointed out this is a duplicate we are gonna close this one and mark it as duplicate.

1630

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergeyshaykhullin picture sergeyshaykhullin  路  3Comments

hognevevle picture hognevevle  路  3Comments

sascha-andres picture sascha-andres  路  4Comments

louisjrdev picture louisjrdev  路  3Comments

jbray1982 picture jbray1982  路  5Comments