「html-pdf」npmモジュールを使用してpdfを生成しようとしています。PDFを生成した後、それに応じて、graphql呼び出しの応答で返したいpdfファイルパスを取得します(以前は、標準的な方法ではないことに気付いたpdfファイルを返す予定でした)。しかし、console.log で pdf ファイル パスを取得しても、以下のコードは常に null を返します。
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,
}