14 releases

new 0.14.10 Feb 18, 2025
0.14.9 Feb 6, 2025
0.14.5 Jan 29, 2025
0.13.4 Jan 14, 2025

#517 in Magic Beans

Download history 90/week @ 2025-01-08 278/week @ 2025-01-15 298/week @ 2025-01-22 521/week @ 2025-01-29 571/week @ 2025-02-05 346/week @ 2025-02-12

1,771 downloads per month
Used in 3 crates

Apache-2.0

340KB
9K SLoC

Rust 5K SLoC // 0.0% comments GraphQL 4.5K SLoC

Sui GraphQL client

First version of Aftermath's Sui GraphQL client using cynic.

The main item here is the GraphQlClient trait, defining the common interface for clients interacting with an RPC. See the reqwest feature for a pre-made implementation.

The queries inclued here (under feature queries) were constructed with the help of cynics generator and use the scalars defined in sui_gql_schema.

Custom queries

Users building their own queries should first:

  1. add sui_gql_schema as a build dependency
  2. register its schema in a build.rs file;
  3. import the schema module in any module defining new fragments

For steps 1 and 2, you can check this crate's [build-dependencies] and build.rs for an example of how to do so. Read more about schema crates in https://cynic-rs.dev/large-apis.

Then, to create query structs, we recommend using the generator with Sui's GraphQL schema and to try reusing the scalars defined in scalars as those automatically convert opaque types to more useful ones like af_sui_types.

Features

  • move-types: compatibility with af-move-type types
  • mutations: enables the mutations submodule
  • queries: enables the queries submodule with pre-made queries
  • reqwest: enables the reqwest submodule with an implementation of GraphQlClient
  • scalars: re-exports the scalars module of sui_gql_schema
  • Query builder: generator.cynic-rs.dev. When prompted either
    • click the "A URL" button and pass in:
      • https://sui-testnet.mystenlabs.com/graphql to build queries against the testnet schema
      • https://sui-mainnet.mystenlabs.com/graphql for the mainnet one
    • click the "I'll Paste It" button and paste the schema
  • Cynic's guide

Requests over HTTPS

You need to import the TLS backend feature yourself in order to use HTTPS. Since this crate only provides a client implementation using reqwest, that means enabling one of its TLS features, e.g.,

  • reqwest = { features = ["native-tls"], ... }
  • reqwest = { features = ["rustls-tls"], ... }

Otherwise, you'll get an error like

$ cargo run --example gql-latest-checkpoint
# ...
Error:
   0: Client error: Inner(ReqwestError(reqwest::Error { kind: Request, url: "https://sui-testnet.mystenlabs.com/graphql", source: hyper_util::client::legacy::Error(Connect, "invalid URL, scheme is not http") }))

Location:
   crates/sui-gql-client/examples/latest_checkpoint.rs:21

This is why the [dev-dependencies] here use reqwest = { features = ["rustls-tls"], ... }, otherwise the crate examples would fail.

Dependencies

~10–23MB
~317K SLoC