Subgraphs provide indexed blockchain data through GraphQL APIs, enabling efficient querying of Mezo protocol data. This guide covers subgraph endpoints and deployment with Goldsky.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mezo-org/documentation/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Mezo subgraphs provide:Indexed Data
Fast access to blockchain data without scanning blocks
GraphQL API
Flexible querying with powerful filtering and sorting
Real-time Updates
Live synchronization with the blockchain
Custom Logic
Transform and aggregate on-chain data
Development Setup
Prerequisites
Before working with subgraphs, ensure you have:- Node.js 18+ (check repository’s
.nvmrcfor exact version) - npm or yarn package manager
- Git
- Graph CLI
- Goldsky account
Installation
Repository Structure
Mezo subgraph repositories contain:- schema.graphql: GraphQL schema definitions
- subgraph.yaml: Subgraph manifest configuration
- src/: Mapping logic (AssemblyScript)
- abis/: Contract ABIs
- tests/: Unit tests
Schema Definition
Define your data models inschema.graphql:
schema.graphql
Use the
@entity directive to mark types that should be stored and queryable.Subgraph Manifest
Configure your subgraph insubgraph.yaml:
subgraph.yaml
Mapping Logic
Implement event handlers insrc/mapping.ts:
src/mapping.ts
Code Generation
Generate TypeScript types from your schema:Testing
Unit Tests
Write unit tests for your mappings:tests/musd.test.ts
Run Tests
Deployment with Goldsky
Setup Goldsky
Create a Goldsky account at goldsky.com before authenticating.
Deploy Subgraph
Goldsky Configuration
Create a Goldsky configuration file:goldsky.json
Querying Subgraphs
GraphQL Queries
Once deployed, query your subgraph using GraphQL:Client Integration
GraphQL Request
Integrate subgraph queries using graphql-request:Apollo Client
Use Apollo Client for React applications:Monitoring and Maintenance
Health Checks
Monitor subgraph health and sync status:Updating Subgraphs
Deploy new versions:Error Handling
Common issues and solutions:- Sync Lag: Check RPC endpoint health and connectivity
- Failed Handlers: Review mapping logic and error logs
- Schema Mismatches: Ensure schema matches deployed version
Best Practices
Schema Design
Meaningful Names
Use descriptive entity and field names
Clear Relationships
Define entity relationships properly
Index Fields
Index frequently queried fields
Immutable IDs
Use immutable, unique entity IDs
Mapping Logic
- Error Handling: Handle null values and edge cases gracefully
- Gas Efficiency: Minimize entity loads and saves
- Consistency: Maintain data consistency across entities
- Testing: Write comprehensive unit tests for all handlers
Performance
- Start Block: Set appropriate start blocks to reduce sync time
- Batch Processing: Process events efficiently in batches
- Caching: Use entity caching to reduce database queries
- Pagination: Implement proper pagination in queries
For detailed subgraph schemas, deployment configurations, and protocol-specific mappings, refer to the individual subgraph repositories in the Mezo organization.
Additional Resources
Goldsky Documentation
Complete Goldsky platform documentation
The Graph Docs
Subgraph development guide
GraphQL Documentation
GraphQL query language reference
AssemblyScript
Mapping language documentation
Mezo Discord
Join the community for support
FAQ
Frequently asked questions