Hashnode / Hashnode/support

Hashnode GraphQL returns stale posts due to Edge caching (latest published posts not visible immediately)

Aberta
#86 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
48
Forks
48
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

**Summary**

We are fetching posts from Hashnode GraphQL API (https://gql.hashnode.com/) for our website blog page.
Even after publishing a new post, the API sometimes returns stale data (old totalDocuments and missing latest post).
This looks like an Edge cache issue, where the response is served from cache even though the publication has new content.

**What we expect**

When a new blog post is published on our Hashnode publication, the query should return the latest post immediately (or within a predictable short time).

What actually happens
• After publishing a new post, our website still shows old posts
• totalDocuments stays the same (example: sometimes 46 instead of 47)
• The newest post doesn’t appear in posts.edges even when requesting the first page
• Sometimes after multiple requests or after some time, it starts showing the latest data

So the response is inconsistent even for the same query + variables.

query
```graphql
query Publication($after: String, $first: Int!) {
publication(host: "prathamd01.hashnode.dev") {
posts(first: $first, after: $after) {
totalDocuments
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
slug
title
publishedAt
url
}
}
}
}
}
```

**Why we think this is Edge caching**

Hashnode docs mention that responses are cached at the Edge:

“Almost all responses of queries are cached on the Edge.”
“Cached data will automatically be purged if you mutate the data.”
“If you don’t request the field id… it is possible that you get stale data.”

We are already requesting id fields, but still getting stale results.

**What we tried**

- Setting cache: "no-store" / cache: "no-cache" in fetch

- Setting response headers in our Next.js API route:

```graphql
res.setHeader("Cache-Control", "no-store, max-age=0, must-revalidate");
res.setHeader("Pragma", "no-cache");
```

- Still stale data sometimes.

- Fetching more posts (first: 20) and sorting by publishedAt client-side

- This works more often but feels like a workaround, not a real fix.

✅ Polling every 15 seconds

- Works but increases request count and is not ideal for production.

**Key problem**

Even if we bypass caching on our side, Hashnode still sometimes returns cached/stale data from the Edge, so the newest published post is not visible immediately.

**Request / Question**

Is there a way to ensure fresh posts data always comes from Hashnode GraphQL?

For example:
• an option to disable edge caching for specific queries
• a recommended approach for “latest posts” use-case
• a way to force cache purge on publish/update
• or a documented cache TTL / propagation time

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece reproduzindo a consulta de posts publicados em https://gql.hashnode.com/ com as variáveis mostradas e compare totalDocuments e posts.edges ao longo do tempo. Revise o comportamento documentado de cache Edge do Hashnode juntamente com as configurações de cache da rota de API do Next.js descritas na issue. Considera-se concluído quando o comportamento de atualização suportado, o tempo de cache ou uma abordagem documentada e acionável para posts mais recentes estiver estabelecido.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
graphql, javascript, next.js
Domínio
api, backend
Tipo de issue
Bug
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.