Skip to main content

gql-api:Hashnode GraphQL 指南

指导 Agent 通过 GraphQL 读写 Hashnode 博客内容,并落实 PAT 鉴权卫生与 Pro 计划门控,避免把令牌贴进对话。

来源信息

仓库
Hashnode/gql-skill
最近来源活动
2026年10月1日 09:23
检测到的 SKILL.md 语言
英语
星标
20
Forks
4

相关案例

SKILL.md 用示例帖 id/slug 说明 hashnode.com 链接格式;references/recipes.md 含发布、分页与传图流程(此处未复跑)。

用途

用于经 gql 端点读写帖子、草稿、出版物、标签、系列或评论,或排查 UNAUTHENTICATED / Pro FORBIDDEN 错误。

必要前提

可访问 https://gql-beta.hashnode.com。鉴权操作须先在 shell 导出 HASHNODE_PAT,禁止把令牌粘贴进聊天。源列明的全部写入 mutation 均受目标出版物的 Pro 计划门控(不是调用者个人计划);出版物范围读取以及单帖 post(id:…) 同样按该出版物是否 Pro 门控。

操作说明

说明博客任务 → Agent 加载端点/鉴权/Pro 规则与参考文档 → 每个请求都带 x-hashnode-client: gql-skill;仅鉴权操作(me、draft、scheduledPost 与全部 mutation)另以 shell 插值发送 Authorization: Bearer $HASHNODE_PAT → 若返回 Pro FORBIDDEN,停止重试并提示升级该出版物。

限制

