Hashnode / Hashnode/support

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

オープン
#86 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
48
フォーク
48
PR マージ指標
30日以内にマージされた PR はありません

説明

**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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、示されている変数を使って https://gql.hashnode.com/ に対する公開済み投稿のクエリを再現し、totalDocuments と posts.edges を時間の経過に沿って比較します。Hashnode がドキュメント化している Edge キャッシュの動作を、issue で説明されている Next.js API route のキャッシュ設定と併せて確認します。サポートされている鮮度の動作、キャッシュのタイミング、または最新の投稿に対する実行可能で文書化されたアプローチが確立されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
graphql, javascript, next.js
領域
api, backend
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。