with enum

This commit is contained in:
2023-01-29 20:14:52 +01:00
parent 0bf6b0e91e
commit 2a1f7c3f26
14 changed files with 97 additions and 19 deletions

View 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)
}
}

View File

@@ -1,3 +1,4 @@
pub mod enumeration;
pub mod scalar;
mod utility;

View File

@@ -29,8 +29,10 @@ impl Handler for Scalar {
fn render_struct(&self, t: &FullType) -> eyre::Result<genco::prelude::rust::Tokens> {
let name = t.name.as_ref().ok_or(eyre::anyhow!("name not found"))?;
let scalar = rust::import("dagger_core", "Scalar");
Ok(quote! {
pub struct $name(Scalar);
pub struct $name($scalar);
})
}