I created the following (using supertest) and placed in a function (removed imports etc for brevity)
module.export = {
addThing: async function(title, done) {
const someGraphQL = `mutation {.....}`
let the_id = ""
request
.post("/graphql")
.send({
query: someGraphQL
})
.set("Accept", "application/json")
.expect(200)
.end((err, res) => {
if (err) return done(err);
the_id = Prmise.resolve(res.body.data.id);
console.log(res.body.data.id)
})
console.log(the_id)
return the_id
}
}
When I call this I can see the console.log with the "res.body.data.id", but not the one in the variable.
I thought this may have been async type behaviour, but as I always see that console log for the res.body.data.id (but not for the variable (no matter where I put the variable) I am confused?