Input converted to a list when it is not
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### What happened?
Hello all. I have a schema describing github repository, and each repository has a field `admins`, which is of type `[Account]`. `[Account]` in my case is an interface, thus `admins` is a list of interfaces:
The respective graphql (excerpt) is as follows:
```graphql
interface Account {
...
}
type GithubUserAccount implements Account {
# CID is github id of form "https://github.com/[handle]"
cid: ID!
name: String
}
type GithubRepository {
cid: ID!
...
admins: [Account!]
}
```
and the generated resolvers are
```golang
type Account interface {
IsAccount()
...
}
type AccountCreateInput struct {
// Cid acts as ID
Cid *string `json:"cid,omitempty"`
GithubUserAccount *GithubUserAccountCreateInput `json:"GithubUserAccount,omitempty"`
...
}
type GithubRepositoryCreateInput struct {
Cid string `json:"cid"`
...
Admins []*AccountCreateInput `json:"admins"
}
```
Now, when I try to do an insertion via the following query:
```
mutation testMutation($input: GithubRepositoryCreateInput!) {
createGithubRepository(input: $input) {
...
}
}
```
with vars:
```
"input": {
"cid": "testrepo",
"admins": {
"GithubUserAccount": {
"cid": "alice",
"name": "alice"
},
"GithubUserAccount": {
"cid": "bob",
"name": "bob"
},
"GithubUserAccount": {
"cid": "carol",
"name": "carol"
}
}
}
}
```
Only `Carol` is created as an account, and the input is implicitly converted to a list:
```
model.GithubRepositoryCreateInput {testrepo testurl 0x400039a140 [] [] [] [] [] [0x400006df80] [] [] [] [] [] [] }
```
(admins are the field `[0x400006df80]` corresponding to a `[]*model.AccountCreateInput`)
If I pass a correct input as below, three users are created:
```
{
"input": {
"cid": "testrepo",
"admins": [
{
"GithubUserAccount": {
"cid": "alice",
"name": "alice"
}
},
{
"GithubUserAccount": {
"cid": "bob",
"name": "bob"
}
},
{
"GithubUserAccount": {
"cid": "carol",
"name": "carol"
}
}
]
}
}
```
### What did you expect?
I would expect a GraphQL validation error.
### versions
- `go run github.com/99designs/gqlgen version`: `v0.17.22`
- `go version`: `go1.19.7 linux/arm64`
贡献指南
评估
这个 Issue 还没有评估数据。