A bring your own types GraphQL client library for Rust https://cynic-rs.dev
  • Rust 98.8%
  • CSS 0.6%
  • TypeScript 0.4%
Find a file
Graeme Coupar 54224e5d4a
All checks were successful
Build TS / build-ts (push) Successful in 25s
Release-plz / Release-plz PR (push) Successful in 56s
Build & Test Rust / check-format (push) Successful in 28s
Build & Test Rust / build-rust (push) Successful in 4m38s
chore: add cynic-book build to ci (#1204)
Migrating to grebedoc.dev instead of netlify

Reviewed-on: #1204
Co-authored-by: Graeme Coupar <graeme@turbofish.tech>
Co-committed-by: Graeme Coupar <graeme@turbofish.tech>
2026-03-02 21:22:21 +01:00
.config Use cargo-nextest on CI (#593) 2022-12-15 18:48:52 +00:00
.forgejo chore: add cynic-book build to ci (#1204) 2026-03-02 21:22:21 +01:00
cynic chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
cynic-book chore: update links to point at codeberg (#1194) 2026-02-27 21:13:02 +01:00
cynic-cli chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
cynic-codegen fix: missing docs in QueryVariables derive (#1201) 2026-02-28 09:38:47 +01:00
cynic-introspection chore: update reqwest to 0.13 (#1190) 2026-02-22 12:45:44 +00:00
cynic-parser chore: release cynic-v3.13, cynic-parser-v0.11 (#1168) 2026-02-27 21:36:50 +01:00
cynic-parser-deser chore: release cynic-v3.13, cynic-parser-v0.11 (#1168) 2026-02-27 21:36:50 +01:00
cynic-parser-deser-macros chore: release cynic-v3.13, cynic-parser-v0.11 (#1168) 2026-02-27 21:36:50 +01:00
cynic-proc-macros chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
cynic-querygen fix: refactor the cynic_querygen interface (#1187) 2026-01-11 20:44:10 +00:00
cynic-querygen-web chore: update links to point at codeberg (#1194) 2026-02-27 21:13:02 +01:00
examples chore: update reqwest to 0.13 (#1190) 2026-02-22 12:45:44 +00:00
graphql-mocks chore: bump to 1.85, edition 2024 (#1172) 2025-09-28 14:56:07 +00:00
large-api-example chore: update reqwest to 0.13 (#1190) 2026-02-22 12:45:44 +00:00
schemas chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
tests chore: update reqwest to 0.13 (#1190) 2026-02-22 12:45:44 +00:00
.gitattributes stop running lalrpop in build.rs 2024-01-14 14:10:22 +00:00
.gitignore chore: bump to 1.85, edition 2024 (#1172) 2025-09-28 14:56:07 +00:00
.ignore Registration benchmarks & optimisations (#715) 2023-06-11 16:49:00 +00:00
Cargo.lock chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
Cargo.toml chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
CHANGELOG.md chore: release v3.13.1 (#1203) 2026-02-28 11:19:16 +01:00
CODE_OF_CONDUCT.md Add code of conduct 2020-06-21 16:53:04 +01:00
CONTRIBUTING.md chore: update links to point at codeberg (#1194) 2026-02-27 21:13:02 +01:00
LICENSE Add LICENSE 2020-06-20 13:09:05 +01:00
logo.png Give the logo a white background. (#204) 2021-02-14 16:58:35 +00:00
README.md chore: update links to point at codeberg (#1194) 2026-02-27 21:13:02 +01:00
release-plz.toml chore: fix cynic changelog path (#1113) 2024-12-03 14:09:55 +00:00
renovate.json chore: renovate should group lalrpop updates 2024-09-01 15:38:59 +01:00
rust-toolchain chore: bump to 1.85, edition 2024 (#1172) 2025-09-28 14:56:07 +00:00

Cynic

A bring your own types GraphQL client for Rust

Crate Info API Docs IRC Room

Documentation | Examples | Changelog

Overview

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.

Features

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
  • Introspection via cynic-cli or cynic-introspection
  • GraphQL Subscriptions via graphql-ws-client.
  • Field directives (@skip, @include and any custom directives that don't require client support)

Documentation

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

Inspiration

  • 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.

Getting Help

If you want help with cynic you can join the #cynic chat room on IRC using any of these options: