2020-03-10 06:14:09 +00:00
|
|
|
use crate::validation::context::ValidatorContext;
|
|
|
|
use crate::validation::visitor::Visitor;
|
|
|
|
use graphql_parser::query::Field;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ScalarLeafs;
|
|
|
|
|
|
|
|
impl<'a> Visitor<'a> for ScalarLeafs {
|
|
|
|
fn enter_field(&mut self, ctx: &mut ValidatorContext<'a>, field: &'a Field) {
|
|
|
|
if let Some(ty) = ctx.parent_type() {
|
|
|
|
if let Some(schema_field) = ty.field_by_name(&field.name) {
|
2020-03-14 03:46:20 +00:00
|
|
|
if let Some(ty) = ctx.registry.basic_type_by_typename(&schema_field.ty) {
|
2020-03-10 06:14:09 +00:00
|
|
|
if ty.is_leaf() && !field.selection_set.items.is_empty() {
|
|
|
|
ctx.report_error(vec![field.position], format!(
|
|
|
|
"Field \"{}\" must not have a selection since type \"{}\" has no subfields",
|
|
|
|
field.name, ty.name()
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|