-
-
Notifications
You must be signed in to change notification settings - Fork 107
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… where be there dragons? #43
Comments
Hey Brian! Thanks for the question. You’re right it would be good to be more specific, and indeed I know more now and have gone through some design iterations since I wrote that warning a few weeks ago. It’s definitely closer to a “I think it's OK but want people to test” warning than a crazy experiment warning. @ssbb is starting to integrate it into his production application and so far he says it’s looking good! And the happy path appears to be working great! My biggest concern is that there seem to be some major issues with the Elm websockets package. There are several stale github issues in that package, and any core issues there prevent any Elm code using websockets from being 100% stable. In particular, the issue I have observed is that if there’s an issue with the server connection the websockets package will try to create a new connection every second or so, but as far as the consumer is concerned (in this case Graphqelm), the connection is still healthy. Unfortunately I lost the slack history for the relevant discussion, @ssbb had some thoughts on this and noted some relevant issues on Github (and that https://github.com/fbonetti/elm-phoenix-socket/issues had encountered some similar problems). I slacked him about it in #graphql and I’ll reply here when I get that context back. I would love to get some help in general in understanding these issues around corner cases, both from people willing to test it and from anyone with knowledge about the Elm WebSockets package. It would be awesome to compile a really solid list of how to reproduce these issues, and which WebSockets issues they stem from (or what possible workarounds Graphqelm could use if possible). I don’t think there’s a ton more I can do to add stability at this point without some fixes to the WebSockets package, but compiling that information and documenting it thoroughly would at the very least allow me to be more specific in warning users, and would allow me to request fixes to the WebSockets package based on these concrete issues. Besides that major concern, here is the status of Subscriptions in Graphqelm: Looking Good
Known Missing
I’ll work on improving the warning in the docs to be more concrete once I’m back from my trip in a week or so. Thanks again for starting the discussion! |
wow! Thank you for the very detailed answer. I'll give it a shot, then. 😄 |
Dillon, thanks for the detailed writeup. I have been giving some thought lately to whether all this should be built into this project. It seems to me that this project could remain focused on being the source for autogeneration of elm types from a graphql schema. If you think of it that way, your goal for subscriptions would then be to provide a standard set of event / hooks for third-party socket libraries to adapt to. https://github.com/fbonetti/elm-phoenix-socket is a nice one for phoenix and no doubt there are other quality projects. An adapter would be written for each third-party lib to integrate with this project. While I am confident you could write your own support, getting this right is not that easy. The socket needs to reconnect, then the channels, then the subscriptions and it all needs to be resilient to a connection that may be flapping. If you structured things right you could always write your own socket support in parallel, as a sibling project. On the other hand, if socket support remains an integral part of this project, you have fine-grained control but you take on an expanding set of issues that seem adjacent to your core mission. |
@akeating thanks for the thoughtful response, I really appreciate your thought process here. @ssbb just reported back to me on his experiments in using Graphqelm Subscriptions in his app, and he told me he ran into some issues with the channel reconnect logic that I mentioned above. He just expressed a similar opinion that he thinks that Graphqelm should let framework-specific packages handle the Subscription transport layer, and Graphqelm should only handle building GraphQL documents and decoding responses. Here are some points he brought up:
Given all the considerations above I think it makes sense to do as both of you suggest @akeating and @ssbb and to decouple the transport knowledge from Graphqelm. It would be awesome to make this seamless and foolproof so that “if it compiles it works”. We’ll have to play around with the API both on the Graphqelm-end and in the framework specific libraries (I’ll likely make some pull requests and ask for help from people who are experimenting to develop some nice APIs). It’s super helpful to get concrete code snippets on how this is happening, so keep the feedback coming! Thanks all for this great discussion! For reference, here is how @ssbb is setting up the GraphQL Subscription using https://github.com/saschatimme/elm-phoenix: subscriptionPayload =
JE.object
[ ( "query", Graphqelm.Document.serializeSubscription subscriptionDocument |> JE.string )
]
subscriptionMessage =
Push.init "__absinthe__:control" "doc"
|> Push.withPayload subscriptionPayload And then |
@ssbb I made the GraphQL response decoders public (see Then based on your feedback I will figure out the next steps for a migration path to move Subscriptions to outside packages. I'm thinking it will look something like: Documentation
3rd Party Packages
Remove deprecated
|
Great, thank you! I have same function already (it's just an JSON decoder at all). Since I am decoding raw subscription data I just using
I have a deadline right now, but will able to create an example of integrating with elm-phoenix later (need to fix my PR also). Anyway after some work on it I can say it's a good idea to abstract subscriptions and should be easy to create packages for integration. |
@dillonkearns How has this matured? We are looking at starting to use subscriptions now, and Graphqelm has been fantastic for us so far! |
Hey @anagrius, I'm glad to hear Graphqelm been a good experience for you and your team! The status is that I'm looking to remove the built-in Subscription functionality as discussed here, but I'll need help from users who are experimenting with Subscriptions, such as @ssbb and perhaps you and your team, to make the transition. It's definitely a safe bet to go ahead and use |
I've gone ahead and officially removed the I would love to hear feedback about this! If you are integrating GraphQL subscriptions using Thanks everyone who chimed in on this topic, and thanks Richard for opening the issue! See the changelog for more details. |
Any chance of updating the old example to show how the new package can be used with a manual/externally supplied connection? |
Hello @JonRowe, thank you for the suggestion! That's a great idea. I created this issue to track making an Ellie example using the new approach. There are some reasons it might make sense to hold off on this (I captured them in #70). Here are the notes I wrote there for reference:
|
@dillonkearns I have just started using this package with an Elixir/Absinthe backend. I like it so far and appreciate your work very much! Do you have any suggestions on how GQL subscriptions can be handled until an elm/websocket package comes along? |
Hello @MonadicT, I'm glad you're enjoying the library! It's actually not that different to use the Elm websockets package compared to going out to a port. In fact, in some ways it's simpler because you can use Phoenix's javascript code for connecting to channels: https://hexdocs.pm/phoenix/js/ All you have to do is wrap some ports that use that library on the JS side, and send a message over to Elm every time new data comes in. You'll need a "Cmd port" (Elm to JS) to send the query over to tell JavaScript to start the subscription. Then you can listen for a If you need more details, ask on the #graphql channel in the Elm Slack: https://elmlang.herokuapp.com/. There are lots of friendly people there who can give you a quick answer to your question! |
@dillonkearns Thanks for your quick response! Guess I will just use ports. Thanks for the JS code pointer. |
The subscriptions docs for GraphQL warn about big 'ol breaking changes to the mechanisms they use, but don't say what might bite or be awful.
Would you mind elaborating on that, and why it wouldn't be ready? Is it an "I think it's OK but want people to test" or "this is more-or-less a huge experiment and really bad in odd ways so probably don't touch it until it stabilizes"?
The text was updated successfully, but these errors were encountered: