Skip to content

Commit 1fc06e1

Browse files
committed
Update diesel to a version that is likely to be merged
1 parent 4fef3ee commit 1fc06e1

File tree

22 files changed

+314
-137
lines changed

22 files changed

+314
-137
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ members = [
88
]
99

1010
[replace]
11-
"diesel:1.2.2" = { git = "https://github.com/weiznich/diesel", rev = "deb2cd532d05" }
12-
"diesel_migrations:1.2.0" = { git = "https://github.com/weiznich/diesel", rev = "deb2cd532d05" }
13-
"migrations_internals:1.2.0" = { git = "https://github.com/weiznich/diesel", rev = "deb2cd532d05" }
14-
"migrations_macros:1.2.0" = { git = "https://github.com/weiznich/diesel", rev = "deb2cd532d05" }
15-
"diesel_derives:1.2.0" = { git = "https://github.com/weiznich/diesel", rev = "deb2cd532d05" }
11+
"diesel:1.3.2" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
12+
"diesel_migrations:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
13+
"migrations_internals:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
14+
"migrations_macros:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
15+
"diesel_derives:1.3.0" = { git = "https://github.com/weiznich/diesel", rev = "a0e25315820290" }
1616
"juniper:0.9.2" = { git = "https://github.com/weiznich/juniper", rev = "15cfff0a78" }
1717
"juniper_codegen:0.9.2" = { git = "https://github.com/weiznich/juniper/", rev = "15cfff0a78" }

wundergraph/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Georg Semmler <[email protected]>"]
55
license = "MIT OR Apache-2.0"
66

77
[dependencies]
8-
diesel = { version = "=1.2.2", features = ["r2d2"]}
8+
diesel = { version = "=1.3.2", features = ["r2d2"]}
99
juniper = "=0.9.2"
1010
indexmap = "1"
1111
wundergraph_derive = { path = "../wundergraph_derive" }

wundergraph/src/helper/primary_keys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ where
359359
}
360360
}
361361

362+
#[derive(Debug)]
362363
pub struct PrimaryKeyInfo(String);
363364

364365
impl PrimaryKeyInfo {

wundergraph/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//#![deny(warnings, missing_debug_implementations, missing_copy_implementations)]
1+
#![deny(missing_debug_implementations, missing_copy_implementations)]
22
// Clippy lints
33
#![cfg_attr(feature = "clippy", allow(unstable_features))]
44
#![cfg_attr(feature = "clippy", feature(plugin))]

wundergraph/src/mutations/delete.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ pub trait DeleteHelper<DB, R, Ctx> {
4343
type Handler: HandleDelete<DB, R, Ctx>;
4444
}
4545

46+
4647
#[doc(hidden)]
48+
#[derive(Debug)]
4749
pub struct DeleteableWrapper<D>(D);
4850

4951
impl<I, R, DB, Ctx, T> DeleteHelper<DB, R, Ctx> for I

wundergraph/src/mutations/insert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub trait HandleInsert<DB, R, Ctx>: Sized {
9696
}
9797

9898
#[doc(hidden)]
99+
#[derive(Debug)]
99100
pub struct InsertableWrapper<I>(I);
100101

101102
impl<I, DB, R, Ctx> InsertHelper<DB, R, Ctx> for I

wundergraph/src/mutations/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub trait UpdateHelper<DB, R, Ctx> {
4141
}
4242

4343
#[doc(hidden)]
44+
#[derive(Debug)]
4445
pub struct AsChangeSetWrapper<U>(U);
4546

4647
impl<U, DB, R, Ctx, T> UpdateHelper<DB, R, Ctx> for U

wundergraph/src/query_helper/has_many.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use diesel::backend::Backend;
2+
use diesel::sql_types::{Bool, Nullable};
3+
use diesel::Queryable;
14
use juniper::meta::MetaType;
25
use juniper::{
36
Arguments, ExecutionResult, Executor, FieldError, GraphQLType, Registry, Selection, Value,
@@ -25,6 +28,19 @@ impl<T> HasMany<T> {
2528
}
2629
}
2730

31+
impl<DB, T> Queryable<Nullable<Bool>, DB> for HasMany<T>
32+
where
33+
DB: Backend,
34+
bool: Queryable<Bool, DB>,
35+
{
36+
type Row = <Option<bool> as Queryable<Nullable<Bool>, DB>>::Row;
37+
38+
fn build(row: Self::Row) -> Self {
39+
assert!(<Option<bool> as Queryable<_, _>>::build(row).is_none());
40+
HasMany::NotLoaded
41+
}
42+
}
43+
2844
impl<T> GraphQLType for HasMany<T>
2945
where
3046
T: GraphQLType,

wundergraph/src/query_helper/has_one.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use diesel::associations::ForeignKey;
1+
use diesel::associations::Identifiable;
22
use diesel::backend::Backend;
33
use diesel::expression::bound::Bound;
44
use diesel::expression::AsExpression;
55
use diesel::Queryable;
6+
use helper::FromLookAheadValue;
67
use juniper::meta::MetaType;
78
use juniper::{
8-
Arguments, ExecutionResult, Executor, FieldError, GraphQLType, Registry, Selection, Value,
9+
Arguments, ExecutionResult, Executor, FieldError, FromInputValue, GraphQLType, InputValue,
10+
Registry, Selection, ToInputValue, Value, LookAheadValue
911
};
12+
1013
use std::hash::Hash;
1114

1215
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -15,16 +18,46 @@ pub enum HasOne<R, T> {
1518
Item(T),
1619
}
1720

18-
impl<R, T, ST> ForeignKey<ST> for HasOne<R, T>
21+
impl<'a, K, I> Into<Option<&'a K>> for &'a HasOne<K, I>
1922
where
20-
R: ForeignKey<ST> + ::std::cmp::Eq + Hash,
23+
&'a I: Identifiable<Id = &'a K>,
24+
K: Eq + Hash,
2125
{
22-
type KeyType = <R as ForeignKey<ST>>::KeyType;
26+
fn into(self) -> Option<&'a K> {
27+
match *self {
28+
HasOne::Id(ref k) => Some(k),
29+
HasOne::Item(ref i) => Some(i.id()),
30+
}
31+
}
32+
}
2333

