2020-03-08 12:35:36 +00:00
|
|
|
use crate::error::RuleErrors;
|
|
|
|
use crate::registry::Registry;
|
2020-03-24 10:54:22 +00:00
|
|
|
use crate::validation::visitor::{visit, VisitorContext, VisitorNil};
|
|
|
|
use crate::{CacheControl, Result};
|
2020-03-08 12:35:36 +00:00
|
|
|
use graphql_parser::query::Document;
|
|
|
|
|
|
|
|
mod rules;
|
|
|
|
mod utils;
|
2020-03-24 10:54:22 +00:00
|
|
|
mod visitor;
|
2020-03-08 12:35:36 +00:00
|
|
|
|
2020-03-24 10:54:22 +00:00
|
|
|
pub fn check_rules(registry: &Registry, doc: &Document) -> Result<CacheControl> {
|
2020-03-22 08:45:59 +00:00
|
|
|
let mut ctx = VisitorContext::new(registry, doc);
|
2020-03-24 10:54:22 +00:00
|
|
|
let mut cache_control = CacheControl::default();
|
2020-03-08 12:58:22 +00:00
|
|
|
let mut visitor = VisitorNil
|
|
|
|
.with(rules::ArgumentsOfCorrectType::default())
|
2020-03-09 04:08:50 +00:00
|
|
|
.with(rules::DefaultValuesOfCorrectType)
|
|
|
|
.with(rules::FieldsOnCorrectType)
|
|
|
|
.with(rules::FragmentsOnCompositeTypes)
|
|
|
|
.with(rules::KnownArgumentNames::default())
|
|
|
|
.with(rules::NoFragmentCycles::default())
|
2020-03-09 10:05:52 +00:00
|
|
|
.with(rules::KnownFragmentNames)
|
|
|
|
.with(rules::KnownTypeNames)
|
|
|
|
.with(rules::LoneAnonymousOperation::default())
|
|
|
|
.with(rules::NoUndefinedVariables::default())
|
2020-03-09 12:39:46 +00:00
|
|
|
.with(rules::NoUnusedFragments::default())
|
|
|
|
.with(rules::NoUnusedVariables::default())
|
|
|
|
.with(rules::UniqueArgumentNames::default())
|
2020-03-10 06:14:09 +00:00
|
|
|
.with(rules::UniqueFragmentNames::default())
|
|
|
|
.with(rules::UniqueOperationNames::default())
|
|
|
|
.with(rules::UniqueVariableNames::default())
|
|
|
|
.with(rules::VariablesAreInputTypes)
|
|
|
|
.with(rules::VariableInAllowedPosition::default())
|
2020-03-10 10:07:47 +00:00
|
|
|
.with(rules::ScalarLeafs)
|
2020-03-17 09:26:59 +00:00
|
|
|
.with(rules::NoComposeLeafs)
|
2020-03-10 12:35:25 +00:00
|
|
|
.with(rules::PossibleFragmentSpreads::default())
|
2020-03-11 02:10:56 +00:00
|
|
|
.with(rules::ProvidedNonNullArguments)
|
2020-03-12 09:11:02 +00:00
|
|
|
.with(rules::KnownDirectives::default())
|
2020-03-14 03:46:20 +00:00
|
|
|
.with(rules::OverlappingFieldsCanBeMerged)
|
2020-03-24 10:54:22 +00:00
|
|
|
.with(rules::UploadFile)
|
|
|
|
.with(rules::CacheControlCalculate {
|
|
|
|
cache_control: &mut cache_control,
|
|
|
|
});
|
2020-03-08 12:35:36 +00:00
|
|
|
|
|
|
|
visit(&mut visitor, &mut ctx, doc);
|
|
|
|
if !ctx.errors.is_empty() {
|
|
|
|
Err(RuleErrors { errors: ctx.errors }.into())
|
|
|
|
} else {
|
2020-03-24 10:54:22 +00:00
|
|
|
Ok(cache_control)
|
2020-03-08 12:35:36 +00:00
|
|
|
}
|
|
|
|
}
|