with proper optional types

This commit is contained in:
2023-02-01 15:27:44 +01:00
parent 8549cfc3a7
commit f4a812a7d2
3 changed files with 337 additions and 342 deletions

View File

@@ -11,15 +11,6 @@ pub fn render_type_ref(inner: &TypeRef) -> eyre::Result<rust::Tokens> {
return t.clone().of_type.map(|t| *t);
};
if !is_required_type_ref(inner) {
if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?;
return Ok(quote! {
Option<$inner_field>
});
}
}
if is_list_type(&inner) {
if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?;
@@ -58,6 +49,15 @@ pub fn render_type_ref(inner: &TypeRef) -> eyre::Result<rust::Tokens> {
});
}
if !is_required_type_ref(inner) {
if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?;
return Ok(quote! {
Option<$inner_field>
});
}
}
if let Some(inner_type) = inner.of_type.as_ref() {
return render_type_ref(&inner_type);
}

View File

@@ -32,8 +32,8 @@ pub fn is_input_object_type(t: &FullType) -> bool {
pub fn is_required_type(t: &FullTypeInputFields) -> bool {
match t.input_value.type_.kind {
Some(__TypeKind::NON_NULL) => return false,
Some(_) => return true,
Some(__TypeKind::NON_NULL) => return true,
Some(_) => return false,
_ => return false,
}
}
@@ -42,7 +42,7 @@ pub fn is_required_type_ref(t: &TypeRef) -> bool {
match t.kind {
Some(__TypeKind::NON_NULL) => return true,
Some(_) => return false,
_ => return true,
_ => return false,
}
}