我正在将 cassandra 与 graphql 和 express 一起使用。在进行突变时,数据库会更新,但它不显示字段,而是只显示 null。使用 console.log 检查数据后,我可以看到它打印在终端上。
突变代码,
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
add_user: {
type: UserType,
args: {
username: { type : GraphQLString},
email: { type : GraphQLString},
name: { type : GraphQLString},
password: { type : GraphQLString}
},
resolve(parent, args){
const query = 'INSERT INTO users(username, email, name, password) VALUES (?, ?, ?, ?) ';
client.execute(query, [args.username, args.email, args.name, args.password])
.then(result => {
const query = 'SELECT * FROM users WHERE username = ? ';
return client.execute(query, [args.username])
.then(result => {
console.log(result.rows[0]);
return result.rows[0];
});
});
}
}
}
});
我得到了什么
{
"data": {
"add_user": null
}
}
在使用这个
mutation{
add_user(username: "ABCdef", email: "abc.def@ddv.com", name: "ABCDEF", password: "abcdxyz"){
username
email
name
}
}
更新可以确认
query{
user(username: "ABCdef"){
username
email
name
}
}
返回
{
"data": {
"user": {
"username": "ABCdef",
"email": "abc.def@ddv.com",
"name": "ABCDEF"
}
}
}
关于用户类型的信息
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
username: { type: GraphQLString },
email: { type: GraphQLString },
name: { type: GraphQLString },
password: { type: GraphQLString }
})
});
我希望 add_user 返回相同但由于某种原因没有发生