如何用gqlgen从Protocol Buffer生成GraphQL查询?枚举报错排查
gqlgen生成GraphQL代码时枚举类型报错问题
问题重现步骤
- 定义包含嵌套枚举的Protocol Buffer文件:
message Advisor { ... enum AdvisorRole { // 枚举值定义 } }
- 通过
protoc-gen-gogo工具生成Go存根代码,在../gen/ProjectService.pb.go中生成的枚举类型为:
type Advisor_AdvisorRole int32 const ( // 枚举常量值 )
- 在
.gqlgen.yaml中配置GraphQL模型映射:
models: ... AdvisorRole: model: github.com/.../gen/pb.Advisor_AdvisorRole
触发的错误
执行go generate ./...时出现编译错误:
C:\Users\...\gql\generated.go:40578:12: ec._AdvisorRole undefined (type *executionContext has no field or method _AdvisorRole)
已尝试的无效操作
将枚举从Advisor消息内部移出,更新配置后重新生成,问题依旧存在。
内容的提问来源于stack exchange,提问作者iapazmino
相关产品推荐
相关产品推荐

