File tree Expand file tree Collapse file tree 2 files changed +57
-17
lines changed
src/query_builder/selection Expand file tree Collapse file tree 2 files changed +57
-17
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments