Skip to content

Commit b0cf967

Browse files
authored
Merge pull request #42 from weiznich/bugfix/41
Bugfix/41
2 parents a9ab2d3 + e3a9afc commit b0cf967

File tree

7 files changed

+58
-107
lines changed

7 files changed

+58
-107
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
brew update
5959
brew uninstall --ignore-dependencies libpq
6060
brew install postgres
61+
/usr/local/Cellar/postgresql/12.2/bin/initdb --locale=C -E UTF-8 /usr/local/var/postgres
6162
/usr/local/opt/postgres/bin/pg_ctl -D /usr/local/var/postgres start
6263
sleep 3
6364
/usr/local/opt/postgres/bin/createuser -s postgres

wundergraph/src/query_builder/selection/filter/transformator/default.rs

-16
This file was deleted.

wundergraph/src/query_builder/selection/filter/transformator/exclusive.rs

-27
This file was deleted.

wundergraph/src/query_builder/selection/filter/transformator/mod.rs

-28
This file was deleted.

wundergraph/src/query_builder/selection/filter/transformator/selective.rs

-19
This file was deleted.

wundergraph/src/query_builder/selection/mod.rs

+17-17
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

+40
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)