Skip to content

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

@prathamd123

Description

@prathamd123

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

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions