use serde::{Deserialize, Serialize};
use crate::schema::{
field_type::{DeprecationInfo, FieldType},
graphql_value::GraphQLValue,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ArgumentDefinition {
pub name: String,
pub arg_type: FieldType,
#[serde(default)]
pub nullable: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default_value: Option<GraphQLValue>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deprecation: Option<DeprecationInfo>,
}
impl ArgumentDefinition {
#[must_use]
pub fn new(name: impl Into<String>, arg_type: FieldType) -> Self {
Self {
name: name.into(),
arg_type,
nullable: false,
default_value: None,
description: None,
deprecation: None,
}
}
#[must_use]
pub fn optional(name: impl Into<String>, arg_type: FieldType) -> Self {
Self {
name: name.into(),
arg_type,
nullable: true,
default_value: None,
description: None,
deprecation: None,
}
}
#[must_use]
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn deprecated(mut self, reason: Option<String>) -> Self {
self.deprecation = Some(DeprecationInfo { reason });
self
}
#[must_use]
pub const fn is_deprecated(&self) -> bool {
self.deprecation.is_some()
}
#[must_use]
pub fn deprecation_reason(&self) -> Option<&str> {
self.deprecation.as_ref().and_then(|d| d.reason.as_deref())
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[allow(clippy::struct_excessive_bools)] pub struct AutoParams {
#[serde(default)]
pub has_where: bool,
#[serde(default)]
pub has_order_by: bool,
#[serde(default)]
pub has_limit: bool,
#[serde(default)]
pub has_offset: bool,
}
impl AutoParams {
#[must_use]
pub const fn all() -> Self {
Self {
has_where: true,
has_order_by: true,
has_limit: true,
has_offset: true,
}
}
#[must_use]
pub fn none() -> Self {
Self::default()
}
}