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

111
Visualizações
Apollo Client useMutation does not call the API

I am trying to use useMutation for my graphql API but it does not seems to make any call,

here is the code

export async function bulkImport(importRequest: BulkImportRequest): Promise<string> {
  const [postBulkImport, { data }] = useMutation(postBulkImportRequest, {
    variables: importRequest,
  });
  await postBulkImport({ variables: importRequest });
  return data?.requestId;
}

and the I call bulkImport in my React component.

I am trying to rewrite below code using useMutation instead of mutate. Bellow code is working fine.

export async function bulkImport(importRequest: BulkImportRequest): Promise<string> {
  const response = await mutate(postBulkImportRequest, importRequest);
  return response?.data?.postBulkImportRequest?.requestId;
}

I am not sure what I am missing when I use useMutation, I am actually not sure if they are the same.

any advice will be appreciated

almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

useMutation is a React Hook and as such can only be used from the top level of a React functional component.

Nothing happens when you try and use it from your bulkImport function because it's not at the top level of a React component.

You'll need to (quite dramatically) rewrite your component in order to work with useMutation successfully.

almost 4 years ago · Santiago Trujillo 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