Невозможно использовать console.log () для мутации сервера apollo - PullRequest
0 голосов
/ 18 октября 2019

Я работаю над двухэтапной аутентификацией с nexmo, у меня есть план реализовать это с помощью мутации graphl, потому что у меня есть API-интерфейс graphql, и я не могу получить значение 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 и вернуть его в мутации

1 Ответ

1 голос
/ 18 октября 2019

nexmo.verify.request не вернет то, что вы хотите. Вам нужно console.log или обработать requestId, как вам нравится, внутри (err, result) => {} Вы также можете потенциально 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
        }
      });

  }
}
...