Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

graphql-api-design

БесплатноЗапускает вложенные скриптыНе проверен

Comprehensive GraphQL API design with Apollo Server, GraphQL Yoga, and Federation v2

williamzujkowskiот williamzujkowski★ 23 звезды на GitHub10 установок в других каталогах

Об этом скилле

GraphQL API Design Skill

Level 1: Quick Reference (~800 tokens)

GraphQL vs REST: When to Use GraphQL

Use GraphQL When:

  • Clients need flexible data fetching (avoid over/under-fetching)
  • Multiple client types with different data requirements (mobile, web, IoT)
  • Real-time data updates via subscriptions
  • Complex data relationships and nested queries
  • Rapid frontend iteration without backend changes

Use REST When:

  • Simple CRUD operations with predictable access patterns
  • File uploads/downloads (though GraphQL can handle with multipart)
  • HTTP caching is critical (GET requests)
  • Team unfamiliarity with GraphQL tooling

Schema Design Principles

Core Concepts:

  1. Type System: Strongly typed schema defines API contract
  2. Query: Read operations (like GET)
  3. Mutation: Write operations (like POST/PUT/DELETE)
  4. Subscription: Real-time data streams over WebSocket
  5. Resolver: Function that returns data for a field

Design Rules:

  • Use nouns for types, verbs for mutations
  • Prefer pagination over large lists
  • Design for client use cases, not database structure
  • Use interfaces for polymorphic types
  • Leverage custom scalars (DateTime, Email, URL)

Essential Checklist

Schema Design

  • Define clear type hierarchy (Query, Mutation, Subscription roots)
  • Use descriptive field names and types
  • Add field-level descriptions for documentation
  • Implement input validation with custom scalars
  • Design pagination with cursor-based approach

Resolvers & Performance

  • Implement DataLoader for N+1 query prevention
  • Batch database queries within request context
  • Add resolver-level caching strategy
  • Use field-level resolvers only when needed
  • Implement query complexity analysis

Authorization & Security

  • Context-based authentication (verify tokens)
  • Field-level authorization with directives
  • Query depth limiting (prevent deeply nested attacks)
  • Query complexity cost analysis
  • Rate limiting per client/operation

Federation (Microservices)

  • Define subgraph schemas with @key directives
  • Implement reference resolvers for entity resolution
  • Configure Apollo Gateway for schema composition
  • Set up schema registry for version control
  • Monitor federated trace data

Error Handling

  • Return structured errors with codes and extensions
  • Distinguish user errors from system errors
  • Implement partial error responses
  • Log errors with correlation IDs
  • Mask sensitive data in error messages

Testing

  • Unit test resolvers with mocked data sources
  • Integration test with test database
  • Schema validation with apollo CLI
  • Performance test with realistic queries
  • Security test for common vulnerabilities

Quick Wins

Immediate Optimizations:

  1. DataLoader: Reduce N+1 queries by 90%+

    const userLoader = new DataLoader(async (userIds) => {
      const users = await db.users.findMany({ where: { id: { in: userIds } } });
      return userIds.map(id => users.find(u => u.id === id));
    });
    
  2. Query Complexity: Prevent expensive queries

    const server = new ApolloServer({
      schema,
      plugins: [createComplexityPlugin({ maximumComplexity: 1000 })]
    });
    
  3. Response Caching: Cache at resolver or HTTP level

    @cacheControl(maxAge: 3600)
    type User { id: ID! name: String! }
    
  4. Subscription Filtering: Reduce unnecessary events

    subscribe: {
      messageAdded: {
        subscribe: withFilter(
          () => pubsub.asyncIterator('MESSAGE_ADDED'),
          (payload, variables) => payload.channelId === variables.channelId
        )
      }
    }
    

Level 2:

📚 Full Examples: See REFERENCE.md for complete code samples, detailed configurations, and production-ready implementations.

Implementation Guide (~4500 tokens)

1. GraphQL Schema Design Best Practices

Type System Fundamentals

Object Types: Primary building blocks

See REFERENCE.md for complete implementation.

Input Types: For mutations and complex arguments

See REFERENCE.md for complete implementation.

Enums: For fixed sets of values

See REFERENCE.md for complete implementation.

Interfaces: For polymorphic types

See REFERENCE.md for complete implementation.

Unions: For heterogeneous result types

union SearchResult = User | Post | Comment

type Query {
  search(query: String!): [SearchResult!]!
}

Custom Scalars: For domain-specific types

scalar DateTime
scalar Email
scalar URL
scalar JSON
scalar PositiveInt

Query Design Patterns

Root Query Type

*See REFERENCE.md for com

Полный SKILL.md на GitHub

Установить graphql-api-design в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

README.mdREFERENCE.mdconfig/apollo-studio.yamltemplates/dataloader-implementation.tstemplates/federation-config.yamltemplates/graphql-schema.graphqltemplates/resolver-patterns.tstemplates/subscription-server.ts

FAQ

Что делает скилл graphql-api-design?

Comprehensive GraphQL API design with Apollo Server, GraphQL Yoga, and Federation v2

Как установить скилл graphql-api-design?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл graphql-api-design запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить graphql-api-design с