99designs / 99designs/gqlgen

Input converted to a list when it is not

Đang mở
#2,582 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
help wanted
Ngôn ngữ chính
Go
Star
10.8k
Fork
1.3k
Merge trung bình
2 ngày 36 phút
Pull request đã merge (30 ngày)
26

Mô tả

### 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`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.