99designs / 99designs/gqlgen

No validation error when resolver output is nullable although in the schema the output is specified as non-nullable

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

描述

### What happened?
While trying to solve a coworker's problem who was getting this error:
```
{
"errors": [
{
"message": "must not be null",
"path": [
"applications"
]
}
],
"data": null
}
```
We realized that the schema output does not match the resolver output, but he did not get any
errors and we were able to run everything except the vague error in the response.

### What did you expect?
To get the error identifying that the resolver output does not match the written schema output in validation.
Something like this:
validation failed: ... cannot use &(queryResolver literal) (value of type *queryResolver) as QueryResolver value in return statement: wrong type for method Applicantions

### Minimal graphql.schema and models to reproduce
#### Schema:
```
type Application {
id: ID!
...
}

type QueryApplicationsOutput {
applications: [ApplicationOutput!]
...
}

type ApplicationOutput {
id: ID!
...
}

type Query {
applications(limit: Int, offset: Int): QueryApplicationsOutput!
}
```

#### Model:
```
type Application struct {
ID uuid.UUID `json:"id"`
...
}

type QueryApplicationsOutput struct {
Applications []*ApplicationOutput `json:"applications"`
...
}

type ApplicationOutput struct {
ID uuid.UUID `json:"id"`
...
}
```

#### Resolver:
```
func (r *queryResolver) Applications(ctx context.Context, limit *int, offset *int) (*QueryApplicationsOutput, error) {
return nil, nil
}
```

### versions
- `gqlgen version`? v0.11.3
- `go version`? 1.13
- dep or go modules? go modules

贡献指南

打开贡献指南

调研方向

这个 issue 是关于当 resolver 为非空 GraphQL 类型返回 nil 时缺少 validation。查看 gqlgen 中的代码生成和 validation 逻辑,可能在 internal/exec 或 internal/validation。先找到 resolver 输出是在哪里根据 schema 进行检查的。运行提供的示例以查看错误,然后添加 validation 来尽早捕获 mismatch。检查与 nullability 和 validation 相关的测试文件。

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

评估

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

把新 issue 发到你的邮箱

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