Skip to content

Commit

Permalink
Merge pull request #289 from matiasanaya/feature/subs-adapter
Browse files Browse the repository at this point in the history
Switch to interface{} for Subscribe() return
  • Loading branch information
pavelnikolov authored Nov 28, 2018
2 parents fd99376 + 6fa3ec9 commit 0079757
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gqltesting/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down

0 comments on commit 0079757

Please sign in to comment.