我的gqlgen模型:
models:
Int64:
model:
- github.com/99designs/gqlgen/graphql.Int64
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int32
- github.com/99designs/gqlgen/graphql.Int64在schema.graphql中:
type Value{
t: Int64!
}我一直在想:failed to load schema: graph/schema.graphqls:97: Undefined type Int64.和我不知道为什么。我尝试自己添加一个自定义类型并在models中引用它
func MarshalInt64(t int64) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, strconv.FormatInt(t, 10))
})
}
func UnmarshalInt64(v interface{}) (int64, error) {
if res, ok := v.(json.Number); ok {
return res.Int64()
}
if res, ok := v.(string); ok {
return json.Number(res).Int64()
}
if res, ok := v.(int64); ok {
return res, nil
}
if res, ok := v.(*int64); ok {
return *res, nil
}
return 0, fmt.Errorf("could not convert %v of type %T to Int64", v, v)
}但同样的问题也会发生。有什么想法吗?
发布于 2022-07-28 13:59:26
我发现了问题所在,似乎需要将自定义类型直接添加到模式中。
将scalar Int64添加到我的schema.graphqls中解决了这个问题。
https://stackoverflow.com/questions/73153517
复制相似问题