Skip to content

Commit 94190cc

Browse files
committed
More WIP
1 parent 4fcc10b commit 94190cc

File tree

36 files changed

+1690
-764
lines changed

36 files changed

+1690
-764
lines changed

wundergraph/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ authors = ["Georg Semmler <[email protected]>"]
55
license = "MIT OR Apache-2.0"
66
autotests = false
77
edition = "2018"
8+
repository = "https://github.com/weiznich/wundergraph"
9+
readme = "../README.md"
10+
keywords = ["GraphQL", "ORM", "PostgreSQL", "SQLite"]
11+
categories = ["database", "web-programming"]
12+
description = "A GraphQL ORM build on top of diesel"
813

914
[dependencies]
1015
serde = "1"
@@ -19,15 +24,15 @@ log = "0.4"
1924
paste = "0.1"
2025

2126
[dev-dependencies]
22-
wundergraph_example = { path = "../wundergraph_example", default-features = false, features = ["postgres"] }
23-
wundergraph_bench = { path = "../wundergraph_bench" }
27+
wundergraph_example = { path = "../wundergraph_example", default-features = false }
28+
wundergraph_bench = { path = "../wundergraph_bench", default-features = false }
2429
diesel_migrations = "1.3.0"
2530
serde_json = "1"
2631
criterion = "0.2"
2732
lazy_static = "1"
2833

2934
[features]
30-
default = ["postgres"]
35+
default = ["postgres", "extras"]
3136
#default = ["postgres", "extras"]
3237
debug = ["wundergraph_derive/debug"]
3338
sqlite = ["diesel/sqlite", "wundergraph_derive/sqlite"]

wundergraph/bench/queries.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ const QUERIES: &[&str] = &[
7474
}
7575
}
7676
}"#,
77-
// r#"query artists_collaboration {
78-
// Artists(filter: {albums: {tracks: {composer: {eq: "Ludwig van Beethoven"}}}})
79-
// {
80-
// id
81-
// name
82-
// }
83-
//}"#,
77+
r#"query artists_collaboration {
78+
Artists(filter: {albums: {tracks: {composer: {eq: "Ludwig van Beethoven"}}}})
79+
{
80+
id
81+
name
82+
}
83+
}"#,
8484
r#"query artistByArtistId {
8585
Artists(filter: {id: {eq:3}}) {
8686
id

wundergraph/src/filter/build_filter.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ where
2828
}
2929
}
3030

31-
#[cfg_attr(feature = "cargo-clippy", allow(use_self))]
3231
impl<T, DB> BuildFilter<DB> for Option<T>
3332
where
3433
T: BuildFilter<DB>,
@@ -51,24 +50,3 @@ where
5150
None
5251
}
5352
}
54-
55-
// impl<DB, T> BuildFilter<DB> for Box<T>
56-
// where
57-
// T: BuildFilter<DB> + Sized,
58-
// DB: Backend,
59-
// {
60-
// type Ret = T::Ret;
61-
62-
// fn into_filter(self) -> Option<Self::Ret> {
63-
// T::into_filter(*self)
64-
// }
65-
// }
66-
67-
// impl<DB, T> BuildFilter<DB> for T where DB: Backend, T: Expression<SqlType = ::diesel::sql_types::Bool> + NonAggregate + QueryFragment<DB> {
68-
69-
// type Ret = T;
70-
71-
// fn into_filter(self) -> Option<Self::Ret> {
72-
// Some(self)
73-
// }
74-
// }

