-
Notifications
You must be signed in to change notification settings - Fork 58
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
Subscription support #10
Comments
Subscription-definition (on the server side) should look like the following example (from jeggy): data class MyNormalValueClass(val value: String)
class MyTypeEvent(val value: MyNormalValueClass) : PubSubEventSealedClass()
...
val pubsub = PubSub<MyTypeEvent, MyNormalValue> { event: MyTypeEvent ->
// This callback would be called once every event and sent to all subscriptions
event.value
}
mutation("add") {
resolver<MyNormalValueClass> { value: String ->
val returnValue = MyNormalValueClass(value)
pubsub.publish(MyTypeEvent(returnValue))
returnValue
}
}
subscription<MyNormalValueClass>("listenToAdds") {
pubsub.iterator()
} The Client will send a subscriptionquery and will receive a stream of data as response: schema.execute("subscription { numbers }").forEach(::println)
// Output:
// 1
// 2
// ... |
I'm currently working on this and it's really hard to accomplish. |
@nidomiro yeah, rewriting lots of code sounds like the right route, but we should be careful before doing so. I can see you started on a Flow implementation, which I really like 👍 But I think it's probably a bit too early to implement this. I would love to have the #37 and probably alongside a spring module implemented. And by having those resolved before starting on flows or something else, we will then have more concrete examples on how the full implementation of GraphQL from server side all the way to the client will work. |
@nidomiro I can see you are investigating ways on how to solve this. If you are considering making big changes to the internal setup. One other thing I would love to keep in mind when designing some new structure is the DataLoader(#19) |
By implementing this feature I learn a lot about the lib. My activity was low and will be for a couple of weeks, because I have much to do at work. |
Merging won't be an option... I tried, but because the files where moved I would have to copy every change manually to the new location... |
@nidomiro I recently added subscriptions to micronaut, and didn't had to change any existing code. So if you had to rewrite a lot of code that sounds a bit worrying. There is also https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md which some of the clients kind of suspect as how it should work. There is also https://github.com/excitement-engineer/ktor-graphql/tree/master/src/main/kotlin/ktor/graphql but I think have a pure Kotlin implementation will better and more performant. I'm going to give it a try using http://adavis.info/2018/02/graphql-api-in-kotlin.html as inspiration. Fist to get just the query working, then maybe to implement subscriptions. |
@gklijs Thanks for your input. Maybe rewriting a lot is not the right way. Maybe I need to think about the problem for a bit longer. |
How I did it, is having a separate controller, that instead of using a http request and response, uses a websocket. From that controller you can re-use a lot of the code since resolving the querie, etc works just the same as if it was a http request. Once you resolve and it turns out it was a query or mutation you can return those to the client. When it's a subscription it needs some more magic, since you need to subscribe to the publisher. |
Are subscriptions still not yet supported? |
Still not really supported 😞 But I'm including this in a bigger update that I'm currently working on. Where the results from This is still all work in progress, so any ideas of how this API should look are welcome. |
This is seen as the new/updated protocol. https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md so following that will probably means is compatible with most client implementations. |
@jeggy In what stage is this update at this moment? Any way we could help/contribute? |
Would be great to have proper subscription support. |
@jeggy Would appreciate an update on this. |
I see messages like subscriptions are not fully supported yet. Does that mean there is partial support? |
Would love to get a reply from jeggy on this, but i strongly suspect that this project has been abandoned. If you prefer to stick with KGraphQL and you want subscription support then you could try to take some code from graphql-kotlin. |
Copied from: pgutkowski#27
The text was updated successfully, but these errors were encountered: