v0.10.1
This commit is contained in:
parent
352d1121b9
commit
e0ffe3faa8
23
README.md
23
README.md
|
@ -83,6 +83,29 @@
|
|||
- [X] INLINE_FRAGMENT
|
||||
- [X] Schema
|
||||
- [ ] Validation rules
|
||||
- [X] ArgumentsOfCorrectType
|
||||
- [X] DefaultValuesOfCorrectType
|
||||
- [ ] FieldsOnCorrectType
|
||||
- [ ] FragmentsOnCompositeTypes
|
||||
- [ ] KnownArgumentNames
|
||||
- [ ] KnownDirectives
|
||||
- [ ] KnownFragmentNames
|
||||
- [ ] KnownTypeNames
|
||||
- [ ] LoneAnonymousOperation
|
||||
- [ ] NoFragmentCycles
|
||||
- [ ] NoUndefinedVariables
|
||||
- [ ] NoUnusedFragments
|
||||
- [ ] NoUnusedVariables
|
||||
- [ ] OverlappingFieldsCanBeMerged
|
||||
- [ ] PossibleFragmentSpreads
|
||||
- [ ] ProvidedNonNullArguments
|
||||
- [ ] ScalarLeafs
|
||||
- [ ] UniqueArgumentNames
|
||||
- [ ] UniqueFragmentNames
|
||||
- [ ] UniqueInputFieldNames
|
||||
- [ ] UniqueOperationNames
|
||||
- [ ] UniqueVariableNames
|
||||
- [ ] VariableInAllowedPosition
|
||||
- [ ] Integration examples
|
||||
- [X] Actix-web
|
||||
- [ ] Hyper
|
||||
|
|
|
@ -12,7 +12,9 @@ mod visitor;
|
|||
|
||||
pub fn check_rules(registry: &Registry, doc: &Document) -> Result<()> {
|
||||
let mut ctx = ValidatorContext::new(registry);
|
||||
let mut visitor = VisitorNil.with(rules::ArgumentsOfCorrectType::default());
|
||||
let mut visitor = VisitorNil
|
||||
.with(rules::ArgumentsOfCorrectType::default())
|
||||
.with(rules::DefaultValuesOfCorrectType);
|
||||
|
||||
visit(&mut visitor, &mut ctx, doc);
|
||||
if !ctx.errors.is_empty() {
|
||||
|
|
38
src/validation/rules/default_values_of_correct_type.rs
Normal file
38
src/validation/rules/default_values_of_correct_type.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use crate::validation::context::ValidatorContext;
|
||||
use crate::validation::utils::is_valid_input_value;
|
||||
use crate::validation::visitor::Visitor;
|
||||
use graphql_parser::query::{Type, VariableDefinition};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultValuesOfCorrectType;
|
||||
|
||||
impl<'a> Visitor<'a> for DefaultValuesOfCorrectType {
|
||||
fn enter_variable_definition(
|
||||
&mut self,
|
||||
ctx: &mut ValidatorContext<'a>,
|
||||
variable_definition: &'a VariableDefinition,
|
||||
) {
|
||||
if let Some(value) = &variable_definition.default_value {
|
||||
if let Type::NonNullType(_) = variable_definition.var_type {
|
||||
ctx.report_error(vec![variable_definition.position],format!(
|
||||
"Argument \"{}\" has type \"{}\" and is not nullable, so it't can't have a default value",
|
||||
variable_definition.name, variable_definition.var_type,
|
||||
));
|
||||
} else {
|
||||
if !is_valid_input_value(
|
||||
ctx.registry,
|
||||
&variable_definition.var_type.to_string(),
|
||||
value,
|
||||
) {
|
||||
ctx.report_error(
|
||||
vec![variable_definition.position],
|
||||
format!(
|
||||
"Invalid default value for argument \"{}\", expected type \"{}\"",
|
||||
variable_definition.name, variable_definition.var_type
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
mod arguments_of_correct_type;
|
||||
mod default_values_of_correct_type;
|
||||
|
||||
pub use arguments_of_correct_type::ArgumentsOfCorrectType;
|
||||
pub use default_values_of_correct_type::DefaultValuesOfCorrectType;
|
||||
|
|
Loading…
Reference in New Issue
Block a user