Skip to main content

generate_ruby_graphql

Function generate_ruby_graphql 

Source
pub fn generate_ruby_graphql(schema: &str, target: &str) -> Result<String>
Expand description

Generate Ruby GraphQL code from a schema

Parses the GraphQL schema string and generates idiomatic Ruby code with graphql-ruby class definitions for types, resolvers, and schema configuration based on the target specification. Supports RBS (Ruby Signature) type definition generation for integration with Steep static type checker.

§Arguments

  • schema - GraphQL schema as a string (SDL format)
  • target - Generation target: “all” (complete), “types” (types only), “resolvers” (resolver classes), “schema” (schema definition), or “rbs” (RBS type signatures for Steep)

§Returns

Generated Ruby code or RBS signatures as a string, or an error if parsing/generation fails

§Examples

Generate all Ruby code:

let schema = r#"
type Query {
  hello: String!
}
"#;
let code = generate_ruby_graphql(schema, "all")?;
println!("{}", code);

Generate RBS type signatures:

let rbs = generate_ruby_graphql(schema, "rbs")?;
// Output is RBS syntax compatible with Steep type checker