Hashnode GraphQL returns stale posts due to Edge caching (latest published posts not visible immediately)
- Langage dominant
- JavaScript
- Étoiles
- 48
- Forks
- 48
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
**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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par reproduire la requête des publications publiées sur https://gql.hashnode.com/ avec les variables indiquées et comparez totalDocuments et posts.edges au fil du temps. Examinez le comportement de mise en cache Edge documenté par Hashnode ainsi que les paramètres de cache de la route API Next.js décrits dans l’issue. C’est terminé lorsque le comportement de fraîcheur pris en charge, le délai de mise en cache ou une approche documentée et exploitable pour les publications les plus récentes est établi.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- graphql, javascript, next.js
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100