I'm new to graphql and node so sorry if this is really simple but I'm trying to perform a mysql query so that the query response is returned by graphql for the client to read from. The problem I'm running into is that because node-mysql does query asynchronously, I can't get the query response directly.
After some tinkering I figured it out, new code:
var root = {
login: function({username, password}) {
var s = `select password from users where username='${username}'`;
var result = sql.query(s);
return result.then(response => {
return password == response[0].password
});
}
Here is the function definition for sql.query
exports.query = function(s, callback) {
var promise = new Promise((resolve, reject) => {
con.query(s, function(err, response) {
if (err) throw err;
resolve(response);
});
});
return promise;
Graphql now return that response is not defined.