1 回答
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
錯(cuò)誤信息來(lái)自graph-gophers/graphql-go internal/exec/resolvable/resolvable.go#makeFieldExec
當(dāng)您解析與現(xiàn)有結(jié)構(gòu)的字段不匹配的模式時(shí)調(diào)用它。
中所示的example/customerrors/starwars.go確實(shí)匹配每個(gè)字段并且不會(huì)觸發(fā)錯(cuò)誤消息:
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
}
它的解析器確實(shí)使用了正確的參數(shù):
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"}
}
嘗試使用該示例來(lái)檢查它是否有效,然后對(duì)其進(jìn)行修改以轉(zhuǎn)換為您自己的代碼。
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
