6 releases

0.2.0 Mar 11, 2024
0.1.4 Jan 9, 2021
0.1.3 Dec 31, 2020

#688 in Parser implementations

Download history 1/week @ 2024-02-14 17/week @ 2024-02-21 8/week @ 2024-02-28 125/week @ 2024-03-06 62/week @ 2024-03-13 2/week @ 2024-03-20 11/week @ 2024-03-27 11/week @ 2024-04-03

153 downloads per month
Used in starry

MIT license

188 lines

MIT Latest Version docs Chat on Miaou

A simple "bring your own queries and types" GraphQL client.

Design Principles

  • I want to use my own Rust structures and not have them generated by macros
  • I want to use my own queries and not have them generated by macros
  • I want to manage queries as strings in my Rust code

Why not use it

  • For now it's very young, the API may grow and change
  • There's already a popular and well tested GraphQL client in Rust

How to use it

Simple query

The github stars example demonstrates querying GitHub's GraphQL API to get the number of stars of a repository.

First create a client, that you may keep and reuse:

let mut graphql_client = GraphqlClient::new("https://api.github.com/graphql")?;

You need the struct into which to deserialize the server's answer:

pub struct Repository {
    stargazers: Count,

(Count is a utility struct provided by byo_graphql, it's just struct Count { totalCount: usize })

And you need a query:

let query = r#"{
	repository(owner: "Canop", name: "bacon") {
	    stargazers {

note: in the example's complete code, the query is dynamically built with format!, as you'll usually do.

Now you can fetch the data:

let repo: Repository = graphql_client.get_first_item(query).await?;
let stars: usize = repo.stargazers.into();

Querying a long list

The github issues example demonstrates how to query a long list with a cursor based exchange.


~272K SLoC