24-
fn key(&self) -> Option<&Self::KeyType> {
34+
impl<R, T> FromInputValue for HasOne<R, T>
35+
where
36+
R: FromInputValue,
37+
{
38+
fn from_input_value(v: &InputValue) -> Option<Self> {
39+
R::from_input_value(v).map(HasOne::Id)
40+
}
41+
}
42+
43+
impl<R, T> FromLookAheadValue for HasOne<R, T>
44+
where
45+
R: FromLookAheadValue,
46+
{
47+
fn from_look_ahead(v: &LookAheadValue) -> Option<Self> {
48+
R::from_look_ahead(v).map(HasOne::Id)
49+
}
50+
}
51+
52+
impl<R, T> ToInputValue for HasOne<R, T>
53+
where
54+
R: ToInputValue,
55+
T: ToInputValue,
56+
{
57+
fn to_input_value(&self) -> InputValue {
2558
match *self {
26-
HasOne::Id(ref id) => id.key(),
27-
_ => None,
59+
HasOne::Id(ref i) => i.to_input_value(),
60+
HasOne::Item(ref i) => i.to_input_value(),
2861
}
2962
}
3063
}

wundergraph/src/query_helper/lazy_load.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use diesel::backend::Backend;
2+
use diesel::sql_types::{NotNull, Nullable};
23
use diesel::Queryable;
34
use filter::filter_value::FilterValue;
45
use helper::{FromLookAheadValue, Nameable};
@@ -30,27 +31,30 @@ impl<T> LazyLoad<T> {
3031
}
3132
}
3233

33-
impl<T, C> FilterValue<C> for LazyLoad<T>
34-
where
35-
T: FilterValue<C>,
36-
{
37-
type RawValue = <T as FilterValue<C>>::RawValue;
38-
type AdditionalFilter = <T as FilterValue<C>>::AdditionalFilter;
39-
}
40-
41-
impl<T, ST, DB> Queryable<ST, DB> for LazyLoad<T>
34+
impl<DB, T, ST> Queryable<Nullable<ST>, DB> for LazyLoad<T>
4235
where
4336
DB: Backend,
4437
T: Queryable<ST, DB>,
38+
ST: NotNull,
4539
{
46-
type Row = <T as Queryable<ST, DB>>::Row;
40+
type Row = <Option<T> as Queryable<Nullable<ST>, DB>>::Row;
4741

4842
fn build(row: Self::Row) -> Self {
49-
let row = Queryable::build(row);
50-
LazyLoad::Item(row)
43+
match Queryable::build(row) {
44+
None => LazyLoad::NotLoaded,
45+
Some(i) => LazyLoad::Item(i),
46+
}
5147
}
5248
}
5349

50+
impl<T, C> FilterValue<C> for LazyLoad<T>
51+
where
52+
T: FilterValue<C>,
53+
{
54+
type RawValue = <T as FilterValue<C>>::RawValue;
55+
type AdditionalFilter = <T as FilterValue<C>>::AdditionalFilter;
56+
}
57+
5458
impl<T> GraphQLType for LazyLoad<T>
5559
where
5660
T: GraphQLType,

wundergraph/src/query_helper/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mod has_many;
22
mod has_one;
33
mod lazy_load;
4+
pub mod null;
45

56
pub use self::has_many::HasMany;
67
pub use self::has_one::HasOne;
78
pub use self::lazy_load::LazyLoad;
9+
pub use self::null::Null;

