pub fn generate_rust_stub(schema: &str, target: &Path) -> Result<()>
Expand description

Given a schema, make a Rust adapter stub for it in the given directory.

Generated code structure:

  • adapter/mod.rs connects everything together
  • adapter/schema.graphql contains the schema for the adapter
  • adapter/adapter_impl.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
  • adapter/tests.rs contains test code

Example

let schema_text = std::fs::read_to_string("./schema.graphql").expect("failed to read schema");
generate_rust_stub(&schema_text, Path::new("crate/with/generated/stubs/src"))
    .expect("stub generation failed");