Skip to content

Commit

Permalink
Improve docs and README for trustfall_stubgen. (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi authored Jun 30, 2023
1 parent 5daac1f commit aaac853
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion trustfall_stubgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trustfall_stubgen"
version = "0.2.0"
version = "0.2.1"
rust-version = "1.70"
license = "Apache-2.0"
description = "Generate a Trustfall adapter stub for a given schema."
Expand Down
28 changes: 28 additions & 0 deletions trustfall_stubgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# trustfall_stubgen

Given a Trustfall schema, autogenerate a high-quality Rust adapter stub
fully wired up with all types, properties, and edges referenced in the schema.

First, install the CLI with: `cargo install --locked trustfall_stubgen --features cli`
Then generate Trustfall adapter stubs for your schema with:
```
trustfall_stubgen --schema <your_schema.graphql> --target <output_directory>
```
Under the hood this directly calls the [`generate_rust_stub`] function from this crate.
This crate can also be used as a library, so you can call that function directly from
your own code without going through the CLI.

The generated Trustfall adapter stub has the following structure:
| file name | purpose |
| ---------------------- | ------------------------------------------------------ |
| adapter/mod.rs | connects everything together |
| adapter/schema.graphql | contains the schema for the adapter |
| adapter/adapter.rs | contains the adapter implementation |
| adapter/vertex.rs | contains the vertex type definition |
| adapter/entrypoints.rs | contains the entry points where all queries must start |
| adapter/properties.rs | contains the property implementations |
| adapter/edges.rs | contains the edge implementations |

See an example of
[a generated adapter stub](https://github.com/obi1kenobi/trustfall/tree/main/trustfall_stubgen/test_data/expected_outputs/hackernews/adapter)
from this crate's test suite.
28 changes: 26 additions & 2 deletions trustfall_stubgen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
//! # trustfall_stubgen
//!
//! Given a Trustfall schema, autogenerate a Rust adapter stub fully wired up with
//! all types, properties, and edges referenced in the schema.
//! Given a Trustfall schema, autogenerate a high-quality Rust adapter stub
//! fully wired up with all types, properties, and edges referenced in the schema.
//!
//! First, install the CLI with: `cargo install --locked trustfall_stubgen --features cli`
//! Then generate Trustfall adapter stubs for your schema with:
//! ```
//! trustfall_stubgen --schema <your_schema.graphql> --target <output_directory>
//! ```
//! Under the hood this directly calls the [`generate_rust_stub`] function from this crate.
//! This crate can also be used as a library, so you can call that function directly from
//! your own code without going through the CLI.
//!
//! The generated Trustfall adapter stub has the following structure:
//! | file name | purpose |
//! | ---------------------- | ------------------------------------------------------ |
//! | adapter/mod.rs | connects everything together |
//! | adapter/schema.graphql | contains the schema for the adapter |
//! | adapter/adapter.rs | contains the adapter implementation |
//! | adapter/vertex.rs | contains the vertex type definition |
//! | adapter/entrypoints.rs | contains the entry points where all queries must start |
//! | adapter/properties.rs | contains the property implementations |
//! | adapter/edges.rs | contains the edge implementations |
//!
//! See an example of
//! [a generated adapter stub](https://github.com/obi1kenobi/trustfall/tree/main/trustfall_stubgen/test_data/expected_outputs/hackernews/adapter)
//! from this crate's test suite.

#![forbid(unsafe_code)]

Expand Down

0 comments on commit aaac853

Please sign in to comment.