我想实现graphql的这种变异
mutation {
SysConfigFile {
UpdateServer(Port: "8080") {
Port
}
}
}
然后我通过允许代码进行构建:
var UpdateServerType = graphql.NewObject(graphql.ObjectConfig{
Name: "UpdateServer",
Fields: graphql.Fields{
"Port": &graphql.Field{
Type: graphql.String,
},
},
})
var UpdateSysConfigFileType = graphql.NewObject(graphql.ObjectConfig{
Name: "UpdateSysConfigFile",
Description: "Update system config",
Fields: graphql.Fields{
"UpdateServer": &graphql.Field{
Type: UpdateServerType,
Args: graphql.FieldConfigArgument{
"Port": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
log.Println("UpdateServer resolved.")
return "8090", nil
},
},
},
})
var mutationType = graphql.NewObject(graphql.ObjectConfig{
Name: "Mutation",
Description: "mutation cmd",
Fields: graphql.Fields{
// Not OK
"SysConfigFile": &graphql.Field{
Type: UpdateSysConfigFileType,
},
},
})
它可以在graphql api中使用,但不能放入resolve函数。 结果是:Result
逻辑错误吗? 还是有毛病?