0
我想請教一下GraphQL 該代碼將失敗,並顯示錯誤現場ARGS拒絕時返回的功能不會反對
Error: Mutation.addUser args must be an object with argument names as keys.
這裏是代碼
const Schema = new GraphQLObjectType({
name: "Mutation",
description: "Mutation schema",
fields() {
return {
// Add user
addUser: {
type: UserSchema,
args:() => {
return {
firstName: {
type: GraphQLString
}
};
},
resolve(_, args){
return Db.models.user.update(() => {
return _.mapValues(args, (v, k) => {
return args[k];
});
}, {
returning: true
});
}
}
};
}
});
但是,這代碼正常工作
const Schema = new GraphQLObjectType({
name: "Mutation",
description: "Mutation schema",
fields() {
return {
// Add user
addUser: {
type: UserSchema,
args: {
firstName: {
type: GraphQLString
},
lastName: {
type: GraphQLString
}
},
resolve(_, args){
return Db.models.user.update(() => {
return _.mapValues(args, (v, k) => {
return args[k];
});
}, {
returning: true
});
}
}
};
}
});
爲什麼args
不能從函數返回對象?
你能舉個例子來實現嗎? –
@HabibRohman你需要哪個部分的例子?在你發佈的代碼中,'fields'本身就是一個函數。 –
@HabibRohman什麼我可以幫忙? –