我正在使用nexmo进行两步身份验证,我计划通过graphl突变实现此目的,因为我有graphql API
而且我无法获得requestId值

  Mutation: {
    signUpFirstStep: async ( parent, { number }, { models, secret }) =>
    {
     const response =  nexmo.verify.request({
        number: number,
        brand: 'Nexmo',
        code_length: '4'
      }, (err, result) => {
        const  requestId  = result.request_id
        return requestId

      });
      console.log(response);  //right here I have undefined
  }
}


我想要的只是获取requestId值以在突变中返回它

最佳答案

nexmo.verify.request不会返回您想要的内容。您需要在console.log(err, result) => {}或随意处理requestId
如果您愿意,您也可以使用res.status(200).send(result);res.status(200).send(requestId);来返回结果或requestId。

见下文:

Mutation: {
    signUpFirstStep: async ( parent, { number }, { models, secret }) =>
    {
     nexmo.verify.request({
        number: number,
        brand: 'Nexmo',
        code_length: '4'
      }, (err, result) => {

        if(result) {
          const  requestId  = result.request_id;
          console.log(requestId); // you should console.log or do whatever you are trying to do with the requestId here
        }
      });

  }
}

关于javascript - 无法在阿波罗服务器突变中使用console.log()函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58453351/

10-11 06:47