AgentSkillsCN

graphql-guide

GraphQL 开发最佳实践。当您处理片段、查询、突变,或 .graphql 文件时,可使用此技能。

SKILL.md
--- frontmatter
name: graphql-guide
description: GraphQL development best practices. Use when working with fragments, queries, mutations, or .graphql files.

GraphQL Guide

命名パターン(ベストプラクティス)

タイプパターン
Fragment[Component][Model]FragmentUserCardFragment
Query[Action][Resource]QueryGetUsersQuery
Mutation[Verb][Target]MutationCreateUserMutation
Subscription[Entity]SubscriptionUserUpdatedSubscription

ファイル命名

code
<type>.<GraphQLName>.graphql
  • type: fragment | query | mutation | subscription
  • GraphQLName: PascalCaseで記述

パターン別

タイプパターン
Fragmentfragment.<Component><Model>.graphqlfragment.CardTask.graphql
Query (Get)query.Get<Context><Resource>.graphqlquery.GetDetailPageCraft.graphql
Query (Search)query.Search<Target>.graphqlquery.SearchCompanies.graphql
Mutationmutation.<Verb><Resource>.graphqlmutation.CreateTask.graphql
Subscriptionsubscription.Subscribe<Event>.graphqlsubscription.SubscribeCraftTimeline.graphql

コロケーションパターン

GraphQLファイルは使用するコンポーネントの近くに配置:

code
components/
└── UserCard/
    ├── index.tsx
    └── graphql/
        └── fragment.UserCard.graphql

Verb一覧(Mutation用)

Verb用途
Create新規作成
Update更新
Delete削除
Add関連追加
Remove関連削除
Submit提出
Cancelキャンセル

Fragment First

  1. コンポーネントが必要なデータをFragmentで定義
  2. 親がFragmentをQuery/Mutationに埋め込み
  3. データの責務が明確になる
graphql
# fragment.UserCard.graphql
fragment UserCardFragment on User {
  id
  name
  avatarUrl
}

# query.GetUsers.graphql
query GetUsersQuery {
  users {
    ...UserCardFragment
  }
}