-
Notifications
You must be signed in to change notification settings - Fork 662
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
Websockets protocol over Phoenix Channels for Absinthe #3809
Comments
Hi 👋 Thanks for sharing this 💜 ! @mrctrifork might be interested as they asked about this some time ago. I'm personally not super familiar with Absinthe but an early question is whether absinthe uses WebSockets or something else? Your implementation uses |
From what I can see, is does use a WebSocket internally, with a protocol on top, which JavaPhoenixClient implements. In theory this means we could make this a
With the current approach using JavaPhoenixClient (I also think it would make sense for it to be at the
|
Hi @martinbonnin ! FYI, Absinthe is just a GraphQL toolkit for Elixir that does not enforce a particular websocket protocol.
That said, Absinthe however uses Phoenix channels (that uses websockets under the hood) in order for it to manage GraphQL subscriptions.
So I thought using Phoenix channels would be the easiest and fastest way to go with Apollo Kotlin since a client was already out there ! Concerning In the next few days/weeks, I'll try to move forward this roadmap:
|
Sorry @BoD, I didn't see your comment. What do you both think about this roadmap ? It seems to me that it could work for iOS/Android but given my recent knowledge of Kotlin & KMP I may be wrong ! |
🤩
🤩
🤩
I suspect
Last time I checked, there was no native websocket support in Ktor so that wouldn't be an option unless things changed recently? You can reuse All in all, sounds like a great plan 👍 . Let us know if extracting |
No worries at all, we commented concurrently 😅 On my side, what you said looks good. Forking / reworking JavaPhoenixClient could be a big endeavour however (but an interesting one for sure!). About using KTOR client, I think it would be nice to avoid the additional dependency. We also had a recent question about it here. |
I'm glad you both like this plan!
It looks like a race condition haha! Joke aside, for shure reworking JavaPhoenixClient seems a bit challenging but nothing too difficult I guess. What JSON encoding/parsing utilities does the Apollo Client already uses ? I thought using I'll take a look at Thanks for all the inputs! |
Apollo uses its own Json parser borrowed from Moshi (itself borrowed from Gson): Line 31 in 31c873c
You can use Using Let us know how that goes! |
I'd like to avoid as much as possible to depend on Apollo modules for the rewrite of JavaPhoenixClient. I think that the new KotlinPhoenixClient must be agnostic and thus should not be aware of any GraphQL client or protocol that's used on top of it, because its only purpose is to provide a clear and robust API for dealing with Phoenix channels. That said, using I'll keep you informed of the progress of the project in this thread! |
Hi @martinbonnin and @BoD ! Some feedbacks about the project ! I just published a brand new Kotlin Phoenix library on Github and Maven Central ! It now uses Coroutines (with multithreading support for iOS) and is now mobile friendly (Android/iOS) ! The majority of callbacks have been replaced with Kotlin's SharedFlow from which you can now I did my best to properly handle coroutines cancellation and suspending functions but I'd like to have some feedbacks about it. There's still quite a lot of work to do on this project. I'm very new to the Kotlin realm and had to learn a lot, especially concerning coroutines ! Some implementations may not be adequate and may lack optimization or concurrency paradigms understanding, so experienced eyes are very much welcome ! Here's the updated roadmap for next weeks :
|
Hey! Thanks for the update, and congrats on phoenix-kotlin, it looks great 😁 On my side I don't have any feedback at this point but don't hesitate if you want eyes on specific parts! |
Hi ! I'd like to have some advices from Apollo devs concerning my implementation of It's pretty simple: First option: Second option: Both options involve gaining access to some Apollo's internal classes such as I prefer the first option for these reasons :
@BoD @martinbonnin What are your thoughts on this ? |
Hi @ajacquierbret 👋 Congrats on To the question of how to use it in Apollo Kotlin, I'd prefer a standalone The current On the other hand, the The only reason there is Long story short, can you copy/paste |
Hi @martinbonnin ! 👋 Thanks a lot for your precious advices and congratulations ! Following your recommendations, I made a As you said, I think we could extract some parts of the code in order to avoid duplication, but for now it's completely functional. If it doesn't bother you too much, I'd really like to have your opinion on the coroutine dispatcher disposal mechanism that is called right after the Anyway, I published the transport on the repo and updated the READMEs, the whole library should now be theoretically usable. I'll continue to post the project's progress on this thread on each update if you don't mind. If this project satisfies Apollo's requirements and reaches some kind of stability, do you think you could recommend developers which uses Absinthe/Phoenix servers to use Kotlin Phoenix in conjunction with the Apollo Client in order to take advantage of subscriptions ? I was thinking about just adding a simple line to the docs. The updated roadmap lies in the repo : https://github.com/ajacquierbret/kotlin-phoenix |
Nice 🤩
The websocket CoroutineScope uses a single thread dispatcher because:
On the JVM, we need the
Nice 👍 Of course updates are always welcome 💙
Sure thing! I'll open a PR in a few minutes |
If I understand well, Kotlin Native through Coroutines version
I assume this is something that no kind of magical version of Coroutine adresses, so I think I'll have to use a single thread dispatcher anyway.
Because JVM is a target I want Kotlin Phoenix to support pretty soon, I'll make sure the thread is properly shutdown ! Thanks a lot for your PR ! ✨ |
The new memory model will indeed help lifting some restrictions but it's not 100% ready yet. Also we need single-threaded operation for other reasons (shared state and concurrent coroutines) so this will most likely stay like this in the foreseeable future. |
Hi! Some news about the project! I managed to handle single-threaded operations by making a copy of Apollo's Also, I managed to handle socket reconnection by exposing a public Does it sound like a good strategy to you? |
Hi @ajacquierbret. This sounds like a very good strategy to me 👍. I know copy/pasting isn't the greatest feeling out there but in that specific case, I think it's ok and will allow us to keep evolving the public API without risking breaking too many things. |
Hi @ajacquierbret can we close this issue now that https://github.com/ajacquierbret/kotlin-phoenix/tree/main/kotlinphoenix-adapters is released? |
Released in |
Currently, there is no built-in way for the Apollo Client (v3) to communicate over websockets with an Absinthe server. An Absinthe official implementation is available for the JS client, but not for Kotlin.
I decided to build my own and share it with you so that everyone can use it.
Even better, if you (project contributors) think it's something developers out there would definitely use and if it meets the project's code quality requirements, feel free to include it in the repo. If that sounds good to you, I'd be happy to tweak a bit the code in order to meet those requirements.
Here's some important things to know :
WsProtocol
and usesOkHttp3
under the hood.I'd love to have some feedbacks about this !
Installation (be sure to use Apollo v3 !)
Usage
Expect protocol
Actual Android protocol
Actual iOS protocol (TODO)
The text was updated successfully, but these errors were encountered: