Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda