I am using cassandra with graphql and express. On doing the mutation the database is updated, but it doesn't display the fields instead just shows null. Upon using console.log to check the data and I can see it printed on terminal.
Code for mutation,
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];
});
});
}
}
}
});
What I get
{
"data": {
"add_user": null
}
}
Upon using this
mutation{
add_user(username: "ABCdef", email: "abc.def@ddv.com", name: "ABCDEF", password: "abcdxyz"){
username
email
name
}
}
Update can be confirmed with
query{
user(username: "ABCdef"){
username
email
name
}
}
which returns
{
"data": {
"user": {
"username": "ABCdef",
"email": "abc.def@ddv.com",
"name": "ABCDEF"
}
}
}
Info about UserType
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
username: { type: GraphQLString },
email: { type: GraphQLString },
name: { type: GraphQLString },
password: { type: GraphQLString }
})
});
I want add_user to return the same but that's not happening for some reason