IOTA GraphQL RPC
The GraphQL server provides read access to the Indexer database and enables transaction execution through the fullnode JSON-RPC API.Architecture
The GraphQL server acts as a bridge between:- Indexer Database: For querying historical and indexed data
- Fullnode JSON-RPC API: For transaction execution
Key Features
- Built with async-graphql
- Automatically generated schema from Rust types
- Interactive GraphiQL IDE for exploring the API
- Query and Mutation support
Query Type
Handles all data fetching operations:- Objects, owners, coins, events
- Transaction blocks
- Move packages
- Checkpoints and protocol information
- Dry run (simulation) of transactions
Mutation Type
Handles data modification:- Execute transaction blocks
- Submit transactions to fullnode
GraphQL vs JSON-RPC Mapping
| JSON-RPC API | GraphQL Equivalent |
|---|---|
CoinApi | Query::coins, Query::coin_metadata |
GovernanceApi | Query::epoch |
MoveUtilsApi | Query::type_ |
ReadApi | Query::transaction_block, Query::objects, etc. |
ExtendedApi | Query::epoch, Query::objects, Query::transaction_blocks |
IndexerApi | Query::object, Object::events, etc. |
WriteApi | Mutation::execute_transaction_block, Query::dry_run_transaction_block |
Prerequisites
Before running the GraphQL server, you need:-
Running Indexer database (PostgreSQL)
- Follow the Indexer database setup
- Default: PostgreSQL on port
5432with databaseiota_indexer
-
Fullnode (optional, for transaction execution)
- Required only if you need transaction execution capabilities
Running the GraphQL Server
Using Docker Compose (Recommended)
See pg-services-local which automatically sets up:- GraphQL server
- Indexer instance
- PostgreSQL database
- Local network
Manual Setup
Basic Launch
Start the server with default configuration:http://127.0.0.1:8000
Custom Configuration
Specify database URL, node RPC URL, and server address:--db-url: PostgreSQL database connection URL--node-rpc-url: Fullnode RPC URL for transaction execution--host: Server host address (default:127.0.0.1)--port: Server port (default:8000)--config: Path to TOML configuration file
Advanced Configuration
Use a TOML configuration file for fine-grained control:ServiceConfig in config.rs for all available options.
Using GraphiQL IDE
Access the interactive GraphiQL IDE at:http://127.0.0.1:8000
Example Query
Test the server with this simple query:More Examples
Find additional query examples in the examples directory.Running with Indexer
For local development, you may want to run both the Indexer (to populate data) and GraphQL server:Using iota start Subcommand
From the repository root:
- Local IOTA network
- Indexer Sync worker
- GraphQL server on
0.0.0.0:8000
Standalone Indexer
See Indexer standalone setup to run the Indexer separately.Development Setup
For VS Code users, update.vscode/settings.json with the Diesel backend feature:
Running Tests
Prerequisites
Start a PostgreSQL test database:Run Server Tests
Test GraphQL-JSON-RPC Compatibility
Regenerating GraphQL Schema
After code changes, regenerate the schema:Environment Variables
The GraphQL server respects standard PostgreSQL environment variables:PGHOST: Database hostPGPORT: Database portPGUSER: Database userPGPASSWORD: Database passwordPGDATABASE: Database name