use-graphql-api
정보
이 스킬은 GraphQL API와의 명령줄 상호작용을 가능하게 하여, 개발자가 `gh api graphql`, `curl`, `jq`와 같은 도구를 사용해 스키마를 검사하고, 쿼리/뮤테이션을 구성 및 실행하며, 응답을 파싱할 수 있도록 합니다. 이는 GitHub 작업(Discussions, Issues, Projects)을 자동화하고 구조화된 API 데이터가 필요한 CLI 워크플로우를 구축하는 데 특히 유용합니다. 또한 이 스킬은 호출 간에 데이터를 파이핑하여 작업을 연쇄적으로 연결하는 것도 지원합니다.
빠른 설치
Claude Code
추천npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/use-graphql-apiClaude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요
문서
用 GraphQL API
於命行下察、構、行、串 GraphQL 之操。
用時
- 經 GraphQL 端讀寫數(GitHub、Hasura、Apollo 等)
- 自 GitHub 之操需 GraphQL 者(Discussions、Projects v2)
- 立殼本以 GraphQL 取結構數
- 串諸 GraphQL 呼,前出為後入
入
- 必要:GraphQL 端 URL 或服名(如
github) - 必要:操之意(讀何寫何)
- 可選:證之憑或法(默:GitHub 用
ghCLI 之證) - 可選:出之偏(生 JSON、jq 過、變賦)
法
第一步:察其綱
定可用之類、域、查、變。
為 GitHub:
# List available query fields
gh api graphql -f query='{ __schema { queryType { fields { name description } } } }' \
| jq '.data.__schema.queryType.fields[] | {name, description}'
# List available mutation fields
gh api graphql -f query='{ __schema { mutationType { fields { name description } } } }' \
| jq '.data.__schema.mutationType.fields[] | {name, description}'
# Inspect a specific type
gh api graphql -f query='{
__type(name: "Repository") {
fields { name type { name kind ofType { name } } }
}
}' | jq '.data.__type.fields[] | {name, type: .type.name // .type.ofType.name}'
為通用之端:
# Full introspection query via curl
curl -s -X POST https://api.example.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"query":"{ __schema { types { name kind fields { name } } } }"}' \
| jq '.data.__schema.types[] | select(.kind == "OBJECT") | {name, fields: [.fields[].name]}'
得:JSON 出列可用之類、域、變。綱之應確端可達、證憑有效。
敗則:
401 Unauthorized— 驗憑;GitHub 行gh auth statusCannot query field— 端或閉內察;查其文檔- 連拒 — 驗端 URL 與網之達
第二步:辨操之類
定其任需查(讀)、變(寫)、抑訂(流)。
| 意 | 操 | 例 |
|---|---|---|
| 取數 | query | 取庫之詳,列討 |
| 立/更/刪 | mutation | 立討、加評 |
| 即時更 | subscription | 守新事(CLI 中罕) |
GitHub 之操,查 GitHub GraphQL API 文。
# Quick check: does the mutation exist?
gh api graphql -f query='{ __schema { mutationType { fields { name } } } }' \
| jq '.data.__schema.mutationType.fields[].name' | grep -i "discussion"
得:明辨需查抑變,並其精確操名(如 createDiscussion、repository)。
敗則:
- 操不見 — 以廣詞搜或察 API 之版
- 不確查抑變 — 動變狀者乃變
第三步:構其操
立 GraphQL 之查或變,含域、參、變數。
查例 — 取庫之討類:
gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
discussionCategories(first: 10) {
nodes { id name }
}
}
}
' -f owner="OWNER" -f repo="REPO" | jq '.data.repository.discussionCategories.nodes'
變例 — 立 GitHub 之 Discussion:
gh api graphql -f query='
mutation($repoId: ID!, $categoryId: ID!, $title: String!, $body: String!) {
createDiscussion(input: {
repositoryId: $repoId,
categoryId: $categoryId,
title: $title,
body: $body
}) {
discussion { url number }
}
}
' -f repoId="$REPO_ID" -f categoryId="$CAT_ID" \
-f title="My Discussion" -f body="Discussion body here"
構之要則:
- 常用變數(
$var: Type!)代內值以重用 - 唯求所需之域以減應
- 連通之分頁用
first: N與nodes - 每物之選加
id— 串之所需
得:語法有效之 GraphQL 操,含合宜變、域選、分頁參。
敗則:
- 語法訛 — 察括之配與末逗(GraphQL 無末逗)
- 類不合 — 對綱驗變數之類(如
ID!對String!) - 缺必域 — 依綱補必入域
第四步:經 CLI 行之
行其操而捕其應。
GitHub — 用 gh api graphql:
# Simple query
gh api graphql -f query='{ viewer { login } }'
# With variables
gh api graphql \
-f query='query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) { id name }
}' \
-f owner="octocat" -f repo="Hello-World"
# With jq post-processing
REPO_ID=$(gh api graphql \
-f query='query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) { id }
}' \
-f owner="OWNER" -f repo="REPO" \
--jq '.data.repository.id')
通用之端 — 用 curl:
curl -s -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "$(jq -n \
--arg query 'query { users { id name } }' \
'{query: $query}'
)"
得:JSON 應有 data 鍵含所求之域,或操敗則有 errors 列。
敗則:
- 應中有
errors— 讀其辭;常因缺權、ID 訛、或限頻 - 空
data— 查無錄;驗入值 - HTTP 403 — 憑缺所需之範;GitHub 察
gh auth status並以gh auth refresh -s scope加範
第五步:解其應
自 JSON 應取所需數。
# Extract a single value
gh api graphql -f query='{ viewer { login } }' --jq '.data.viewer.login'
# Extract from a list
gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(first: 5, states: OPEN) {
nodes { number title }
}
}
}
' -f owner="OWNER" -f repo="REPO" \
--jq '.data.repository.issues.nodes[] | "\(.number): \(.title)"'
# Assign to a variable for later use
CATEGORY_ID=$(gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
discussionCategories(first: 20) {
nodes { id name }
}
}
}
' -f owner="OWNER" -f repo="REPO" \
--jq '.data.repository.discussionCategories.nodes[] | select(.name == "Show and Tell") | .id')
得:清取之值,可顯或賦於殼變。
敗則:
jq返 null — 域徑誤;先導生 JSON 至jq .察結構- 期一而得多 — 加
select()過或| first - Unicode 之疾 — jq 加
-r為生串
第六步:串其操
以前操之出為後操之入。
# Step A: Get the repository ID
REPO_ID=$(gh api graphql \
-f query='query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) { id }
}' \
-f owner="$OWNER" -f repo="$REPO" \
--jq '.data.repository.id')
# Step B: Get the discussion category ID
CAT_ID=$(gh api graphql \
-f query='query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
discussionCategories(first: 20) {
nodes { id name }
}
}
}' \
-f owner="$OWNER" -f repo="$REPO" \
--jq '.data.repository.discussionCategories.nodes[]
| select(.name == "Show and Tell") | .id')
# Step C: Create the discussion using both IDs
RESULT=$(gh api graphql \
-f query='mutation($repoId: ID!, $catId: ID!, $title: String!, $body: String!) {
createDiscussion(input: {
repositoryId: $repoId,
categoryId: $catId,
title: $title,
body: $body
}) {
discussion { url number }
}
}' \
-f repoId="$REPO_ID" -f catId="$CAT_ID" \
-f title="$TITLE" -f body="$BODY" \
--jq '.data.createDiscussion.discussion')
echo "Created: $(echo "$RESULT" | jq -r '.url')"
模:常於早查取 id 域,以為 ID! 變數傳於後變。
得:多步流,每呼成而 ID 正流於諸操間。
敗則:
- 變空 — 前步默敗;加
set -e並察各中值 - ID 形誤 — GitHub 之節 ID 為不透明串(如
R_kgDO...);勿手構之 - 限頻 — 呼間加
sleep 1或以別名批查
驗
- 察綱之查返綱數(第一步成)
- 構之查語法有效(無 GraphQL 析訛)
- 應含
data鍵而無errors - 取之值合所期類(ID 為非空串、計為數)
- 串之操首尾通(變用前查之 ID)
陷
| 陷 | 防 |
|---|---|
必變類忘 ! | 常察綱之可空否;多入域為非空(!) |
| 用 REST 之 ID 於 GraphQL | GraphQL 用不透明節 ID;以 GraphQL 取,非 REST |
| 大果集不分頁 | 用 first/after 與 pageInfo { hasNextPage endCursor } |
| 硬編 ID 而不查 | ID 於諸境異;常動查之 |
忽 errors 列 | data 在亦察訛 — 部分訛可存 |
| 殼引嵌 JSON 之疾 | 用 gh 之 --jq 旗或單導 jq |
參
- scaffold-nextjs-app — 立用 GraphQL 之 web 應
- create-pull-request — GitHub 流自(REST 之對)
- manage-git-branches — Git 操常與 API 自並
- serialize-data-formats — 應處中之 JSON 析模
GitHub 저장소
연관 스킬
content-collections
메타이 스킬은 콘텐츠 콜렉션(Content Collections)을 위한 프로덕션 검증된 설정을 제공합니다. 콘텐츠 콜렉션은 Markdown/MDX 파일을 Zod 검증이 포함된 타입 안전한 데이터 콜렉션으로 변환해주는 TypeScript 최우선 도구입니다. 블로그, 문서 사이트 또는 콘텐츠 중심의 Vite + React 애플리케이션을 구축할 때 타입 안전성과 자동 콘텐츠 검증을 보장하기 위해 사용하세요. Vite 플러그인 구성과 MDX 컴파일부터 배포 최적화 및 스키마 검증에 이르기까지 모든 것을 다룹니다.
polymarket
메타이 스킬은 개발자들이 Polymarket 예측 시장 플랫폼을 활용한 애플리케이션을 구축할 수 있도록 지원하며, 거래 및 시장 데이터를 위한 API 통합 기능을 포함합니다. 또한 WebSocket을 통한 실시간 데이터 스트리밍을 제공하여 실시간 거래와 시장 활동을 모니터링할 수 있습니다. 이를 통해 거래 전략을 구현하거나 실시간 시장 업데이트를 처리하는 도구를 생성하는 데 활용할 수 있습니다.
creating-opencode-plugins
메타이 스킬은 개발자들이 명령어, 파일, LSP 작업 등 25개 이상의 이벤트 유형에 연결되는 OpenCode 플러그인을 만들 수 있도록 돕습니다. JavaScript/TypeScript 모듈을 위한 플러그인 구조, 이벤트 API 명세, 구현 패턴을 제공합니다. OpenCode AI 어시스턴트의 라이프사이클을 사용자 정의 이벤트 기반 로직으로 가로채거나, 모니터링하거나, 확장해야 할 때 사용하세요.
sglang
메타SGLang은 RadixAttention 프리픽스 캐싱을 활용하여 JSON, 정규식, 에이전트 워크플로우를 위한 고속 구조화 생성에 특화된 고성능 LLM 서빙 프레임워크입니다. 특히 반복되는 프리픽스가 있는 작업에서 상당히 빠른 추론 속도를 제공하여 복잡한 구조화 출력 및 다중 턴 대화에 이상적입니다. 제약 디코딩이 필요하거나 광범위한 프리픽스 공유가 있는 애플리케이션을 구축할 때는 vLLM과 같은 대안보다 SGLang을 선택하십시오.
