|
1 | 1 | use crate::{ |
2 | | - graphql, |
| 2 | + GraphQLError, RuleError, graphql, |
| 3 | + parser::SourcePosition, |
3 | 4 | schema::model::RootNode, |
4 | 5 | tests::fixtures::starwars::schema::{Database, Query}, |
5 | 6 | types::scalars::{EmptyMutation, EmptySubscription}, |
@@ -290,6 +291,26 @@ async fn test_query_name_invalid_variable() { |
290 | 291 | ); |
291 | 292 | } |
292 | 293 |
|
| 294 | +#[tokio::test] |
| 295 | +async fn test_rejects_unknown_argument_on_query_field_without_args() { |
| 296 | + let doc = "{ hero { name(unknownArg: true) } }"; |
| 297 | + let database = Database::new(); |
| 298 | + let schema = RootNode::new( |
| 299 | + Query, |
| 300 | + EmptyMutation::<Database>::new(), |
| 301 | + EmptySubscription::<Database>::new(), |
| 302 | + ); |
| 303 | + |
| 304 | + assert_eq!( |
| 305 | + crate::execute(doc, None, &schema, &graphql::vars! {}, &database).await, |
| 306 | + Err(GraphQLError::ValidationError(vec![RuleError::new( |
| 307 | + r#"Unknown argument "unknownArg" on field "name" of type "Character""#, |
| 308 | + &[SourcePosition::new(14, 0, 14)], |
| 309 | + )])), |
| 310 | + "expected validation error, got successful response", |
| 311 | + ); |
| 312 | +} |
| 313 | + |
293 | 314 | #[tokio::test] |
294 | 315 | async fn test_query_friends_names() { |
295 | 316 | let doc = r#"{ human(id: "1000") { friends { name } } }"#; |
|
0 commit comments