Skip to content
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 #16

Open
paralin opened this issue Jan 2, 2017 · 3 comments
Open

Subscriptions #16

paralin opened this issue Jan 2, 2017 · 3 comments

Comments

@paralin
Copy link

paralin commented Jan 2, 2017

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.Context argument to the resolve parameters. Use a context for each request. Similar to how go-grpc does 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.

@kumarharsh
Copy link
Member

@paralin we're ourselves looking to add subscriptions in the near future. We'll keep this issue open, and post updates when we get around to it. @atrniv would be better placed to discuss the technical details of the design.

@smithaitufe
Copy link

Attention
@atrniv @kumarharsh

Please what is the current state with Subscription? It's been 11 months now since the last discussion in this thread.

@fungl164
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants