Skip to content

Commit 1fc61f7

Browse files
committed
subscription: added more comments
1 parent 4e255bf commit 1fc61f7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

subscription.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ type SubscribeParams struct {
2222
}
2323

2424
// SubscriptableSchema implements `graphql-transport-ws` `GraphQLService` interface: https://github.com/graph-gophers/graphql-transport-ws/blob/40c0484322990a129cac2f2d2763c3315230280c/graphqlws/internal/connection/connection.go#L53
25+
// you can pass `SubscriptableSchema` to `graphql-transport-ws` `NewHandlerFunc`
2526
type SubscriptableSchema struct {
2627
Schema Schema
2728
RootObject map[string]interface{}
2829
}
2930

31+
// Subscribe method let you use SubscriptableSchema with graphql-transport-ws https://github.com/graph-gophers/graphql-transport-ws
3032
func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) (<-chan *Result, error) {
3133
c := Subscribe(Params{
3234
Schema: self.Schema,
@@ -39,7 +41,8 @@ func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString stri
3941
return c, nil
4042
}
4143

42-
// Subscribe performs a subscribe operation
44+
// Subscribe performs a subscribe operation on the given query and schema
45+
// currently does not support extensions hooks
4346
func Subscribe(p Params) chan *Result {
4447

4548
source := source.NewSource(&source.Source{
@@ -80,12 +83,14 @@ func Subscribe(p Params) chan *Result {
8083
}
8184

8285
func sendOneResultAndClose(res *Result) chan *Result {
83-
resultChannel := make(chan *Result, 1) // TODO unbuffered channel does not pass errors, why?
86+
resultChannel := make(chan *Result, 1)
8487
resultChannel <- res
8588
close(resultChannel)
8689
return resultChannel
8790
}
8891

92+
// ExecuteSubscription is similar to graphql.Execute but returns a channel instead of a Result
93+
// currently does not support extensions
8994
func ExecuteSubscription(p ExecuteParams) chan *Result {
9095

9196
if p.Context == nil {
@@ -175,7 +180,6 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
175180
resultChannel <- &Result{
176181
Errors: gqlerrors.FormatErrors(fmt.Errorf("the subscription function %q is not defined", fieldName)),
177182
}
178-
179183
return
180184
}
181185
fieldPath := &ResponsePath{
@@ -229,7 +233,6 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
229233

230234
case res, more := <-sub:
231235
if !more {
232-
233236
return
234237
}
235238
resultChannel <- mapSourceToResponse(res)

0 commit comments

Comments
 (0)