Skip to main content

graphql_tools/validation/rules/
defaults.rs

1use crate::validation::{rules::ValidationRule, validate::ValidationPlan};
2
3use super::{
4    FieldsOnCorrectType, FragmentsOnCompositeTypes, KnownArgumentNames, KnownDirectives,
5    KnownFragmentNames, KnownTypeNames, LeafFieldSelections, LoneAnonymousOperation,
6    NoFragmentsCycle, NoUndefinedVariables, NoUnusedFragments, NoUnusedVariables,
7    OverlappingFieldsCanBeMerged, PossibleFragmentSpreads, ProvidedRequiredArguments,
8    SingleFieldSubscriptions, UniqueArgumentNames, UniqueDirectivesPerLocation,
9    UniqueFragmentNames, UniqueOperationNames, UniqueVariableNames, ValuesOfCorrectType,
10    VariablesAreInputTypes, VariablesInAllowedPosition,
11};
12
13pub fn default_rules_validation_plan() -> ValidationPlan {
14    let rules: Vec<Box<dyn ValidationRule>> = vec![
15        Box::new(UniqueOperationNames::new()),
16        Box::new(LoneAnonymousOperation::new()),
17        Box::new(SingleFieldSubscriptions::new()),
18        Box::new(KnownTypeNames::new()),
19        Box::new(FragmentsOnCompositeTypes::new()),
20        Box::new(VariablesAreInputTypes::new()),
21        Box::new(LeafFieldSelections::new()),
22        Box::new(FieldsOnCorrectType::new()),
23        Box::new(UniqueFragmentNames::new()),
24        Box::new(KnownFragmentNames::new()),
25        Box::new(NoUnusedFragments::new()),
26        Box::new(OverlappingFieldsCanBeMerged::new()),
27        Box::new(NoFragmentsCycle::new()),
28        Box::new(PossibleFragmentSpreads::new()),
29        Box::new(NoUnusedVariables::new()),
30        Box::new(NoUndefinedVariables::new()),
31        Box::new(KnownArgumentNames::new()),
32        Box::new(UniqueArgumentNames::new()),
33        Box::new(UniqueVariableNames::new()),
34        Box::new(ProvidedRequiredArguments::new()),
35        Box::new(KnownDirectives::new()),
36        Box::new(VariablesInAllowedPosition::new()),
37        Box::new(ValuesOfCorrectType::new()),
38        Box::new(UniqueDirectivesPerLocation::new()),
39    ];
40
41    ValidationPlan::from(rules)
42}