99designs / 99designs/gqlgen

Issue with GraphQL subscriptions ! kinda ?

未关闭
#2,415 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?

Hey guys, so i was trying out GraphQL subscriptions and it does kinda work.

So here is the overview. i have ZeroMQ server which streams the data to Golang client and then UI gets the data through GraphQL.

```ZeroMQ Server(Python) --> ZeroMQ Client (Go) --> GraphQL Subscription --> UI ```

![sample](https://user-images.githubusercontent.com/48326585/199944196-5c6f90e5-cb68-4d97-bd7d-76b549495abc.gif)

* Right Window is the socket server running on python
* Left Window is the Go Client.

#### GraphQL Output

Graphql

### What did you expect?

I thought it was going to be fast since the socket response on the go side without GraphQL Subscription is great. Am i missing something with respect to tick can i make it lower i think its 1 min tick on the websocket end.

### Minimal graphql.schema and models to reproduce

```schema.graphql```
```graphql
type Data{
image: String!
temperature: Int!
relhumidity: Int!
}

# create a subscription
type Subscription {
data: Data!
}
```

```models.go and subscription Func()```
```go
func (r *subscriptionResolver) Data(ctx context.Context) (<-chan *model.Data, error) {
subscriber, _ := zmq.NewSocket(zmq.SUB)
defer subscriber.Close()

subscriber.Connect("tcp://localhost:5555")
subscriber.SetSubscribe("")
for {
// read message contents
incoming_data, _ := subscriber.Recv(0)
fmt.Printf("\nRecevied: [%s]", incoming_data)
contents := strings.Fields(incoming_data)
data2, _ := strconv.Atoi(string(contents[1]))
data3, _ := strconv.Atoi(string(contents[2]))

reponse_data := &model.Data{
Image: contents[0],
Temperature: data2,
Relhumidity: data3,
}

// return reponse_data as a channel
ch := make(chan *model.Data)
go func() {
ch <- reponse_data
}()
return ch, nil

}
}

```

### Versions
- `gqlgen version` : `v0.17.20`
- `go version`: `1.19`

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。