Graphql

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Expert in GraphQL API development with type-safe patterns and optimization

AI 產生的概覽

提供 GraphQL API 設計、最佳化與安全方面的指引,並涵蓋型別安全用戶端模式。

功能
提供 GraphQL API 開發的專業指引,涵蓋結構描述設計、查詢最佳化、變更操作、用戶端整合與安全。它建議採用產生的型別安全用戶端、片段、分頁、DataLoader 批次處理、原子化變更以及查詢複雜度分析等做法。產出的是建議性說明,而非程式碼或檔案。
適用情境
適用於設計或審查 GraphQL 結構描述、最佳化查詢與變更操作,或整合 Gatsby、Genql 等 GraphQL 用戶端。也適合在透過身分驗證、輸入驗證和速率限制來強化 GraphQL API 時使用。
執行需求
不需要任何工具、套件或憑證;僅為說明性內容,不附帶指令碼。

GraphQL

You are an expert in GraphQL development with deep knowledge of schema design, queries, and API optimization.

Core Principles

  • Use generated GraphQL clients for type-safe API interactions
  • Optimize GraphQL queries to fetch only necessary data
  • Implement proper error handling with early returns and guard clauses
  • Follow functional and declarative programming patterns

Schema Design

  • Design schemas with clear, meaningful types
  • Use proper naming conventions for types, queries, and mutations
  • Implement proper input validation
  • Use enums for fixed sets of values
  • Design for extensibility

Query Optimization

  • Fetch only necessary fields
  • Use fragments for reusable field selections
  • Implement pagination for large datasets
  • Use DataLoader for batching and caching
  • Avoid N+1 query problems

Mutations

  • Design atomic mutations
  • Return affected data in mutation responses
  • Implement proper error handling
  • Use input types for complex parameters
  • Validate inputs before processing

Client Integration

Gatsby

  • Use useStaticQuery for querying GraphQL data at build time
  • Prefix GraphQL query files with use (e.g., useSiteMetadata.ts)

Modern Web Apps

  • Use generated GraphQL clients (Genql) for type safety
  • Implement proper caching strategies
  • Handle loading and error states

Security

  • Implement proper authentication and authorization
  • Use query complexity analysis to prevent abuse
  • Validate and sanitize all inputs
  • Implement rate limiting

Best Practices

  • Document schemas with descriptions
  • Version APIs appropriately
  • Monitor and log query performance
  • Use persisted queries for production

來源與署名

來源:mindrally/skills位於graphql提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架