99designs / 99designs/gqlgen

[Bug Report]subscription returns null if query contains certain field

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

描述

### What happened?

```graphql
type Mutation {
post(text: String!): Message!
}
type Subscription {
messageAdded: Message!
}

type Message {
id: ID!
text: String!
testMessage: String!
}
```

``` golang
type Message struct {
ID string `json:"id" gorm:"primary_key:true;type:char(36);column:id"`
Text string `json:"text"`

TestMessage *string `json:"test_message"`
}
```

As schema file shows, post messages will show up in "messageAdded" subscription.

But if subscription queried with `testMessage` field, the result will return `null` as below

Xnip2020-04-10_03-40-34

And if subscription queried without `testMessage` field, the result seems to be normal

![image](https://user-images.githubusercontent.com/22412638/78934573-bddd9d00-7add-11ea-851d-41f8c6eef228.png)

### Minimal graphql.schema and models to reproduce

I made an example project to debug
https://github.com/fredliang44/debug-gqlgen

### versions
- `gqlgen version`?
v0.11.3
- `go version`?
go1.14.1
- dep or go modules?
go mod

贡献指南

打开贡献指南

调研方向

问题出在 gqlgen 库对 subscription 的处理上:当查询中包含 nullable 字段(testMessage)时会出现问题。首先检查 https://github.com/fredliang44/debug-gqlgen 中的示例项目,以重现该 bug。查看 subscription resolver 代码以及字段的解析方式,尤其是 nullable 指针的处理。检查为 Message 类型和 subscription 字段生成的代码。运行示例并在 resolver 周围添加 logging,有助于确定 null 是在哪里引入的。

由索引模型根据 Issue 内容生成。

评估

技术栈
go, graphql
领域
api, backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
40/100

把新 issue 发到你的邮箱

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