diff --git a/crates/sui-graphql-client-build/README.md b/crates/sui-graphql-client-build/README.md index 357b4b4ab..e6f20fbec 100644 --- a/crates/sui-graphql-client-build/README.md +++ b/crates/sui-graphql-client-build/README.md @@ -2,22 +2,41 @@ 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. -### Example +### Usage +1. Add this crate as a build dependency in your `Cargo.toml` file. +```toml +[build-dependencies] +sui-graphql-client-build = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client-build", branch = "master" } +``` + +2. Add a `build.rs` file in your crate root directory and call the `register_schema` function in it. ```rust,ignore // build.rs file fn main() { - let schema_name = "MYSCHEMA" + let schema_name = "MYSCHEMA"; sui_graphql_client_build::register_schema(schema_name); } +``` -// Cargo.toml -... +3. Add the `cynic` and `sui-graphql-client` dependencies in your `Cargo.toml` file. You should have something like this. +```toml +# Cargo.toml +# ... [dependencies] cynic = "3.8.0" -... +sui-graphql-client = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client", branch = "master" } + [build-dependencies] -sui_graphql_client_build = "VERSION_HERE" +sui-graphql-client-build = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client-build", branch = "master" } +``` +4. 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. + +5. In your Rust code, you can now use the custom query types generated by `cynic`. + +```rust,ignore // lib.rs // Custom query use cynic::QueryBuilder; @@ -37,3 +56,7 @@ async fn main() { println!("{:?}", q); } ``` + +6. For `UInt53`, you can use `u64` type directly as the `sui-graphql-client`'s schema implements the `impl_scalar`. Similarly for other types (Base64, DateTime). See more available types here: https://github.com/MystenLabs/sui-rust-sdk/blob/02639f6b09375fe03fa2243868be17bec1dfa33c/crates/sui-graphql-client/src/query_types/mod.rs?plain=1#L124-L126 + +7. Read the `cynic` [documentation](https://cynic-rs.dev/) to learn how to work with it, particularly when it comes to passing arguments to the query.