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

159
Views
What is the best practice to use the Apollo cache identify method?

Based on the official docs Apollo's cache identify method is used to get the id of the cache item because this ID could be custom and composed from different fields. That's clear.

To do it we need to receive an item from the cache to pass this item into the cache.identify and receive this item ID.

To get a cache item we have the next possibilities, based on the docs:

  1. readQuery.
const READ_TODO = gql`
  query ReadTodo($id: ID!) {
    todo(id: $id) {
      id
      text
      completed
    }
  }
`;

// Fetch the cached to-do item with ID 5
const { todo } = client.readQuery({
   query: READ_TODO,
   variables: {
     id: 5,
   },
 });
  1. readFragment
const todo = client.readFragment({
  id: 'Todo:5', // The value of the to-do item's cache ID
  fragment: gql`
    fragment MyTodo on Todo {
      id
      text
      completed
    }
  `,
});

These methods will return an item from the cache that we further could pass into the cache.identify to receive the ID.
But they require the ID so it must be known at the moment of the execution of any of them.

So I'm wondering what is the best practice to use the cache.identify ?

So far I know, probably, it could be the only 1 use-case.
Obtain the possible cache item id in the update callback that could be used as an option for a mutation that only updates an existing item. The backend could return a response with the modified object and it's possible to pass this object into the cache.identify to get the ID and pass it further into the appropriated cache update method. But I'm not sure if I'm right so would like to clarify it with more experienced Apollo developers.
Is this the only 1 purpose for the cache.identify method?

Thanks for any help!

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