-
Notifications
You must be signed in to change notification settings - Fork 20
Description
I'm using the library now in my code and quite like how robust it is.
Can we add subscriptions? They are supported in the GraphQL spec and Apollo client.
https://dev-blog.apollodata.com/graphql-subscriptions-in-apollo-client-9a2457f015fb#.lkud9zs7b
subscription comments($repoName: String!) {
newComments(repoName: $repoName) {
content
postedBy {
username
}
postedAt
}
}
From the article:
Based on the subscription field name “newComments” and a mapping from subscription names to channels, the server subscribes to one or more pub/sub channels. When something is published to one of these channels, the server runs the GraphQL query specified in the subscription and sends a full new result to the client.
My API surface idea for this is:
- Add a
net.Contextargument to the resolve parameters. Use a context for each request. Similar to howgo-grpcdoes it. - When a streaming call starts, create a context, and call the resolver functions. If a resolver function needs to return a stream of objects, instead of an array, it can return a
chan interface{}channel. - The call continues to execute and finishes when one of (Context ended/closed, Result channel closed) occurs.
It's a little tough to work around the current pattern of Execute -> return result. I think the best way to handle this is to change the Execute function OR add another function that returns an object instead of a map[string]interface{}, and also accepts a root Context. In this object we can define how the result is shown. If it's a single map[string]interface{} result, set the result field of that object. Otherwise, set the resultChan fields on that object.