From 6fa3ec92f38c9e26f76f5fa8eee9541ef49b72e3 Mon Sep 17 00:00:00 2001 From: Matias Anaya Date: Tue, 13 Nov 2018 15:50:56 +1100 Subject: [PATCH] Switch to interface{} for Subscribe() return --- gqltesting/subscriptions.go | 2 +- subscriptions.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gqltesting/subscriptions.go b/gqltesting/subscriptions.go index ea25514e..b18ab6a5 100644 --- a/gqltesting/subscriptions.go +++ b/gqltesting/subscriptions.go @@ -57,7 +57,7 @@ func RunSubscribe(t *testing.T, test *TestSubscription) { var results []*graphql.Response for res := range c { - results = append(results, res) + results = append(results, res.(*graphql.Response)) } for i, expected := range test.ExpectedResults { diff --git a/subscriptions.go b/subscriptions.go index a78aa765..fbec253a 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -19,14 +19,14 @@ import ( // If the context gets cancelled, the response channel will be closed and no // further resolvers will be called. The context error will be returned as soon // as possible (not immediately). -func (s *Schema) Subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) (<-chan *Response, error) { +func (s *Schema) Subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) (<-chan interface{}, error) { if s.res == nil { return nil, errors.New("schema created without resolver, can not subscribe") } return s.subscribe(ctx, queryString, operationName, variables, s.res), nil } -func (s *Schema) subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) <-chan *Response { +func (s *Schema) subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) <-chan interface{} { doc, qErr := query.Parse(queryString) if qErr != nil { return sendAndReturnClosed(&Response{Errors: []*qerrors.QueryError{qErr}}) @@ -69,7 +69,7 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam } responses := r.Subscribe(ctx, res, op) - c := make(chan *Response) + c := make(chan interface{}) go func() { for resp := range responses { c <- &Response{ @@ -83,8 +83,8 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam return c } -func sendAndReturnClosed(resp *Response) chan *Response { - c := make(chan *Response, 1) +func sendAndReturnClosed(resp *Response) chan interface{} { + c := make(chan interface{}, 1) c <- resp close(c) return c