PAT 等同写权限:禁止打印、记录或提交。需要 PAT 的是 me、draft、scheduledPost 与全部 mutation;公开 feed/user/tag 读取不需要令牌。publication 与 post 可不带 PAT 做公开读,但仍可能受目标出版物 Pro 门控;Pro 是出版物门控,不是「调用者个人计划」的泛化。传图流程的请求发往 Hashnode,图片经预签名 S3 完成(README);上传前核对目标与内容,勿当作纯本地处理。仓库根目录未声明 LICENSE。官方 X 帖是在 Ahrefs DR4 引用串中的软推广。本站未执行该技能,也未使用任何 PAT。

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
7 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
gql-api
description
Query and mutate content on the Hashnode GraphQL API (posts, drafts, publications, users, tags, series, comments). Use when a user wants to read or write data through the Hashnode gql endpoint, needs a reference for a specific query or mutation, is wiring up a Personal Access Token, or hits a "Publication does not have an active Pro plan" / FORBIDDEN error and needs to know an operation is Pro-gated.
# Hashnode GraphQL API A GraphQL API (Apollo Server) for publishing and managing content on Hashnode: posts, drafts, publications, users, tags, series, and comments. This skill tells an agent how to talk to it correctly — endpoint, auth, which operations need a Pro plan, the limits that cause requests to fail, and where to find the full field-level reference. ## Endpoint | Environment | URL | Path | |-------------|-----|------| | Production | `https://gql-beta.hashnode.com` | `/` (POST GraphQL here) | | Local dev | `http://localhost:8080` | `/graphql` | Standard GraphQL over HTTP `POST` with a JSON body (`{ "query": "...", "variables": {...} }`). Introspection is enabled, so the schema is browsable from any GraphQL IDE. ## Authentication Auth uses a **Personal Access Token (PAT)**. The token must be provided via the `HASHNODE_PAT` environment variable and passed by reference at execution time — never inline the literal token value: ```bash curl -H "Authorization: Bearer $HASHNODE_PAT" -H "x-hashnode-client: gql-skill" ... ``` Get a PAT from the Hashnode dashboard (Account Settings → Developer / API tokens) and export it in the shell: `export HASHNODE_PAT=...`. Also send `x-hashnode-client: gql-skill` on every request, so the API can tell this skill's traffic apart from other callers. Not a secret, grants no access. **Token handling rules — the PAT is a password.** It grants full write access to the user's publications (publish, edit, delete): - Never ask the user to paste the token into the conversation. If `HASHNODE_PAT` is unset, tell the user to export it in their shell and retry. - Never print, echo, or log the token, and never expand it into a command string — always let the shell interpolate `$HASHNODE_PAT` inside the request itself. - Never write the token into files, scripts, or commits. - **Public reads** need no token: `post`, `feed`, `user`, `tag`, `publication`, `documentationProject`, `checkCustomDomainAvailability`, `checkSubdomainAvailability`. - **Authenticated** operations need a valid PAT: `me`, `draft`, `scheduledPost`, and **every mutation**. A missing/invalid token returns `UNAUTHENTICATED`. See [references/auth-and-roles.md](references/auth-and-roles.md) for the role model (OWNER / EDITOR / CONTRIBUTOR) and the contributor review workflow. ## Pro plan gating Some operations require the **target publication** to have an active Pro plan. This is keyed to the publication, not the calling user. When the publication is not Pro, the API returns: ```json { "errors": [{ "message": "Publication does not have an active Pro plan. Upgrade in your dashboard to access this via the API.", "extensions": { "code": "FORBIDDEN" } }] } ``` **When you see this, tell the user the publication needs to upgrade to Pro in the Hashnode dashboard. Do not retry the request — it will keep failing until the publication is on Pro.** Pro-gated operations: - **All write mutations:** `publishPost`, `updatePost`, `createDraft`, `updateDraft`, `publishDraft`, `submitDraftForReview`, `rejectDraftSubmission`, `deleteDraft`. - **Publication-scoped reads:** `publication`, `draft`, `scheduledPost`, `searchPostsOfPublication`, `topCommenters`. (`draft` and `scheduledPost` also require a PAT and authorization; the owning publication must be Pro.) - **Single-post reads:** `post(id: ...)`. Gated on the owning publication's Pro plan, same as `publication`. There's no free-tier carve-out for reading one post by id. `feed`, `user`, and `tag` reads are **not** Pro-gated. Hashnode also has a **Growth Plan** (Pro + the AEO toolkit). It adds no new gates to this API: `publication.aeoSettings` and `post.faq` are readable on the same terms as their parent types, and `aeoSettings` resolves with permissive defaults for non-Growth publications (`isEnabled` tells you whether the publication actually has the toolkit). See "AEO fields" in [references/queries.md](references/queries.md). ## Linking to Hashnode pages (never guess URLs) When you need to link to a post's discussion, a comment, or a profile on hashnode.com, build the URL from API data using these exact formats. Do not browse hashnode.com to discover URL schemes, and do not invent paths. | Page | URL format | |------|-----------| | Post discussion on hashnode.com | `https://hashnode.com/posts/<slug>/<postId>` | | A specific comment | `https://hashnode.com/posts/<slug>/<postId>/comment/<commentId>` | | User profile | `https://hashnode.com/@<username>` | | Post on the author's own blog | Use the post's `url` field from the API; it already resolves the custom domain vs `<username>.hashnode.dev` | - `<slug>` and `<postId>` are the post's `slug` and `id` from the API. **Both are required**; there is no id-only or slug-only form. - `<commentId>` is the comment's `id` from the post's `comments` connection. - Legacy paths like `/discussions/post/<id>` and `/<postId>` **404**. Never emit them. Example: post `id: 6a603fb103e2cb323e7851f6`, `slug: sealed-with-a-kyss-inside-an-android-banking-rat` → `https://hashnode.com/posts/sealed-with-a-kyss-inside-an-android-banking-rat/6a603fb103e2cb323e7851f6` ## Reference - [references/schema.graphql](references/schema.graphql) — full SDL (introspection schema) from `gql-beta`: the canonical source for every type, field, argument, and input. Use this when you need exact field names or types; use the curated files below for auth/Pro behavior the schema can't express. - [references/queries.md](references/queries.md) — all 13 queries: arguments, return types, auth/Pro notes. - [references/mutations.md](references/mutations.md) — all 10 mutations: inputs, payloads, auth/Pro notes. - [references/auth-and-roles.md](references/auth-and-roles.md) — PAT setup, public vs. authenticated, roles, contributor review flow. - [references/errors-and-limits.md](references/errors-and-limits.md) — error codes, page-size caps, query depth, payload/image limits. - [references/recipes.md](references/recipes.md) — end-to-end examples: publish a post, paginate a feed, upload an image. ## Rules for the agent 1. Always send `Authorization: Bearer $HASHNODE_PAT` (shell-interpolated from the environment, never the literal token) for `me`, `draft`, `scheduledPost`, and any mutation. Without it you get `UNAUTHENTICATED`. Follow the token handling rules in the Authentication section: don't ask for, print, or persist the token. Also send `x-hashnode-client: gql-skill` on every request (see Authentication). 2. On `FORBIDDEN` + the Pro-plan message, stop and tell the user to upgrade the publication to Pro. Don't retry. 3. Respect page-size caps: most connections cap `first` at **100**, drafts at **50**. Asking for more is silently clamped. 4. Keep query depth at or below **10** — deeper queries are rejected. 5. Tag inputs use **slug** (e.g. `javascript`), max **15** per post/draft. 6. Pagination is cursor-based: read `pageInfo.endCursor` / `pageInfo.hasNextPage`, pass `endCursor` as the next `after`. 7. Mutations are never cached; queries may be cached for up to ~25s. 8. Build hashnode.com links from API data using the formats in "Linking to Hashnode pages". Never guess or browse for URL schemes.
在 GitHub 查看