Skip to content

Commit 0419020

Browse files
committed
Fix tests that followed old argument validation behavior
Add regression coverage to ensure fields without declared arguments reject unknown arguments.
1 parent 9c85420 commit 0419020

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

juniper/src/tests/query_tests.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
graphql,
2+
GraphQLError, RuleError, graphql,
3+
parser::SourcePosition,
34
schema::model::RootNode,
45
tests::fixtures::starwars::schema::{Database, Query},
56
types::scalars::{EmptyMutation, EmptySubscription},
@@ -290,6 +291,26 @@ async fn test_query_name_invalid_variable() {
290291
);
291292
}
292293

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+
293314
#[tokio::test]
294315
async fn test_query_friends_names() {
295316
let doc = r#"{ human(id: "1000") { friends { name } } }"#;

juniper/src/tests/subscriptions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn create_and_execute(
148148
#[test]
149149
fn returns_requested_object() {
150150
let query = r#"subscription {
151-
asyncHuman(id: "1") {
151+
asyncHuman {
152152
id
153153
name
154154
}
@@ -176,7 +176,7 @@ fn returns_requested_object() {
176176
#[test]
177177
fn returns_error() {
178178
let query = r#"subscription {
179-
errorHuman(id: "1") {
179+
errorHuman {
180180
id
181181
name
182182
}
@@ -227,7 +227,7 @@ fn can_access_context() {
227227
fn resolves_typed_inline_fragments() {
228228
let query = r#"subscription {
229229
... on MySubscription {
230-
asyncHuman(id: "32") {
230+
asyncHuman {
231231
id
232232
}
233233
}
@@ -255,7 +255,7 @@ fn resolves_typed_inline_fragments() {
255255
fn resolves_nontyped_inline_fragments() {
256256
let query = r#"subscription {
257257
... {
258-
asyncHuman(id: "32") {
258+
asyncHuman {
259259
id
260260
}
261261
}
@@ -310,7 +310,7 @@ fn can_access_arguments() {
310310
#[test]
311311
fn type_alias() {
312312
let query = r#"subscription {
313-
aliasedHuman: asyncHuman(id: "1") {
313+
aliasedHuman: asyncHuman {
314314
id
315315
name
316316
}

0 commit comments

Comments
 (0)