51 releases (21 stable)

3.2.2 Jun 26, 2023
3.0.0-beta.3 May 13, 2023
2.2.8 Mar 3, 2023
2.2.2 Dec 28, 2022
0.1.2 Feb 4, 2020

#21 in Web programming

Download history 6404/week @ 2023-06-01 6426/week @ 2023-06-08 6378/week @ 2023-06-15 7320/week @ 2023-06-22 6679/week @ 2023-06-29 8826/week @ 2023-07-06 7040/week @ 2023-07-13 8146/week @ 2023-07-20 7255/week @ 2023-07-27 9323/week @ 2023-08-03 7935/week @ 2023-08-10 8723/week @ 2023-08-17 7691/week @ 2023-08-24 7769/week @ 2023-08-31 7215/week @ 2023-09-07 6632/week @ 2023-09-14

30,727 downloads per month
Used in 45 crates (19 directly)

MPL-2.0 license

3.5K SLoC


A bring your own types GraphQL client for Rust

Crate Info API Docs Discord Chat

Documentation | Examples | Changelog


Cynic is a GraphQL library for Rust. It's not the first but it takes a different approach from the existing libraries.

Existing libraries take a query first approach to GQL - you write a query using GraphQL and libraries use that to generate Rust structs for you using macros. This is really easy and great for getting going quickly. However, if you want to use structs that aren't quite what the macros output you're out of luck. Some more complex use cases like sharing structs among queries are also commonly not supported.

Cynic takes a different approach - it uses Rust structs to define queries and generates GraphQL from them. This gives you freedom to control the structs you'll be working with while still enjoying type safe queries, checked against the GraphQL schema. When its built in derives don't do exactly what you want it provides lower level APIs to hook in and fetch the data you want in the format you want to work with it.

Of course writing out all the structs to represent a large GraphQL query can be quite challenging, and GraphQL has excellent tooling for building queries usually. Cynic provides querygen to help with this - you write a GraphQL query using the existing GQL tooling and it'll generate some cynic structs to make that query. You can use this as a starting point for your projects - either adding on to the rust structs directly, or re-using querygen as appropriate.


Cynic is currently a work in progress, but the following features are supported:

  • Typesafe queries & mutations.
  • Defining custom scalars.
  • Building dynamic (but still type checked) queries at run time.
  • Query arguments including input objects
  • Interfaces & union types
  • GraphQL Subscriptions via graphql-ws-client. (though graphql-ws-client is fairly alpha quality)

The following features are not yet supported, though should be soon (if you want to help out with the project I'd be happy for someone else to try and implement these - if you open an issue I'd be happy to give pointers on how to go about implementing any of them)

  • Directives
  • Potentially other things (please open an issue if you find anything obviously missing)


Cynic is documented in a few places:

  1. There's a guide to using cynic on cynic-rs.dev
  2. The reference documentation on docs.rs


  • graphql-client, the original Rust GraphQL client. This is a great library for using GraphQL from Rust. It wasn't quite what I wanted but it might be what you want.
  • The idea of encoding the GraphQL typesystem into a DSL was taken from elm-graphql.
  • Most of the JSON decoding APIs were taken from Json.Decode in Elm.
  • Deriving code from structs is a fairly common Rust pattern, though serde in particular provided inspiration for the derive APIs.


~223K SLoC