How can I use Knexjs to fetch data synchronously on a resolver in Apollo GraphQL Server? For instance, if I run the following query:
const resolvers = {
Query: {
MySchema: (_, args, { dataSources }, info) => {
var result = db.knex.select('*')
.from('SomeTable')
.where({SomeColumn:'SomeValue'})
.then(function(rows) {console.log(rows)})
.catch(function(error) {console.error(error)});
// Do something with the result here..
console.log(result);
return db.knex.select('*').from('SomeOtherTable')
}
}
}
The line console.log(result); just displays a Promise {<pending>} and by the time the line .then(function(rows) {console.log(rows)}) is executed (asynchronously), the main function will be already finished.
Is there a way to get the result of the database query instead of a Promise on line console.log(result);?