1 回答

TA贡献1906条经验 获得超3个赞
错误信息来自graph-gophers/graphql-go
internal/exec/resolvable/resolvable.go#makeFieldExec
当您解析与现有结构的字段不匹配的模式时调用它。
中所示的example/customerrors/starwars.go
确实匹配每个字段并且不会触发错误消息:
var Schema = `
schema {
query: Query
}
type Query {
droid(id: ID!): Droid!
}
# An autonomous mechanical character in the Star Wars universe
type Droid {
# The ID of the droid
id: ID!
# What others call this droid
name: String!
}
`
type droid struct {
ID graphql.ID
Name string
}
它的解析器确实使用了正确的参数:
type Resolver struct{}
func (r *Resolver) Droid(args struct{ ID graphql.ID }) (*droidResolver, error) {
if d := droidData[args.ID]; d != nil {
return &droidResolver{d: d}, nil
}
return nil, &droidNotFoundError{Code: "NotFound", Message: "This is not the droid you are looking for"}
}
尝试使用该示例来检查它是否有效,然后对其进行修改以转换为您自己的代码。
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报