Overview
EverShop uses a modular GraphQL schema architecture where each module contributes its own types, queries, and resolvers. The schema is automatically built by scanning all modules and merging their GraphQL definitions.Schema Architecture
Modular Design
The GraphQL schema is distributed across modules in:- Type Definitions (
.graphqlfiles) - Define GraphQL types, queries, mutations - Resolvers (
.resolvers.jsor.resolvers.tsfiles) - Implement the logic for fields and operations - Admin Extensions (
.admin.graphqlfiles) - Additional fields/queries for admin API
Schema Building Process
The schema is built using these core services:1. Type Definitions (buildTypes.js)
Collects all .graphql files from enabled modules:
2. Resolvers (buildResolvers.js)
Merges all resolver files:
3. Schema Compilation (buildSchema.js)
Combines types and resolvers into executable schema:
Schema Types
Storefront vs Admin
EverShop maintains two GraphQL schemas:Storefront Schema
Public-facing API for customers
- Product browsing
- Cart operations
- Customer authentication
- Order viewing
Admin Schema
Management API with extended fields
- CRUD operations
- Additional data fields
- Management URLs
- Analytics queries
Type Extension Pattern
EverShop uses GraphQL’sextend type to add fields from different modules:
Core Modules
Catalog Module
- Products, categories, collections
- Attributes and variants
- Product images and pricing
Checkout Module
- Shopping cart
- Shipping and payment methods
- Price calculations
Customer Module
- Customer accounts
- Addresses
- Authentication
OMS (Order Management)
- Orders and order items
- Shipments
- Order status tracking
CMS Module
- Pages and content
- Menus
- Widgets
Base Module
- Common types (Country, Province, Currency)
- Date/time handling
- URLs and routes
Schema Interfaces
EverShop uses GraphQL interfaces for shared structures:ShoppingCart Interface
Implemented by bothCart and Order types:
Address Interface
Implemented byCartAddress, OrderAddress, and CustomerAddress:
Custom Scalars
EverShop defines custom scalar types:JSON- For storing structured dataDate- For date valuesDateTime- For timestamp values
Schema Introspection
You can explore the full schema using GraphQL introspection:Best Practices
Organizing GraphQL Files
Organizing GraphQL Files
- Place
.graphqlfiles ingraphql/types/TypeName/directories - Use descriptive type names matching your domain models
- Keep related types in the same directory
- Use
.admin.graphqlfor admin-only extensions
Extending Types
Extending Types
- Use
extend typewhen adding fields from different modules - Keep field resolvers in the same directory as type definitions
- Document complex fields with GraphQL descriptions
Writing Resolvers
Writing Resolvers
- Name resolver files matching the GraphQL file:
Type.resolvers.js - Use async/await for database operations
- Leverage the context object for authentication and services
- Handle errors gracefully and return null for optional fields
Next Steps
Queries
Explore available GraphQL queries
Mutations
Learn about data modification operations
Types
View all GraphQL types and their fields