@@ -22,11 +22,13 @@ type SubscribeParams struct {
22
22
}
23
23
24
24
// 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`
25
26
type SubscriptableSchema struct {
26
27
Schema Schema
27
28
RootObject map [string ]interface {}
28
29
}
29
30
31
+ // Subscribe method let you use SubscriptableSchema with graphql-transport-ws https://github.com/graph-gophers/graphql-transport-ws
30
32
func (self * SubscriptableSchema ) Subscribe (ctx context.Context , queryString string , operationName string , variables map [string ]interface {}) (<- chan * Result , error ) {
31
33
c := Subscribe (Params {
32
34
Schema : self .Schema ,
@@ -39,7 +41,8 @@ func (self *SubscriptableSchema) Subscribe(ctx context.Context, queryString stri
39
41
return c , nil
40
42
}
41
43
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
43
46
func Subscribe (p Params ) chan * Result {
44
47
45
48
source := source .NewSource (& source.Source {
@@ -80,12 +83,14 @@ func Subscribe(p Params) chan *Result {
80
83
}
81
84
82
85
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 )
84
87
resultChannel <- res
85
88
close (resultChannel )
86
89
return resultChannel
87
90
}
88
91
92
+ // ExecuteSubscription is similar to graphql.Execute but returns a channel instead of a Result
93
+ // currently does not support extensions
89
94
func ExecuteSubscription (p ExecuteParams ) chan * Result {
90
95
91
96
if p .Context == nil {
@@ -175,7 +180,6 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
175
180
resultChannel <- & Result {
176
181
Errors : gqlerrors .FormatErrors (fmt .Errorf ("the subscription function %q is not defined" , fieldName )),
177
182
}
178
-
179
183
return
180
184
}
181
185
fieldPath := & ResponsePath {
@@ -229,7 +233,6 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
229
233
230
234
case res , more := <- sub :
231
235
if ! more {
232
-
233
236
return
234
237
}
235
238
resultChannel <- mapSourceToResponse (res )
0 commit comments