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

88
Visualizações
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
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