mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-08-04 22:53:26 +02:00
with enum
This commit is contained in:
31
crates/dagger-codegen/src/handlers/enumeration.rs
Normal file
31
crates/dagger-codegen/src/handlers/enumeration.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use genco::{prelude::rust, quote};
|
||||
use graphql_introspection_query::introspection_response::FullType;
|
||||
|
||||
use crate::predicates::is_enum_type;
|
||||
|
||||
use super::{utility::render_description, Handler};
|
||||
|
||||
pub struct Enumeration;
|
||||
|
||||
impl Handler for Enumeration {
|
||||
fn predicate(&self, t: &FullType) -> bool {
|
||||
is_enum_type(t)
|
||||
}
|
||||
|
||||
fn render(&self, t: &FullType) -> eyre::Result<rust::Tokens> {
|
||||
let name = t
|
||||
.name
|
||||
.as_ref()
|
||||
.ok_or(eyre::anyhow!("could not get name from type"))?;
|
||||
|
||||
let description =
|
||||
render_description(t).ok_or(eyre::anyhow!("could not find description"))?;
|
||||
|
||||
let out = quote! {
|
||||
$description
|
||||
pub enum $name {}
|
||||
};
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user