Skip to content

Commit 0d71618

Browse files
committed
As discovered in #41 we accept invalid variants for the order argument
The argument then is silently dropped. This commit changes the behaviour in such a way that now an error is generated for such cases.
1 parent 10d847e commit 0d71618

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

wundergraph/src/query_builder/selection/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,24 @@ where
375375
Self::Table: 'static,
376376
{
377377
use juniper::LookAheadMethods;
378-
if let Some(LookAheadValue::List(order)) =
379-
select.argument("order").map(LookAheadArgument::value)
380-
{
381-
let order_stmts = <Self::Columns as BuildOrder<Self::Table, DB>>::build_order(
382-
order,
383-
|local_index| {
384-
Self::FieldList::map_table_field(local_index, |global| {
385-
Self::FIELD_NAMES[global]
386-
})
387-
.expect("Field is there")
388-
},
389-
)?;
390-
for s in order_stmts {
391-
query = query.then_order_by(s);
378+
match select.argument("order").map(LookAheadArgument::value) {
379+
Some(LookAheadValue::List(order)) => {
380+
let order_stmts = <Self::Columns as BuildOrder<Self::Table, DB>>::build_order(
381+
order,
382+
|local_index| {
383+
Self::FieldList::map_table_field(local_index, |global| {
384+
Self::FIELD_NAMES[global]
385+
})
386+
.expect("Field is there")
387+
},
388+
)?;
389+
for s in order_stmts {
390+
query = query.then_order_by(s);
391+
}
392+
Ok(query)
392393
}
393-
Ok(query)
394-
} else {
395-
Ok(query)
394+
Some(_) => Err(WundergraphError::CouldNotBuildFilterArgument),
395+
None => Ok(query),
396396
}
397397
}
398398

wundergraph/tests/order.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,43 @@ fn order_desc() {
8686
]"###
8787
);
8888
}
89+
90+
#[test]
91+
fn invalid_order() {
92+
let (schema, pool) = get_example_schema();
93+
let ctx = MyContext::new(pool.get().unwrap());
94+
95+
let res = execute_query(
96+
&schema,
97+
&ctx,
98+
"
99+
{
100+
Heros(order: {column: heroName, direction: DESC}) {
101+
heroName
102+
}
103+
}
104+
",
105+
);
106+
assert!(res.is_ok());
107+
assert_json_snapshot!(
108+
res.as_json(), @r###"
109+
[
110+
null,
111+
[
112+
{
113+
"locations": [
114+
{
115+
"column": 5,
116+
"line": 3
117+
}
118+
],
119+
"message": "Could not build filter from arguments",
120+
"path": [
121+
"Heros"
122+
]
123+
}
124+
]
125+
]
126+
"###
127+
);
128+
}

0 commit comments

Comments
 (0)