11use crate :: error:: Result ;
2- #[ cfg( any( feature = "postgres" , feature = "sqlite" ) ) ]
2+ #[ cfg( any( feature = "postgres" , feature = "sqlite" , feature = "mysql" ) ) ]
33use crate :: error:: WundergraphError ;
4- #[ cfg( any( feature = "postgres" , feature = "sqlite" ) ) ]
4+ #[ cfg( any( feature = "postgres" , feature = "sqlite" , feature = "mysql" ) ) ]
55use crate :: juniper_ext:: FromLookAheadValue ;
66use crate :: query_builder:: selection:: { BoxedQuery , LoadingHandler } ;
77use crate :: scalar:: WundergraphScalarValue ;
88use diesel:: backend:: Backend ;
99#[ cfg( feature = "sqlite" ) ]
1010use diesel:: query_dsl:: methods:: LimitDsl ;
11- #[ cfg( any( feature = "postgres" , feature = "sqlite" ) ) ]
11+ #[ cfg( any( feature = "postgres" , feature = "sqlite" , feature = "mysql" ) ) ]
1212use diesel:: query_dsl:: methods:: OffsetDsl ;
13+
1314use juniper:: LookAheadSelection ;
1415
1516/// A trait abstracting over the different behaviour of limit/offset
@@ -72,3 +73,25 @@ impl ApplyOffset for diesel::sqlite::Sqlite {
7273 }
7374 }
7475}
76+
77+ #[ cfg( feature = "mysql" ) ]
78+ impl ApplyOffset for diesel:: mysql:: Mysql {
79+ fn apply_offset < ' a , L , Ctx > (
80+ query : BoxedQuery < ' a , L , Self , Ctx > ,
81+ select : & LookAheadSelection < ' _ , WundergraphScalarValue > ,
82+ ) -> Result < BoxedQuery < ' a , L , Self , Ctx > >
83+ where
84+ L : LoadingHandler < Self , Ctx > ,
85+ {
86+ use juniper:: LookAheadMethods ;
87+ if let Some ( offset) = select. argument ( "offset" ) {
88+ Ok ( <_ as OffsetDsl >:: offset (
89+ query,
90+ i64:: from_look_ahead ( offset. value ( ) )
91+ . ok_or ( WundergraphError :: CouldNotBuildFilterArgument ) ?,
92+ ) )
93+ } else {
94+ Ok ( query)
95+ }
96+ }
97+ }
0 commit comments