-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathTestGenerate-SimpleSubscription.graphql-SimpleSubscription.graphql.go
More file actions
66 lines (54 loc) · 1.78 KB
/
TestGenerate-SimpleSubscription.graphql-SimpleSubscription.graphql.go
File metadata and controls
66 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
package test
import (
"encoding/json"
"errors"
"github.com/Khan/genqlient/graphql"
)
// SimpleSubscriptionResponse is returned by SimpleSubscription on success.
type SimpleSubscriptionResponse struct {
Count int `json:"count"`
}
// GetCount returns SimpleSubscriptionResponse.Count, and is useful for accessing the field via an interface.
func (v *SimpleSubscriptionResponse) GetCount() int { return v.Count }
// The subscription executed by SimpleSubscription.
const SimpleSubscription_Operation = `
subscription SimpleSubscription {
count
}
`
// To unsubscribe, use [graphql.WebSocketClient.Unsubscribe]
func SimpleSubscription(
client_ graphql.WebSocketClient,
) (dataChan_ chan SimpleSubscriptionWsResponse, subscriptionID_ string, err_ error) {
req_ := &graphql.Request{
OpName: "SimpleSubscription",
Query: SimpleSubscription_Operation,
}
dataChan_ = make(chan SimpleSubscriptionWsResponse)
subscriptionID_, err_ = client_.Subscribe(req_, dataChan_, SimpleSubscriptionForwardData)
return dataChan_, subscriptionID_, err_
}
type SimpleSubscriptionWsResponse graphql.BaseResponse[*SimpleSubscriptionResponse]
func SimpleSubscriptionForwardData(interfaceChan interface{}, jsonRawMsg json.RawMessage) error {
var gqlResp graphql.Response
var wsResp SimpleSubscriptionWsResponse
err := json.Unmarshal(jsonRawMsg, &gqlResp)
if err != nil {
return err
}
if len(gqlResp.Errors) == 0 {
err = json.Unmarshal(jsonRawMsg, &wsResp)
if err != nil {
return err
}
} else {
wsResp.Errors = gqlResp.Errors
}
dataChan_, ok := interfaceChan.(chan SimpleSubscriptionWsResponse)
if !ok {
return errors.New("failed to cast interface into 'chan SimpleSubscriptionWsResponse'")
}
graphql.SafeSend(dataChan_, wsResp)
return nil
}