jamesmacaulay / elm-graphql

A GraphQL library for Elm
http://package.elm-lang.org/packages/jamesmacaulay/elm-graphql/latest
BSD 3-Clause "New" or "Revised" License
312 stars 19 forks source link

Subscriptions #37

Open 3nigm4 opened 6 years ago

3nigm4 commented 6 years ago

Hello,

thanks for this library. The latest GraphQL spec was just released and a lot of stuff on your roadmap is now part of the spec, like subscriptions.... https://github.com/facebook/graphql/releases/tag/June2018 ... therefor ... Featuer Request 🥇 Subscriptions

jamesmacaulay commented 6 years ago

Thanks for the heads up about this! I will dig into the new spec and try to put some time into implementation soon.

jamesmacaulay commented 6 years ago

I've now done a fair bit of research into this and unfortunately I've encountered a huge roadblock: the most popular transport protocol for GraphQL subscriptions relies on the client specifying the protocols argument of the WebSocket constructor. Unfortunately the elm-lang/websocket package currently offers no way of specifying this argument:

https://github.com/elm-lang/websocket/issues/20

Apparently the only way to specify websocket subprotocols in Elm right now is to write your websocket code in JS and communicate with ports. That means that pretty much the only worthwhile thing that I can add to this package right now is a way to build decodable subscription requests, but I can't really offer any way to send them and listen for responses from within Elm; the end user will need to figure out that part for themselves with ports :(

Actually there is one relatively popular transport that I may be able to provide an implementation for, which is the one based on Phoenix Channels used by the Absinthe package for Elixir. I'll have to do more research into that and if it ends up making sense I would probably make a separate package for that transport.

3nigm4 commented 6 years ago

Thanks for your research on this!

spunkedy commented 5 years ago

@jamesmacaulay any more thoughts on this? I've used the phoenix channels and JS. But have been wanting to learn elm and wasn't sure if it could replace some of the things I have been wanting to do.