with input objects

This commit is contained in:
2023-01-29 22:17:36 +01:00
parent 2a1f7c3f26
commit dc53fc1d47
5 changed files with 344 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
use graphql_introspection_query::introspection_response::{self, FullType};
use graphql_introspection_query::introspection_response::{
self, FullType, FullTypeInputFields, TypeRef, __TypeKind,
};
use crate::models::Scalars;
@@ -9,6 +11,13 @@ pub fn is_scalar_type(t: &FullType) -> bool {
false
}
pub fn is_scalar_type_ref(t: &TypeRef) -> bool {
if let Some(introspection_response::__TypeKind::SCALAR) = t.kind {
return true;
}
false
}
pub fn is_enum_type(t: &FullType) -> bool {
if let Some(introspection_response::__TypeKind::ENUM) = t.kind {
return true;
@@ -16,6 +25,36 @@ pub fn is_enum_type(t: &FullType) -> bool {
false
}
pub fn is_input_object_type(t: &FullType) -> bool {
if let Some(introspection_response::__TypeKind::INPUT_OBJECT) = t.kind {
return true;
}
false
}
pub fn is_required_type(t: &FullTypeInputFields) -> bool {
match t.input_value.type_.kind {
Some(__TypeKind::NON_NULL) => return false,
Some(_) => return true,
_ => return false,
}
}
pub fn is_required_type_ref(t: &TypeRef) -> bool {
match t.kind {
Some(__TypeKind::NON_NULL) => return false,
Some(_) => return true,
_ => return false,
}
}
pub fn is_list_type(t: &TypeRef) -> bool {
if let Some(introspection_response::__TypeKind::LIST) = t.kind {
return true;
}
false
}
pub fn is_custom_scalar_type(t: &FullType) -> bool {
if is_scalar_type(t) {
// TODO: Insert scalar
@@ -35,3 +74,23 @@ pub fn is_custom_scalar_type(t: &FullType) -> bool {
}
false
}
pub fn is_custom_scalar_type_ref(t: &TypeRef) -> bool {
if is_scalar_type_ref(t) {
// TODO: Insert scalar
let _ = match t.name.as_ref().map(|s| s.as_str()) {
Some("ID") => Scalars::ID("ID".into()),
Some("Int") => Scalars::Int(0),
Some("String") => Scalars::String("ID".into()),
Some("Float") => Scalars::Float(0.0),
Some("Boolean") => Scalars::Boolean(false),
Some("Date") => Scalars::Date("ID".into()),
Some("DateTime") => Scalars::DateTime("ID".into()),
Some("Time") => Scalars::Time("ID".into()),
Some("Decimal") => Scalars::Decimal(0.0),
Some(_) => return true,
None => return false,
};
}
false
}