99designs / 99designs/gqlgen

Bug with multi-resolver for federation and custom ID type

Đang mở
#3,788 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
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ả

https://github.com/99designs/gqlgen/pull/3632 introduced a bug in generating our federated graph.

Our schema looks like this:
```graphqls
extend type Thing @key(fields: "id") @entityResolver(multi: true) {
id: ID!
}
```

The generated code in federation.go changed from:
```go
func (ec *executionContext) resolveManyEntities(
...
case "Thing":
...
case "findManyThingByIDs":
...
id0, err := ec.unmarshalNID2string(ctx, rep.entity["id"])
```

to
```
id0, err := ec.unmarshalNID2githubᚗcomᚋsomethingᚋscalarᚐID(ctx, rep.entity["id"])
```

We have a custom scalar ID model (I don't know why TBH, looks like something silly we did a long time ago and forgot about).

The ID type:
```go
type ID string

func (id ID) MarshalJSON() ([]byte, error) {
return strconv.AppendQuote(nil, string(id)), nil
}

func (id ID) MarshalGQL(w io.Writer) {
_, _ = w.Write(strconv.AppendQuote(nil, string(id)))
}

func (id *ID) UnmarshalGQL(v interface{}) error {
switch v := v.(type) {
case string:
*id = ID(v)
return nil
case int64:
*id = ID(strconv.FormatInt(v, 10))
return nil
default:
return stacktrace.NewError("%T is not an ID", v)
}
}
```

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.