async-graphql / examples

217 stars 54 forks source link

Warp + Subscription example not working #21

Closed arlyon closed 4 years ago

arlyon commented 4 years ago

I'm testing this out on macOS (if that is of relevance) and can't get the subscriptions working properly whether that is integration into my codebase or by running the example. Here is the output from the example (with some extra logging):

    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/server`
Playground: http://localhost:8000
[2020-07-02T22:12:07Z INFO  warp::server] listening on http://0.0.0.0:8000
[2020-07-02T22:12:10Z DEBUG hyper::proto::h1::io] read 1848 bytes
[2020-07-02T22:12:10Z DEBUG hyper::proto::h1::io] parsed 12 headers
[2020-07-02T22:12:10Z DEBUG hyper::proto::h1::conn] incoming body is content-length (1468 bytes)
[2020-07-02T22:12:10Z DEBUG hyper::proto::h1::conn] incoming body completed
[2020-07-02T22:12:10Z INFO  warp::filters::log] 127.0.0.1:62976 "POST / HTTP/1.1" 200 "http://localhost:8000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:79.0) Gecko/20100101 Firefox/79.0" 25.517814ms
[2020-07-02T22:12:10Z DEBUG hyper::proto::h1::io] flushed 23023 bytes
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::io] read 503 bytes
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::io] parsed 15 headers
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::conn] incoming body is empty
[2020-07-02T22:12:11Z INFO  warp::filters::log] 127.0.0.1:62977 "GET / HTTP/1.1" 200 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:79.0) Gecko/20100101 Firefox/79.0" 142.884µs
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::io] flushed 19149 bytes
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::io] read 0 bytes
[2020-07-02T22:12:11Z DEBUG hyper::proto::h1::conn] read eof
[2020-07-02T22:12:12Z DEBUG hyper::proto::h1::io] read 1848 bytes
[2020-07-02T22:12:12Z DEBUG hyper::proto::h1::io] parsed 12 headers
[2020-07-02T22:12:12Z DEBUG hyper::proto::h1::conn] incoming body is content-length (1468 bytes)
[2020-07-02T22:12:12Z DEBUG hyper::proto::h1::conn] incoming body completed
[2020-07-02T22:12:12Z INFO  warp::filters::log] 127.0.0.1:62976 "POST / HTTP/1.1" 200 "http://localhost:8000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:79.0) Gecko/20100101 Firefox/79.0" 26.931438ms
[2020-07-02T22:12:12Z DEBUG hyper::proto::h1::io] flushed 23023 bytes

And from the playground:

{
  "error": "Could not connect to websocket endpoint ws://localhost:8000/. Please check if the endpoint url is correct."
}

Seems like the subscription isn't being called at all. This was tested on the exact deps in cargo, as well as the latest versions of each of the libraries.

sunli829 commented 4 years ago

graphql_subscription filter should be used first, I've fixed the example.

let routes = graphql_subscription(schema)
        .or(graphql_playground)
        .or(graphql_post);
arlyon commented 4 years ago

Hah feel bad for missing that. Thanks!