wundergraph/src/query_helper/null.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use diesel::backend::Backend;
2+
use diesel::expression::{AppearsOnTable, Expression, NonAggregate, SelectableExpression};
3+
use diesel::query_builder::{AstPass, QueryFragment, QueryId};
4+
use diesel::result::QueryResult;
5+
use diesel::sql_types::{NotNull, Nullable};
6+
use std::marker::PhantomData;
7+
8+
#[derive(Debug, Clone, Copy)]
9+
pub struct Null<ST>(PhantomData<ST>);
10+
11+
pub fn null<ST>() -> Null<ST> {
12+
Null(PhantomData)
13+
}
14+
15+
impl<ST> Expression for Null<ST>
16+
where
17+
ST: NotNull,
18+
{
19+
type SqlType = Nullable<ST>;
20+
}
21+
22+
impl<ST, DB> QueryFragment<DB> for Null<ST>
23+
where
24+
DB: Backend,
25+
{
26+
fn walk_ast(&self, mut pass: AstPass<DB>) -> QueryResult<()> {
27+
pass.push_sql(" NULL ");
28+
Ok(())
29+
}
30+
}
31+
32+
impl<ST> QueryId for Null<ST>
33+
where
34+
ST: QueryId + NotNull,
35+
{
36+
type QueryId = <Nullable<ST> as QueryId>::QueryId;
37+
const HAS_STATIC_QUERY_ID: bool = true;
38+
}
39+
40+
impl<ST> NonAggregate for Null<ST> {}
41+
42+
impl<ST, QS> AppearsOnTable<QS> for Null<ST>
43+
where
44+
Self: Expression,
45+
{
46+
}
47+
48+
impl<T, ST> SelectableExpression<T> for Null<ST>
49+
where
50+
Self: Expression,
51+
{
52+
}

wundergraph_bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Georg Semmler <[email protected]>"]
55

66
[dependencies]
77
wundergraph = {path = "../wundergraph", default-features = false, features = ["postgres", "chrono"]}
8-
diesel = {version = "=1.2.2", features = ["r2d2", "sqlite", "chrono", "postgres"]}
8+
diesel = {version = "=1.3.2", features = ["r2d2", "sqlite", "chrono", "postgres"]}
99
juniper = "=0.9.2"
1010
actix = "0.7"
1111
actix-web = "0.7"

wundergraph_bench/src/api.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ struct Album {
202202
id: i32,
203203
title: String,
204204
artist_id: HasOne<i32, Artist>,
205-
#[diesel(default)]
206205
#[wundergraph(is_nullable_reference = "true")]
207206
tracks: HasMany<Track>,
208207
}
@@ -214,7 +213,6 @@ struct Album {
214213
struct Artist {
215214
id: i32,
216215
name: Option<String>,
217-
#[diesel(default)]
218216
albums: HasMany<Album>,
219217
}
220218

@@ -246,8 +244,7 @@ struct Customer {
246244
phone: Option<String>,
247245
fax: Option<String>,
248246
email: String,
249-
support_rep_id: HasOne<Option<i32>, Option<Employee>>,
250-
#[diesel(default)]
247+
support_rep_id: Option<HasOne<i32, Employee>>,
251248
invoices: HasMany<Invoice>,
252249
}
253250

@@ -271,7 +268,6 @@ struct Employee {
271268
phone: Option<String>,
272269
fax: Option<String>,
273270
email: Option<String>,
274-
#[diesel(default)]
275271
#[wundergraph(is_nullable_reference = "true")]
276272
customers: HasMany<Customer>,
277273
}
@@ -313,7 +309,6 @@ struct Film {
313309
struct Genre {
314310
id: i32,
315311
name: Option<String>,
316-
#[diesel(default)]
317312
#[wundergraph(is_nullable_reference = "true")]
318313
tracks: HasMany<Track>,
319314
}
@@ -347,7 +342,6 @@ struct Invoice {
347342
billing_country: Option<String>,
348343
billing_postal_code: Option<String>,
349344
// total: BigDecimal,
350-
#[diesel(default)]
351345
invoice_lines: HasMany<InvoiceLine>,
352346
}
353347

@@ -358,7 +352,6 @@ struct Invoice {
358352
struct MediaType {
359353
id: i32,
360354
name: Option<String>,
361-
#[diesel(default)]
362355
tracks: HasMany<Track>,
363356
}
364357

@@ -369,7 +362,6 @@ struct MediaType {
369362
struct Playlist {
370363
id: i32,
371364
name: Option<String>,
372-
#[diesel(default)]
373365
playlist_track: HasMany<PlaylistTrack>,
374366
}
375367

@@ -394,16 +386,14 @@ struct PlaylistTrack {
394386
struct Track {
395387
id: i32,
396388
name: String,
397-
album_id: HasOne<Option<i32>, Option<Album>>,
389+
album_id: Option<HasOne<i32, Album>>,
398390
media_type_id: HasOne<i32, MediaType>,
399-
genre_id: HasOne<Option<i32>, Option<Genre>>,
391+
genre_id: Option<HasOne<i32, Genre>>,
400392
composer: Option<String>,
401393
milliseconds: i32,
402394
bytes: Option<i32>,
403395
// unit_price: BigDecimal,
404-
#[diesel(default)]
405396
invoice_lines: HasMany<InvoiceLine>,
406-
#[diesel(default)]
407397
playlist_track: HasMany<PlaylistTrack>,
408398
}
409399

0 commit comments

Comments
 (0)