gqlgen无法识别自定义类型



我的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)
}

但同样的问题也发生了。有什么想法吗?

我发现了问题所在,似乎需要将自定义类型直接添加到架构中。

scalar Int64添加到我的schema.graphqls中解决了这个问题。

最新更新