🎬 That's a Wrap for GraphQLConf 2024! • Watch the Videos • Check out the recorded talks and workshops

Code Using GraphQL

Sort by:
cynic
A bring your own types GraphQL client for Rust
README

A client library for rust that generates queries from types you provide, verifying that the types match the shape of your schema.

It provides a generator to bootstrap types from existing GraphQL queries.

Usage example:

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
    schema_path = "../schemas/starwars.schema.graphql",
    query_module = "query_dsl",
    graphql_type = "Root",
    argument_struct = "FilmArguments"
)]
struct FilmDirectorQuery {
    #[arguments(id = &args.id)]
    film: Option<Film>,
}
 
#[derive(cynic::QueryFragment, Debug)]
#[cynic(
    schema_path = "../schemas/starwars.schema.graphql",
    query_module = "query_dsl",
    graphql_type = "Film"
)]
struct Film {
    title: Option<String>,
    director: Option<String>,
}
 
#[derive(cynic::FragmentArguments)]
struct FilmArguments {
    id: Option<cynic::Id>,
}
 
fn main() {
    use cynic::{QueryBuilder, http::ReqwestBlockingExt};
 
    let query = FilmDirectorQuery::build(&FilmArguments {
        id: Some("ZmlsbXM6MQ==".into()),
    })
 
    reqwest::blocking::Client::new()
        .post("https://swapi-graphql.netlify.com/.netlify/functions/index")
        .run_graphql(query)
        .unwrap()
}
 
mod query_dsl {
    cynic::query_dsl!("../schemas/starwars.schema.graphql");
}
gql_client
Minimal GraphQL client for Rust
README

Usage example

use gql_client::Client;
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let endpoint = "https://graphqlzero.almansi.me/api";
  let query = r#"
    query AllPostsQuery {
      posts {
        data {
          id
        }
      }
    }
  "#;
 
  let client = Client::new(endpoint);
  let data: AllPosts = client.query::<AllPosts>(query).await.unwrap();
 
  println!("{:?}" data);
 
  Ok(())
}
Async-graphql
Async-graphql is a high-performance server-side library that supports all GraphQL specifications.
README
 use async_graphql::*;
 struct Query;
 #[Object]
 impl Query {
    /// Returns the sum of a and b
    async fn add(&self, a: i32, b: i32) -> i32 {
        a + b
    }
 }
graphql-rust/juniper
GraphQL server library for Rust