Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs and README for trustfall_stubgen. #334

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading