const Photo = new GraphQLObjectType({
name: 'Photo',
description: 'Photo',
fields: () => ({
upload: {type: GraphQLString},
facebook: {type: GraphQLString},
linkedin: {type: GraphQLString}
})
});
const Account = new GraphQLObjectType({
name: 'Account',
description: 'Account',
fields: () => ({
_id: {type: new GraphQLNonNull(GraphQLString)},
created_on: {type: GraphQLDate},
username: {type: GraphQLString},
password: {type: GraphQLString},
photo: {type: Photo},
})
});
export default Account;
我有一个变异查询来更新记录:
mutation {
updateAccountById(id: "587c84c713742bf421f3fa4e", update: {photo: {upload: "test1"}}) {
photo {
upload
facebook
linkedin
}
}
}
在:
photo{
upload:"test1"
facebook: "test2"
linkedin: "test3"
}
在: 这会将照片属性更新为
photo{
upload:"test1"
}
有没有办法只更新照片字段?任何帮助,将不胜感激。提前谢谢。
突变:
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
updateAccountById:{
type: Account,
args: {
id:{type: new GraphQLNonNull(GraphQLString)},
update: {
type: new GraphQLInputObjectType({
name: 'update_account_byId',
fields: Account.getFields()
})
}
},
resolve: function(rootValue, args) {
let update = Object.assign({}, args.update);
db.account.update({ _id: pmongo.ObjectId(args.id.toString())}, {$set: update},{multi:true});
}
}
}
});