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

Switch to interface{} for Subscribe() return #289

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of this change?

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