Replies: 2 comments 3 replies
-
Thank you!! It's even better than I envisioned it.
I suggest we move this conversation to a PR from the "demo". It seems like 80% of it is working from what I've seen.
What do you think? What should I help you with? |
Beta Was this translation helpful? Give feedback.
3 replies
-
This is now fairly outdated and I'm just cleaning up. Sounds like it was mostly completed anyway, closing 👍 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
See prototype here: main...Amzd:main
Web sockets
I've done some research and to work with subscriptions you need to use web sockets.
There is three big web socket libraries;
SocketRocket has not been updated in 5 years so I think that's a no.
Starscream gets updated regularly and apollo uses this too. It looks ok from initial checking.
Apple's WebSocket support is iOS 13 and up, since I no longer develop new features for iOS 12 this is not an issue for me so I went ahead and created a working prototype with this.
Changes
This is changes I propose to make
SwiftGraphQL.observe
orSwiftGraphQL.listen
(need feedback on naming) which allows for cancelling the websocketCompile time access to operation type
Right now we have the operation type as an enum. I propose changing that to an actual type so we can type check against it with generics.
Removing:
Document.swift
Adding:
Operation.swift
In CodeGen we need to change the type:
CodeGen/Operation.swift
What this enables is type checking for the type of operation so you cannot call SG.observe() with a Query.
Adding
SwiftGraphQL.observe
orSwiftGraphQL.listen
(need feedback on naming) which allows for cancelling the websocketMy SG.observe() builds a query similar to SG.send, but then sends it into a web socket which calls the onEvent every time an event happens.
Since you don't want this to happen indefinitely I have a Token object that when released from memory stops the web socket:
A way to set availability of an operation (since in my example I use Apples web sockets which are iOS 13+)
I replaced the operation parameter in GraphQLCodegen.generateOperation with availibity that takes an optional String which I add before each extension if present.
Beta Was this translation helpful? Give feedback.
All reactions