Added document validation in the resolve_into_stream method and a test (#604)

This commit is contained in:
Jordão Rodrigues Oliveira Rosario 2020-04-05 18:59:10 -03:00 committed by GitHub
parent e5f655044e
commit 1412561ffd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -152,4 +152,24 @@ async fn async_field_validation_error() {
assert!(is_validation_error);
}
#[tokio::test]
async fn resolve_into_stream_validation_error() {
let schema = RootNode::new(Query, Mutation, Subscription);
let doc = r#"
subscription {
nonExistent
}
"#;
let vars = Default::default();
let result = juniper::resolve_into_stream(doc, None, &schema, &vars, &()).await;
assert!(result.is_err());
let error = result.err().unwrap();
let is_validation_error = match error {
GraphQLError::ValidationError(_) => true,
_ => false,
};
assert!(is_validation_error);
}
fn main() {}

View file

@ -328,6 +328,16 @@ where
let document: crate::ast::Document<'a, S> =
parse_document_source(document_source, &root_node.schema)?;
{
let mut ctx = ValidatorContext::new(&root_node.schema, &document);
visit_all_rules(&mut ctx, &document);
let errors = ctx.into_errors();
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
}
}
let operation = get_operation(&document, operation_name)?;
{