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

106
Views
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 answers
Answer question

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 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!