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

81
Views
Apollo writeQuery is not re-rendering page

I'm using the following code to get a list of post objects:

const { data, fetchMore, loading } = usePostsQuery({
    variables: {
      type: code as string, // TODO: remove type casting
      fromDate,
    },
  })

Then in my deletePost mutation I'm doing a write query:

deletePost({
          variables: { postId },
          update(cache, { data }) {
            // TODO: move to separate function
            if (!data) {
              return
            }

            const readQueryResult = cache.readQuery<
              PostsQuery,
              PostsQueryVariables
            >({
              query: PostsDocument,
              variables: { type: code as string }, // TODO: remove type casting
            })

            const posts = readQueryResult?.posts || []
            cache.writeQuery({
              query: PostsDocument,
              data: { posts: posts.filter(post => post._id !== postId) },
              variables: { type: code },
            })
          },
        })
          .then(() => history.push(url.replace('/create', '')))
          .catch(e => console.log(e))

To get the posts to render I am looping around data?.posts:

  const topics: TopicInfo[] =
    data?.posts?.map(post => {

Any idea how I can get the posts to update? Should the writeQuery do it? Will usePostsQuery automatically know to get the latest posts in the cache? At the moment the data.posts array is not removing the deleted post. Any ideas?

about 4 years ago · Juan Pablo Isaza
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!