async-graphql/src/validation/visitors/cache_control.rs

25 lines
885 B
Rust
Raw Normal View History

2020-03-24 10:54:22 +00:00
use crate::registry::Type;
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::CacheControl;
use graphql_parser::query::{Field, SelectionSet};
pub struct CacheControlCalculate<'a> {
pub cache_control: &'a mut CacheControl,
}
impl<'ctx, 'a> Visitor<'ctx> for CacheControlCalculate<'a> {
fn enter_selection_set(&mut self, ctx: &mut VisitorContext<'_>, _selection_set: &SelectionSet) {
2020-04-05 08:00:26 +00:00
if let Some(current_type) = ctx.current_type() {
if let Type::Object { cache_control, .. } = current_type {
self.cache_control.merge(cache_control);
}
2020-03-24 10:54:22 +00:00
}
}
fn enter_field(&mut self, ctx: &mut VisitorContext<'_>, field: &Field) {
if let Some(registry_field) = ctx.parent_type().unwrap().field_by_name(&field.name) {
self.cache_control.merge(&registry_field.cache_control);
}
}
}