wundergraph/src/filter/filter_helper.rs

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::query_helper::placeholder::{FieldListExtractor, NonTableFieldExtracto
1212
use crate::query_helper::tuple::ConcatTuples;
1313
use crate::query_helper::{HasMany, HasOne};
1414
use crate::scalar::WundergraphScalarValue;
15-
use crate::LoadingHandler;
15+
use crate::{ApplyOffset, LoadingHandler};
1616
use diesel::associations::HasTable;
1717
use diesel::backend::Backend;
1818
use diesel::expression::NonAggregate;
@@ -73,7 +73,7 @@ pub trait CreateFilter {
7373

7474
impl<L, DB, Ctx> CreateFilter for FilterConverter<L, DB, Ctx>
7575
where
76-
DB: Backend + 'static,
76+
DB: Backend + ApplyOffset + 'static,
7777
DB::QueryBuilder: Default,
7878
L::Table: 'static,
7979
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -109,7 +109,7 @@ where
109109
L: HasTable,
110110
O: WundergraphBelongsTo<L::Table, DB, Ctx>,
111111
O::Table: 'static,
112-
DB: Backend + 'static,
112+
DB: Backend + ApplyOffset + 'static,
113113
<O::Table as QuerySource>::FromClause: QueryFragment<DB>,
114114
DB::QueryBuilder: Default,
115115
{
@@ -179,7 +179,7 @@ where
179179

180180
impl<C, K, I, DB, Ctx> AsColumnFilter<C, DB, Ctx> for HasOne<K, I>
181181
where
182-
DB: Backend + 'static,
182+
DB: Backend + ApplyOffset + 'static,
183183
I::Table: 'static,
184184
I: LoadingHandler<DB, Ctx>,
185185
<I::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -193,7 +193,7 @@ where
193193
#[allow(clippy::use_self)]
194194
impl<C, K, I, DB, Ctx> AsColumnFilter<C, DB, Ctx> for Option<HasOne<K, I>>
195195
where
196-
DB: Backend + 'static,
196+
DB: Backend + ApplyOffset + 'static,
197197
I::Table: 'static,
198198
I: LoadingHandler<DB, Ctx>,
199199
<I::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -209,7 +209,7 @@ where
209209

210210
impl<L, DB, Ctx> Nameable for FilterWrapper<L, DB, Ctx>
211211
where
212-
DB: Backend + 'static,
212+
DB: Backend + ApplyOffset + 'static,
213213
L::Table: 'static,
214214
L: LoadingHandler<DB, Ctx>,
215215
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -231,6 +231,11 @@ where
231231
fn into_filter(f: F) -> Option<Self::Ret>;
232232

233233
fn from_inner_look_ahead(objs: &[(&str, LookAheadValue<'_, WundergraphScalarValue>)]) -> F;
234+
fn from_inner_input_value(
235+
obj: IndexMap<&str, &InputValue<WundergraphScalarValue>>,
236+
) -> Option<F>;
237+
238+
fn to_inner_input_value(f: &F, _v: &mut IndexMap<&str, InputValue<WundergraphScalarValue>>);
234239

235240
fn register_fields<'r>(
236241
_info: &NameBuilder<()>,
@@ -240,16 +245,19 @@ where
240245

241246
impl<L, DB, Ctx> BuildFilter<DB> for FilterWrapper<L, DB, Ctx>
242247
where
243-
DB: Backend + 'static,
248+
DB: Backend + ApplyOffset + 'static,
244249
L::Table: 'static,
245250
L: LoadingHandler<DB, Ctx>,
246251
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
247252
DB::QueryBuilder: Default,
248253
FilterConverter<L, DB, Ctx>: CreateFilter,
249254
L::Table: BuildFilterHelper<DB, <FilterConverter<L, DB, Ctx> as CreateFilter>::Filter, Ctx>,
250255
{
251-
type Ret =
252-
<L::Table as BuildFilterHelper<DB, <FilterConverter<L, DB, Ctx> as CreateFilter>::Filter, Ctx>>::Ret;
256+
type Ret = <L::Table as BuildFilterHelper<
257+
DB,
258+
<FilterConverter<L, DB, Ctx> as CreateFilter>::Filter,
259+
Ctx,
260+
>>::Ret;
253261

254262
fn into_filter(self) -> Option<Self::Ret> {
255263
<L::Table as BuildFilterHelper<DB, _, Ctx>>::into_filter(self.filter)
@@ -261,7 +269,7 @@ pub struct FilterBuildHelper<F, L, DB, Ctx>(pub F, PhantomData<(L, DB, Ctx)>);
261269

262270
impl<F, L, DB, Ctx> Nameable for FilterBuildHelper<F, L, DB, Ctx>
263271
where
264-
DB: Backend + 'static,
272+
DB: Backend + ApplyOffset + 'static,
265273
L::Table: 'static,
266274
L: LoadingHandler<DB, Ctx>,
267275
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -274,7 +282,7 @@ where
274282

275283
impl<L, DB, Ctx> InnerFilter for FilterWrapper<L, DB, Ctx>
276284
where
277-
DB: Backend + 'static,
285+
DB: Backend + ApplyOffset + 'static,
278286
L::Table: 'static,
279287
L: LoadingHandler<DB, Ctx>,
280288
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
@@ -287,9 +295,11 @@ where
287295
const FIELD_COUNT: usize = L::Table::FIELD_COUNT;
288296

289297
fn from_inner_input_value(
290-
_obj: IndexMap<&str, &InputValue<WundergraphScalarValue>>,
298+
obj: IndexMap<&str, &InputValue<WundergraphScalarValue>>,
291299
) -> Option<Self> {
292-
unimplemented!()
300+
Some(Self {
301+
filter: L::Table::from_inner_input_value(obj)?,
302+
})
293303
}
294304

295305
fn from_inner_look_ahead(objs: &[(&str, LookAheadValue<'_, WundergraphScalarValue>)]) -> Self {
@@ -298,8 +308,8 @@ where
298308
}
299309
}
300310

301-
fn to_inner_input_value(&self, _v: &mut IndexMap<&str, InputValue<WundergraphScalarValue>>) {
302-
unimplemented!()
311+
fn to_inner_input_value(&self, v: &mut IndexMap<&str, InputValue<WundergraphScalarValue>>) {
312+
L::Table::to_inner_input_value(&self.filter, v)
303313
}
304314

305315
fn register_fields<'r>(
@@ -336,9 +346,8 @@ macro_rules! __impl_build_filter_for_tuples {
336346
}
337347
}
338348

339-
340349
impl<$($T,)* Loading, Back, Ctx> InnerFilter for FilterBuildHelper<($(Option<$T>,)*), Loading, Back, Ctx>
341-
where Back: Backend + 'static,
350+
where Back: Backend + ApplyOffset + 'static,
342351
Loading::Table: 'static,
343352
Loading: LoadingHandler<Back, Ctx>,
344353
<Loading::Table as QuerySource>::FromClause: QueryFragment<Back>,
@@ -352,8 +361,18 @@ macro_rules! __impl_build_filter_for_tuples {
352361
fn from_inner_input_value(
353362
obj: IndexMap<&str, &InputValue<WundergraphScalarValue>>
354363
) -> Option<Self> {
355-
dbg!(obj);
356-
unimplemented!()
364+
let mut values = ($(Option::<$T>::default(),)*);
365+
for (name, value) in obj {
366+
match name {
367+
$(
368+
n if n == Loading::FIELD_NAMES[$idx] => {
369+
values.$idx = <$T as FromInputValue<WundergraphScalarValue>>::from_input_value(value);
370+
}
371+
)*
372+
_ => {}
373+
}
374+
}
375+
Some(FilterBuildHelper(values, PhantomData))
357376
}
358377

359378
fn from_inner_look_ahead(
@@ -376,8 +395,11 @@ macro_rules! __impl_build_filter_for_tuples {
376395
fn to_inner_input_value(
377396
&self, v: &mut IndexMap<&str, InputValue<WundergraphScalarValue>>
378397
) {
379-
dbg!(v);
380-
unimplemented!()
398+
let inner = &self.0;
399+
$(
400+
let value = <Option<$T> as ToInputValue<WundergraphScalarValue>>::to_input_value(&inner.$idx);
401+
v.insert(Loading::FIELD_NAMES[$idx], value);
402+
)*
381403
}
382404

383405
fn register_fields<'r>(

wundergraph/src/graphql_type.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::query_helper::placeholder::FieldListExtractor;
22
use crate::scalar::WundergraphScalarValue;
3-
use crate::LoadingHandler;
3+
use crate::{LoadingHandler, ApplyOffset};
44
use diesel::backend::Backend;
55
use diesel::query_builder::QueryFragment;
66
use diesel::QuerySource;
@@ -15,7 +15,7 @@ pub struct GraphqlOrderWrapper<T, DB, Ctx>(PhantomData<(T, DB, Ctx)>);
1515

1616
impl<T, DB, Ctx> GraphQLType<WundergraphScalarValue> for GraphqlWrapper<T, DB, Ctx>
1717
where
18-
DB: Backend + 'static,
18+
DB: Backend + ApplyOffset + 'static,
1919
T::Table: 'static,
2020
<T::Table as QuerySource>::FromClause: QueryFragment<DB>,
2121
T: LoadingHandler<DB, Ctx>,
@@ -48,7 +48,7 @@ pub struct OrderTypeInfo<L, DB, Ctx>(String, PhantomData<(L, DB, Ctx)>);
4848

4949
impl<L, DB, Ctx> Default for OrderTypeInfo<L, DB, Ctx>
5050
where
51-
DB: Backend + 'static,
51+
DB: Backend + ApplyOffset + 'static,
5252
L::Table: 'static,
5353
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
5454
L: LoadingHandler<DB, Ctx>,
@@ -61,7 +61,7 @@ where
6161

6262
impl<T, DB, Ctx> GraphQLType<WundergraphScalarValue> for GraphqlOrderWrapper<T, DB, Ctx>
6363
where
64-
DB: Backend + 'static,
64+
DB: Backend + ApplyOffset + 'static,
6565
T::Table: 'static,
6666
<T::Table as QuerySource>::FromClause: QueryFragment<DB>,
6767
T: LoadingHandler<DB, Ctx>,
@@ -107,6 +107,13 @@ impl<T, DB, Ctx> FromInputValue<WundergraphScalarValue> for GraphqlOrderWrapper<
107107

108108
pub trait WundergraphGraphqlMapper<DB, Ctx> {
109109
type GraphQLType: GraphQLType<WundergraphScalarValue, TypeInfo = ()>;
110+
111+
fn register_arguments<'r>(
112+
_registry: &mut Registry<'r, WundergraphScalarValue>,
113+
field: meta::Field<'r, WundergraphScalarValue>,
114+
) -> meta::Field<'r, WundergraphScalarValue> {
115+
field
116+
}
110117
}
111118

112119
impl<T, DB, Ctx> WundergraphGraphqlMapper<DB, Ctx> for T
@@ -143,7 +150,7 @@ macro_rules! wundergraph_graphql_helper_impl {
143150
$(
144151
impl<$($T,)* Loading, Back, Ctx> WundergraphGraphqlHelper<Loading, Back, Ctx> for ($($T,)*)
145152
where $($T: WundergraphGraphqlMapper<Back, Ctx>,)*
146-
Back: Backend + 'static,
153+
Back: Backend + ApplyOffset + 'static,
147154
Loading::Table: 'static,
148155
<Loading::Table as QuerySource>::FromClause: QueryFragment<Back>,
149156
Loading: LoadingHandler<Back, Ctx>,
@@ -158,6 +165,7 @@ macro_rules! wundergraph_graphql_helper_impl {
158165
let fields = [
159166
$({
160167
let mut field = registry.field::<<$T as WundergraphGraphqlMapper<Back, Ctx>>::GraphQLType>(names[$idx], &());
168+
field = <$T as WundergraphGraphqlMapper<Back, Ctx>>::register_arguments(registry, field);
161169
if let Some(doc) = Loading::field_description($idx) {
162170
field = field.description(doc);
163171
}

wundergraph/src/helper/from_lookahead.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ where
107107
}
108108
}
109109

110-
#[allow(clippy::use_self)]
111110
impl<T> FromLookAheadValue for Box<T>
112111
where
113112
T: FromLookAheadValue,
@@ -117,7 +116,6 @@ where
117116
}
118117
}
119118

120-
#[cfg_attr(feature = "cargo-clippy", allow(use_self))]
121119
impl<T> FromLookAheadValue for Option<T>
122120
where
123121
T: FromLookAheadValue,

wundergraph/src/helper/primary_keys.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,12 @@ macro_rules! primary_key_input_object_impl {
173173
}
174174
}
175175

176-
fn to_input_value(_values: &($($ST, )+)) -> InputValue<WundergraphScalarValue> {
177-
// let mut map = IndexMap::with_capacity($Tuple);
178-
// $(
179-
// map.extend($T::to_input_value(values.$idx))
180-
// )
181-
// $(
182-
// map.insert($T::NAME, values.$idx.to_input_value());
183-
// )+
184-
// InputValue::object(map)
185-
unimplemented!()
176+
fn to_input_value(values: &($($ST, )+)) -> InputValue<WundergraphScalarValue> {
177+
let mut map = IndexMap::with_capacity($Tuple);
178+
$(
179+
map.insert($T::NAME, $T::to_input_value(&values.$idx));
180+
)+
181+
InputValue::object(map)
186182
}
187183
}
188184
)+

0 commit comments

Comments
 (0)