A schema generator for async-graphql 4.x.
⚠️ This is a fork from linksplatform/gql-gen, which forks uselessgoddess/codegen-for-async-graphql which forks the original project at atsuhiro/codegen-for-async-graphql. All of them seem unmaintained.
Todo:
-
Support generating code for custom directives (example here)
-
Support overriding default implementation for fields and custom scalars
In order to install, just run the following command
$ git clone git@github.com:codetalkio/async-graphql-codegen.git
$ cd async-graphql-codegen
$ cargo build --bin cargo-gql-gen
$ ln -s $(pwd)/target/debug/gql-gen ~/.cargo/bin/gql-gen
- Set up your Rust project
- Create a folder inside your
src/
folder to contain the generated code (e.g.src/schema/
) - Create your GraphQL schema and store it somewhere (e.g.
schema.graphql
) - Run
gql-gen --schema schema.graphql --output ./src/schema
from the root of your project
Voila! 🎉 You have now generated Rust code from your schema types.
Check out the examples folder, which sets up the necessary structure along with an axum service (adjusted from async-graphql/examples/axum/starwars):
.
├── Cargo.toml
├── schema.graphql
└── src
├── main.rs
└── schema
└── .gitignore
We need a schema
(or similar folder) to output the generated code into, and we of course need the schema itself, which is found in schema.graphql
for the example case.
With everything set up, we are now ready to generate the code from the schema:
$ cd examples
$ gql-gen --schema schema.graphql --output ./src/schema
You can then check out the generated code in the examples/src/schema folder.