iota-sdk-graphql-client-build

Crates.ioiota-sdk-graphql-client-build
lib.rsiota-sdk-graphql-client-build
version0.0.1-alpha.1
created_at2025-11-07 11:19:52.455886+00
updated_at2025-11-07 11:19:52.455886+00
descriptionGraphQL RPC Client for the IOTA Blockchain
homepage
repositoryhttps://github.com/iotaledger/iota-rust-sdk/
max_upload_size
id1921459
size153,398
(iota-ci)

documentation

README

Description

This crate provides a function to register a schema to enable building custom queries using cynic derive macros queries. Call this function in a build.rs file in your crate if you need to build custom queries.

Usage

  1. Add this crate as a build dependency in your Cargo.toml file.
[build-dependencies]
iota-sdk-graphql-client-build = { git = "https://github.com/iotaledger/iota-rust-sdk", package = "iota-sdk-graphql-client-build", branch = "develop" }
  1. Add a build.rs file in your crate root directory and call the register_schema function in it.
// build.rs file
fn main() {
    let schema_name = "MYSCHEMA";
    iota_graphql_client_build::register_schema(schema_name);
}
  1. Add the cynic and iota-sdk-graphql-client dependencies in your Cargo.toml file. You should have something like this.
# Cargo.toml
# ...
[dependencies]
cynic = "3.8.0"
iota-sdk-graphql-client = { git = "https://github.com/iotaledger/iota-rust-sdk", package = "iota-sdk-graphql-client", branch = "develop" }

[build-dependencies]
iota-sdk-graphql-client-build = { git = "https://github.com/iotaledger/iota-rust-sdk", package = "iota-sdk-graphql-client-build", branch = "develop" }
  1. If using cynic, use the cynic generator to generate the Rust types from the GraphQL schema.
    Go to https://generator.cynic-rs.dev/ and paste the URL to the GraphQL service or manually copy paste the schema.
    Then you can select the fields in the query you want to have, and the generator will generate the Rust types for you.

  2. In your Rust code, you can now use the custom query types generated by cynic.

// lib.rs
// Custom query
use cynic::QueryBuilder;
use iota_graphql_client::{query_types::schema, Client};

#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema = "MYSCHEMA", graphql_type = "Query")]
pub struct MyQuery {
   pub chain_identifier: String,
}

#[tokio::main]
async fn main() {
    let client = Client::new_mainnet();
    let operation = MyQuery::build(());
    let q = client.run_query(&operation).await.unwrap();
    println!("{:?}", q);
}
  1. For UInt53, you can use u64 type directly as the iota-sdk-graphql-client's schema implements the impl_scalar. Similarly for other types (Base64, DateTime). See more available types here: https://github.com/iotaledger/iota-rust-sdk/blob/02639f6b09375fe03fa2243868be17bec1dfa33c/crates/iota-sdk-graphql-client/src/query_types/mod.rs?plain=1#L124-L126

  2. Read the cynic documentation to learn how to work with it, particularly when it comes to passing arguments to the query.

Commit count: 0

cargo fmt