Upgrading Cynic v2 to v3

Cynic made a few minor breaking changes in v3, but they shouldn't affect most users. However, there were a bunch of quality of life changes in this version. This guide will show you how to take advantage of these.

Update your Cargo.toml

First update the version reference for cynic in your Cargo.toml to 3.

This verison also added an optional rkyv feature that can speed up compilation for some users. Add this in if you like.

Pre-register your schemas

v3 added the concept of pre-registering schemas. This saves you from having to pass the schema_path attribute to the derives, and makes the schema_for_derives macro mostly redundant (assuming you're only using one schema at least).

To do this you should create a build.rs in the root of your project, with the following contents:

fn main() {

Where github is the name of your schema and schemas/github.graphql is the path to the schema SDL (relative to the build.rs file).

See the schemas page for more details.

After you've done this, you should be able to remove any schema_path attributes, and any uses of the schema_for_derives attribute.

Replace use_schema with #[cynic::schema]

If you've pre-registered your schema you should update the code where you call use_schema. Find this code, it'll look something like this:

fn main() {
mod schema {

and replace it with

fn main() {
mod schema {}

where github is the name you gave the schema in your build.rs