Skip to content

Commit 183515e

Browse files
committed
subscription: SubscriptableSchema conforms to ws interface
1 parent 1fc61f7 commit 183515e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

subscription.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type SubscriptableSchema struct {
2929
}
3030

3131
// Subscribe method let you use SubscriptableSchema with graphql-transport-ws https://github.com/graph-gophers/graphql-transport-ws
32-
func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) (<-chan *Result, error) {
32+
func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) (<-chan interface{}, error) {
3333
c := Subscribe(Params{
3434
Schema: self.Schema,
3535
Context: ctx,
@@ -38,7 +38,20 @@ func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString stri
3838
RootObject: self.RootObject,
3939
VariableValues: variables,
4040
})
41-
return c, nil
41+
to := make(chan interface{})
42+
go func() {
43+
defer close(to)
44+
select {
45+
case <-ctx.Done():
46+
return
47+
case res, more := <-c:
48+
if !more {
49+
return
50+
}
51+
to <- res
52+
}
53+
}()
54+
return to, nil
4255
}
4356

4457
// Subscribe performs a subscribe operation on the given query and schema

0 commit comments

Comments
 (0)