본문으로 건너뛰기
cccskills
무료GitHub에 공개

sanity-data-operations

Manage Sanity content -- schema changes, data migrations, debugging queries, batch operations, and revalidation.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.5 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Sanity Data Operations

When to use this skill

  • Modifying Sanity schemas or adding new document types
  • Debugging missing or incorrect data in the frontend
  • Running batch operations on Sanity documents
  • Troubleshooting revalidation and ISR issues
  • Managing Sanity webhooks and live preview
  • Seeding or resetting demo data

Sanity project reference

FieldValue
Project IDnamias-cms (from NEXT_PUBLIC_SANITY_PROJECT_ID)
Datasetproduction (from NEXT_PUBLIC_SANITY_DATASET)
Studio URLhttp://localhost:3333 (local) / https://namias-cms.sanity.studio (prod)
API version2024-01-01

Workflow

1. Schema inspection

List all document types:

cd studio && npx sanity schema list

View a specific schema:

cd studio && npx sanity schema describe <documentType>

Common document types in this project:

TypePurpose
profileHero section: name, title, role rotator, email, image
projectPortfolio projects with title, slug, summary, tech, images
experienceWork history: role, company, dates, highlights
certificationCredentials: issuer, dates, expiry, credential URL
blogPostBlog articles with Portable Text body, categories
socialLinkSocial media links displayed in Connect section
skillSkills displayed in the Skills section
siteSettingsGlobal site configuration

2. Debugging data issues

Check if data exists via API:

curl "https://namias-cms.api.sanity.io/v2024-01-01/data/query/production?query=*[_type=='profile'][0]{name,email}"

Common query patterns:

// All projects
*[_type == "project"] | order(order asc) { title, slug, summary }

// Single project by slug
*[_type == "project" && slug.current == $slug][0]

// Published documents only (exclude drafts)
*[_type == "project" && !(_id in path("drafts.**"))]

// Count documents
count(*[_type == "blogPost"])

Debug in Sanity Studio:

  1. Open http://localhost:3333
  2. Go to Vision tab (GROQ playground)
  3. Run the query above
  4. Check that documents exist and have the expected fields

3. Data mutations

Using Sanity CLI:

cd studio && npx sanity document create <type>
cd studio && npx sanity document edit <documentId>
cd studio && npx sanity document delete <documentId>

Using GROQ mutations (via API):

curl -X POST "https://namias-cms.api.sanity.io/v2024-01-01/data/mutate/production" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "mutations": [{
      "patch": {
        "id": "<documentId>",
        "set": { "title": "New Title" }
      }
    }]
  }'

4. Revalidation and ISR

How revalidation works:

  • The Sanity webhook calls /api/sanity/revalidate when content changes
  • The route uses revalidateTag() to invalidate cached data
  • SWR in components refetches on the next client visit

Trigger manual revalidation:

curl -X POST "http://localhost:3000/api/sanity/revalidate" \
  -H "Content-Type: application/json" \
  -d '{"secret": "<SANITY_REVALIDATE_SECRET>"}'

Check revalidation is working:

  1. Change content in Sanity Studio
  2. Open the frontend
  3. The change should appear within the revalidate period (or on manual trigger)

Common revalidation issues:

SymptomCauseFix
Changes don't appearWebhook not configuredCheck Sanity webhook settings
Stale data persistsTag not invalidatedCheck revalidateTag() calls in route handlers
401 on revalidateWrong secretVerify SANITY_REVALIDATE_SECRET env var
Build shows old dataISR cacheRedeploy or wait for revalidation period

5. Webhook configuration

Sanity webhook setup:

  1. Go to Sanity Management → Project → API → Webhooks
  2. Create a webhook:
    • URL: https://<your-domain>/api/sanity/revalidate
    • Trigger on: create, update, delete
    • Filter: _type in ["project", "experience", "certification", "blogPost", "profile"]
    • Secret: match SANITY_REVALIDATE_SECRET

6. Seeding demo data

npm run sanity:seed

This runs scripts/sanity/seed-demo.ts which creates sample documents for development.

7. Common tasks

Add a new field to an existing document:

  1. Edit the schema in studio/schemas/<documentType>.ts
  2. Add the field definition
  3. Run cd studio && npx sanity typegen generate (if using typegen)
  4. Migrate existing documents if the field is required
  5. Test in studio at localhost:3333

Add a new document type:

  1. Create schema in studio/schemas/<newType>.ts
  2. Register in studio/schemas/index.ts
  3. Add to structureDeskTool in studio/deskStructure.ts
  4. Create a query in the frontend to fetch it
  5. Create a component to display it

Common mistakes

  • Editing documents directly in the production Sanity project without testing locally first
  • Forgetting to set revalidate on fetch calls ({ next: { revalidate: 60 } })
  • Using stale GROQ queries after schema changes
  • Not handling null responses from Sanity (always use ?? defaultValue)

Delivery checks

  • Schema changes work in Sanity Studio locally
  • Frontend renders the new/updated data correctly
  • Revalidation webhook triggers and data refreshes
  • No TypeScript errors after schema changes
  • Draft documents are filtered out in production queries

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Audit and fix accessibility issues across the portfolio to ensure WCAG 2.1 AA compliance.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

Creates a new blog post document in the Sanity studio. Use when the user wants to write a blog post, publish an article, or schedule a future post.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

Creates a new certification document in the Sanity studio. Use when the user wants to add a credential, certificate, or professional accreditation to the Certifications collection.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

Adds a new skill MD file to the studio's skills collection. Use when the user wants to author a new step-by-step recipe for the studio's in-app Skills tool or the .agents mirror.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

Creates a new project document in the Sanity studio. Use when the user wants to add a new portfolio project, a case study, or a work sample to the Projects collection.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

Creates a new experience document in the Sanity studio. Use when the user wants to add a job, role, internship, or work history entry to the Experience collection.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PP-Namias/Portfolio22026년 10월 20일 업데이트

PP-Namias의 스킬 모두 보기

이 스킬의 문제 신고