Installation
The GraphQL transport is included in the main SDK package:Basic Setup
Client Configuration
TheIotaGraphQLClient accepts the following options:
With Custom Headers
With Custom Fetch
Executing Queries
Basic Query
Typed Queries with gql.tada
The SDK supports typed GraphQL queries usinggql.tada:
Common GraphQL Queries
Query Objects
Query Transactions
Query Events
Query Coins
Pagination
GraphQL uses cursor-based pagination:Fragments
Use GraphQL fragments to reuse query parts:Error Handling
Predefined Queries
Register commonly used queries:GraphQL vs JSON-RPC
- GraphQL Advantages
- JSON-RPC Advantages
- Flexible queries: Request exactly the data you need
- Batch queries: Combine multiple queries in one request
- Strongly typed: Full TypeScript support with gql.tada
- Efficient: Reduce over-fetching and under-fetching
- Advanced filtering: Complex query filters and sorting
Schema Versions
The SDK includes GraphQL schemas for different versions:Best Practices
Request Only Needed Fields
Request Only Needed Fields
GraphQL allows you to request exactly the fields you need:
Use Typed Queries
Use Typed Queries
Leverage TypeScript types with gql.tada:
Batch Related Queries
Batch Related Queries
Handle Errors Gracefully
Handle Errors Gracefully
Always check for both errors and data:
Next Steps
Reading Data
Query blockchain data with JSON-RPC
Events
Subscribe to and query events
Client Setup
Configure the IotaClient
Examples
See complete examples