use std::collections::HashMap;
#[derive(Debug, Clone, Default)]
pub struct ProtographSchema {
pub types: HashMap<String, EntityType>,
pub input_types: HashMap<String, InputType>,
pub enums: HashMap<String, EnumType>,
pub query_fields: Vec<QueryField>,
pub mutation_fields: Vec<MutationField>,
}
#[derive(Debug, Clone)]
pub struct EntityType {
pub name: String,
pub is_entity: bool,
pub is_private: bool,
pub fields: Vec<Field>,
}
#[derive(Debug, Clone)]
pub struct InputType {
pub name: String,
pub fields: Vec<InputField>,
}
#[derive(Debug, Clone)]
pub struct EnumType {
pub name: String,
pub values: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct Field {
pub name: String,
pub field_type: FieldType,
pub is_private: bool,
pub relationship: Option<Relationship>,
}
#[derive(Debug, Clone)]
pub struct InputField {
pub name: String,
pub field_type: FieldType,
}
#[derive(Debug, Clone)]
pub enum FieldType {
Named(String),
NonNull(Box<FieldType>),
List(Box<FieldType>),
}
impl FieldType {
pub fn base_type(&self) -> &str {
match self {
FieldType::Named(name) => name,
FieldType::NonNull(inner) => inner.base_type(),
FieldType::List(inner) => inner.base_type(),
}
}
pub fn is_list(&self) -> bool {
match self {
FieldType::List(_) => true,
FieldType::NonNull(inner) => inner.is_list(),
_ => false,
}
}
pub fn is_non_null(&self) -> bool {
matches!(self, FieldType::NonNull(_))
}
}
#[derive(Debug, Clone)]
pub enum Relationship {
BelongsTo { foreign_key: String },
HasMany { foreign_key: String },
ManyToMany { junction_table: String, foreign_key: String },
}
#[derive(Debug, Clone)]
pub struct QueryField {
pub name: String,
pub arguments: Vec<InputField>,
pub return_type: FieldType,
}
#[derive(Debug, Clone)]
pub struct MutationField {
pub name: String,
pub arguments: Vec<InputField>,
pub return_type: FieldType,
}