pub fn generate_php_graphql(schema: &str, target: &str) -> Result<String>Expand description
Generate PHP GraphQL code from a schema
Parses the GraphQL schema string and generates complete PHP code with type definitions,
resolver implementations, and schema configuration based on the target specification.
Generated code uses PSR-4 namespacing, strict_types declarations, typed properties,
and webonyx/graphql-php library for schema binding.
§Arguments
schema- GraphQL schema as a string (SDL format)target- Generation target: “all” (complete), “types” (types only), “resolvers” (resolver classes), or “schema” (schema definition)
§Returns
Generated PHP code as a string with:
<?phpopening tag anddeclare(strict_types=1);- PSR-4 namespace declaration under GraphQL namespace
- Class definitions for object types, input types, and enums (PHP 8.1+)
- Typed properties with appropriate nullability markers
- Resolver method signatures with return type declarations
- Or an error if parsing/generation fails
§Examples
ⓘ
let schema = r#"
type Query {
user(id: ID!): User
}
type User {
id: ID!
name: String!
}
"#;
let code = generate_php_graphql(schema, "all")?;
println!("{}", code);