Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
How to return the response of a post request in qraphql

I'm developing an app using GraphQL in the backend and I want to implement a face comparison method. I am using the facepp npm package, which gives me an API to perform the comparison. The problem I am having is that when my resolver runs, it finishes before it gets a response from facepp. How can I make it return the response from facepp?

    module.exports = {
      Mutation: {
         checkFace: async () => {
           console.log("Checking.....");

        let confidence;

        var parameters = {
          image_url1: "link to image 1",

          image_url2: "link to image 2",
        };

        facepp.post("/compare", parameters, function (err, res) {
            if (!err) {
                confidence = res.confidence;
              //return res.confidence doesn't work
            } else {
                confidence = "There was an error"
            }
        });

        return confidence
    },
},

};

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After a couple of trials and researches, I came up with a working solution. The problem in my original code was that I didn't correctly handle the asynchronous handler of the facepp.post method. In case if someone runs into the same issue, below is a working implementation of my code.

module.exports = {
    Mutation: {
        checkFace: async () => {
            let confidence;
            const callCheck = () => {
                return new Promise((resolve, reject) => {
                    var parameters = {
                        image_url1: "link to image 1",
                        image_url2: "link to image 2",
                    };
                    facepp.post("/compare", parameters, function (err, 
                  res) {
                        if (!err) {
                            confidence = res.confidence;
                            resolve();
                        } else {
                            confidence = "error";
                            reject();
                        }
                    });
                });
            };
            await callCheck();
            return confidence;
        },
    },
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!