Architecture
The GraphQL integration consists of several key components:1. Query Definitions
GraphQL queries and mutations are defined in TypeScript files using thegql template tag from graphql-request:
/packages/codegen/query/*.ts
2. Code Generation
The @graphql-codegen tool automatically generates:- TypeScript types from the GraphQL schema
- Operation types for queries and mutations
- React Query hooks for data fetching
/packages/codegen/graphql-codegen.yml
3. Generated Hooks
Custom React hooks are automatically generated that wrap the codegen output with application-specific logic:/apps/console/src/lib/graphql-hooks/*.ts
4. Component Usage
Components import and use the generated hooks:GraphQL Client
The application usesgraphql-request as the lightweight GraphQL client, integrated with TanStack Query (React Query) for caching and state management.
Key Features
- Type Safety: Full TypeScript support with generated types
- Automatic Caching: React Query manages query caching and invalidation
- Optimistic Updates: Support for optimistic UI updates
- File Uploads: Custom
fetchGraphQLWithUploadfor multipart requests - Error Handling: Structured error messages from the API