use crate::QueryGraphError;
use query_structure::{DomainError, RelationFieldRef};
use user_facing_errors::query_engine::validation::ValidationError;
#[derive(Debug)]
pub enum QueryGraphBuilderError {
SchemaError(String),
InputError(String),
MissingRequiredArgument {
argument_name: String,
field_name: String,
object_name: String,
},
QueryParserError(ValidationError),
DomainError(DomainError),
AssertionError(String),
RelationViolation(RelationViolation),
RecordsNotConnected {
relation_name: String,
parent_name: String,
child_name: String,
},
RecordNotFound(String),
QueryGraphError(QueryGraphError),
}
#[derive(Debug)]
pub struct RelationViolation {
pub(crate) relation_name: String,
pub(crate) model_a_name: String,
pub(crate) model_b_name: String,
}
impl From<RelationFieldRef> for RelationViolation {
fn from(rf: RelationFieldRef) -> Self {
Self::from(&rf)
}
}
impl From<&RelationFieldRef> for RelationViolation {
fn from(rf: &RelationFieldRef) -> Self {
let relation = rf.relation();
let relation_name = relation.name();
let [model_a_name, model_b_name] = relation.walker().models().map(|m| rf.dm.walk(m).name().to_owned());
Self {
relation_name,
model_a_name,
model_b_name,
}
}
}
impl From<DomainError> for QueryGraphBuilderError {
fn from(err: DomainError) -> Self {
QueryGraphBuilderError::DomainError(err)
}
}
impl From<ValidationError> for QueryGraphBuilderError {
fn from(err: ValidationError) -> Self {
QueryGraphBuilderError::QueryParserError(err)
}
}
impl From<QueryGraphError> for QueryGraphBuilderError {
fn from(err: QueryGraphError) -> Self {
QueryGraphBuilderError::QueryGraphError(err)
}
}