Overview
AnimeThemes Web uses a merged GraphQL schema that combines multiple data sources into a unified API. This allows the frontend to query different backends (AnimeThemes API and AnimeBracket API) through a single GraphQL interface.Architecture
Schema Merging
Server-Side Schema
The server schema combines AnimeThemes and AnimeBracket type definitions:Type Definitions
Type definitions are defined usinggraphql-tag:
- AnimeThemes Types
- AnimeBracket Types
- Search Types
Resolvers
API Resolver Factory
A custom resolver factory bridges GraphQL with REST APIs:Smart Include System
Resolvers automatically determine which related data to include based on the GraphQL query:Optimize
Removes redundant includes (e.g., if
anime.themes.song is included, anime.themes is redundant)Code Generation
TypeScript types are generated from GraphQL schemas:Query Examples
Fragment-Based Queries
Components define GraphQL fragments for their data requirements:Client-Side Queries
React components use React Query for client-side data fetching:Search Queries
Performance Optimizations
Concurrency Limiting
Request Caching
Build-Time Caching
getStaticPaths for reuse in getStaticPropsSmart Field Selection
Error Handling
Type Safety Flow
Best Practices
Define Fragments in Components
Define Fragments in Components
Co-locate data requirements with the components that use them:
Use Type Imports
Use Type Imports
Import generated types for type safety:
Leverage Smart Includes
Leverage Smart Includes
Let the resolver system automatically determine includes instead of manually specifying them
Cache Within Context
Cache Within Context
Use the context cache to avoid duplicate requests in the same operation