mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-07-25 19:09:22 +02:00
fix: serialization of enum args for graphql (#34)
This commit is contained in:
@@ -196,6 +196,22 @@ pub fn type_ref_is_scalar(type_ref: &TypeRef) -> bool {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn type_ref_is_enum(type_ref: &TypeRef) -> bool {
|
||||
let mut type_ref = type_ref.clone();
|
||||
if type_ref
|
||||
.kind
|
||||
.pipe(|k| *k == __TypeKind::NON_NULL)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
type_ref = *type_ref.of_type.unwrap().clone();
|
||||
}
|
||||
|
||||
type_ref
|
||||
.kind
|
||||
.pipe(|k| *k == __TypeKind::ENUM)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn type_ref_is_object(type_ref: &TypeRef) -> bool {
|
||||
let mut type_ref = type_ref.clone();
|
||||
if type_ref
|
||||
|
@@ -5,8 +5,8 @@ use genco::quote;
|
||||
use genco::tokens::quoted;
|
||||
|
||||
use crate::functions::{
|
||||
type_field_has_optional, type_ref_is_list, type_ref_is_list_of_objects, type_ref_is_object,
|
||||
type_ref_is_optional, type_ref_is_scalar, CommonFunctions, Scalar,
|
||||
type_field_has_optional, type_ref_is_enum, type_ref_is_list, type_ref_is_list_of_objects,
|
||||
type_ref_is_object, type_ref_is_optional, type_ref_is_scalar, CommonFunctions, Scalar,
|
||||
};
|
||||
use crate::utility::OptionExt;
|
||||
|
||||
@@ -133,6 +133,12 @@ fn render_required_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Opt
|
||||
}
|
||||
}
|
||||
|
||||
if type_ref_is_enum(&s.input_value.type_) {
|
||||
return Some(quote! {
|
||||
query = query.arg_enum($(quoted(name)), $(n));
|
||||
})
|
||||
}
|
||||
|
||||
if type_ref_is_list(&s.input_value.type_) {
|
||||
let inner = *s
|
||||
.input_value
|
||||
@@ -187,6 +193,14 @@ fn render_optional_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Opt
|
||||
let n = format_struct_name(&s.input_value.name);
|
||||
let name = &s.input_value.name;
|
||||
|
||||
if type_ref_is_enum(&s.input_value.type_) {
|
||||
return Some(quote! {
|
||||
if let Some($(&n)) = opts.$(&n) {
|
||||
query = query.arg_enum($(quoted(name)), $(n));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Some(quote! {
|
||||
if let Some($(&n)) = opts.$(&n) {
|
||||
query = query.arg($(quoted(name)), $(&n));
|
||||
|
Reference in New Issue
Block a user