首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gqlgen未能识别自定义类型

gqlgen未能识别自定义类型
EN

Stack Overflow用户
提问于 2022-07-28 13:09:14
回答 1查看 284关注 0票数 2

我的gqlgen模型:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
type Value{
    t: Int64!
}

我一直在想:failed to load schema: graph/schema.graphqls:97: Undefined type Int64.和我不知道为什么。我尝试自己添加一个自定义类型并在models中引用它

代码语言:javascript
复制
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)
}

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

EN

回答 1

Stack Overflow用户

发布于 2022-07-28 13:59:26

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73153517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档