I am trying to generate pdf using 'html-pdf' npm module. After generating pdf, in response I get pdf file path which I want to return with response of graphql call (earlier was planning to return pdf file which I realized is not a standard way). But the below code always return null though I get pdf file path in console.log
var pdfLib = require('html-pdf');
const resolvers = {
Query: {
to_pdf(parent, args, context, info){
console.log('Creating pdf file ', args.html);
var options = { format: 'A4' }
pdfLib.create(args.html, options).toFile('./myfile.pdf', callback)
},
},
};
async function callback(err, res) {
if (err) return console.log(err);
console.log(res.filename); // prints filename in console
return res;
};
module.exports = {
resolvers,
}