I'm building a graphql server and one of the resolvers should return an url that is fetched from the aws api. I have tried in hours with promises, async await but nothing have worked yet.
What happens in the code i the following: 1) i make a call to aws api, and get a signed url in the callback. 2) i want to return that url in the graphql resolver function - getSignedURL
My question is: How can i make a resolver function return a result that i've got in another functions callback?
I will appreciate any help!
IN CLASS S3Store
var s3 = new aws.S3();
newSignedUrl(callback){
var params = {
Bucket: 'testBucket28993746',
Key: uuid.v4(),
Expires: 100,
ContentType: 'image/jpg'
};
s3.getSignedUrl('putObject', params, (err, signedURL)=>{
callback(err,signedURL);
});
}
Graphql resolver
getSignedURL(){//TODO: more secure, require auth first
let newURL = null;
s3store = new S3Store();
s3store.newSignedUrl((err,result)=>{
if(err){
console.log(err)
newURL = {}
} else{
console.log(result);
newURL = result;
}
});
return newURL;
},
When i make a call to the graphql endpoint, i get following:
{
"data": {
"getSignedURL": null
}
}