DEV Community

Tom Houlé
Tom Houlé

Posted on

graphql_client 0.6, to the browser and beyond

graphql_client is getting a new release today! The most visible new feature is a new graphql_client_web crate that makes calling a GraphQL API from Rust code running in browsers boilerplate-free.

Another notable change is the move into the graphql-rust organization on GitHub, where we can pool documentation and branding efforts with the other GraphQL crates. Thanks to the graphql-rust team for their support with and feedback on graphql_client!

Web client

Calling a GraphQL API in WebAssembly code inside a browser is now as simple as this:

  • Add graphql_client_web as a dependency.
  • Construct a client with Client::new("<GraphQL endpoint URL>").
  • Call it with a normal graphql_client query struct and the query variables struct.
  • You get a Rust future that returns a strongly typed response or a client error.

This is how it looks (copy-pasted directly from the test suite):

    schema_path = "tests/countries_schema.json",
    query_path = "tests/Germany.graphql"
struct Country;

fn test_country() -> impl Future<Item = (), Error = JsValue> {
            country::Variables {
                country_code: "CN".to_owned(),
        .map(|response| {
            let continent_name = response
                .expect("response data is not null")
                .expect("country is not null")
                .expect("continent is not null")
                .expect("country is on a continent");

            assert_eq!(continent_name, "Asia");
        .map_err(|err| {
            panic!("{:?}", err);

Network (via the fetch API) and serialization/deserialization are taken care of by graphql_client_web.

This crate works with the wasm-bindgen ecosystem only (web-sys, js-sys), support for stdweb could be investigated if there is demand for it.

This is a first release, so expect some minor breaking changes, especially around error handling.


@h-michael has been pushing for code generation using the CLI, and it is shaping up rapidly with new features such as:

  • Support for query documents defining multiple queries
  • Optional formatting of the output code with rustfmt

Other fixes and improvements

There were a few other new features, bug fixes and breaking (naming) changes. You can take a look at the changelog for the full list of changes.

Next steps

reform the ninja empire

The library is now in a very usable state, and we can start thinking about a 1.0 release. There are many enhancement ideas in the issues, but the core abstractions are stable, so we should not be too afraid to take that step once the documentation is in better shape.


As always, many warm thanks to everyone who contributed to make the crate happen!

Top comments (0)