Skip to content

Commit c8d2d48

Browse files
committed
More fixes to reach feature parity with old version
1 parent b35f8c1 commit c8d2d48

File tree

17 files changed

+370
-237
lines changed

17 files changed

+370
-237
lines changed

wundergraph/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,28 @@ diesel = { version = "1.4", features = ["r2d2"]}
1717
juniper = "0.11"
1818
indexmap = "1"
1919
wundergraph_derive = { path = "../wundergraph_derive" }
20-
uuid = { version = "0.7", optional = true }
21-
chrono = { version = "0.4", optional = true }
20+
uuid_internal = { version = "0.7", optional = true, package = "uuid" }
21+
chrono_internal = { version = "0.4", optional = true, package = "chrono" }
2222
failure = "0.1"
2323
log = "0.4"
2424
paste = "0.1"
2525

2626
[dev-dependencies]
2727
wundergraph_example = { path = "../wundergraph_example", default-features = false }
2828
wundergraph_bench = { path = "../wundergraph_bench", default-features = false }
29-
diesel_migrations = "1.3.0"
29+
diesel_migrations = "1.4.0"
3030
serde_json = "1"
3131
criterion = "0.2"
3232
lazy_static = "1"
3333

3434
[features]
3535
default = ["postgres", "extras"]
36-
#default = ["postgres", "extras"]
3736
debug = ["wundergraph_derive/debug"]
3837
sqlite = ["diesel/sqlite", "wundergraph_derive/sqlite"]
3938
postgres = ["diesel/postgres", "wundergraph_derive/postgres"]
4039
extras = ["chrono", "uuid"]
41-
42-
40+
uuid = ["uuid_internal", "diesel/uuidv07"]
41+
chrono = ["chrono_internal", "diesel/chrono"]
4342

4443
[[test]]
4544
name = "integration_tests"

wundergraph/src/filter/filter_helper.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::scalar::WundergraphScalarValue;
1515
use crate::{ApplyOffset, LoadingHandler};
1616
use diesel::associations::HasTable;
1717
use diesel::backend::Backend;
18-
use diesel::expression::NonAggregate;
18+
use diesel::expression::{NonAggregate, SelectableExpression};
1919
use diesel::query_builder::QueryFragment;
2020
use diesel::sql_types::Bool;
2121
use diesel::Expression;
@@ -104,21 +104,18 @@ pub trait AsNonColumnFilter<L, DB, Ctx> {
104104
type Filter;
105105
}
106106

107-
impl<L, O, DB, Ctx> AsNonColumnFilter<L, DB, Ctx> for HasMany<O>
107+
impl<L, O, DB, Ctx, FK> AsNonColumnFilter<L, DB, Ctx> for HasMany<O, FK>
108108
where
109109
L: HasTable,
110-
O: WundergraphBelongsTo<L::Table, DB, Ctx>,
110+
FK: Default + NonAggregate + QueryFragment<DB> + SelectableExpression<O::Table>,
111+
O: WundergraphBelongsTo<L::Table, DB, Ctx, FK>,
111112
O::Table: 'static,
112113
DB: Backend + ApplyOffset + 'static,
113114
<O::Table as QuerySource>::FromClause: QueryFragment<DB>,
114115
DB::QueryBuilder: Default,
115116
{
116-
type Filter = ReferenceFilter<
117-
<L::Table as Table>::PrimaryKey,
118-
Filter<O::Filter, O::Table>,
119-
O::ForeignKeyColumn,
120-
(),
121-
>;
117+
type Filter =
118+
ReferenceFilter<<L::Table as Table>::PrimaryKey, Filter<O::Filter, O::Table>, FK, ()>;
122119
}
123120

124121
impl<C, DB, Ctx> AsColumnFilter<C, DB, Ctx> for i16 {
@@ -161,7 +158,17 @@ where
161158
}
162159

163160
#[cfg(feature = "chrono")]
164-
impl<C, DB, Ctx> AsColumnFilter<C, DB, Ctx> for chrono::NaiveDateTime {
161+
impl<C, DB, Ctx> AsColumnFilter<C, DB, Ctx> for chrono_internal::NaiveDateTime {
162+
type Filter = FilterOption<Self, C>;
163+
}
164+
165+
#[cfg(feature = "chrono")]
166+
impl<C, DB, Ctx> AsColumnFilter<C, DB, Ctx> for chrono_internal::DateTime<chrono_internal::Utc> {
167+
type Filter = FilterOption<Self, C>;
168+
}
169+
170+
#[cfg(feature = "uuid")]
171+
impl<C, DB, Ctx> AsColumnFilter<C, DB, Ctx> for uuid_internal::Uuid {
165172
type Filter = FilterOption<Self, C>;
166173
}
167174

wundergraph/src/filter/filter_value.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,15 @@ where
8686
}
8787

8888
#[cfg(feature = "chrono")]
89-
extern crate chrono;
90-
91-
#[cfg(feature = "chrono")]
92-
impl<C> FilterValue<C> for self::chrono::NaiveDateTime {
89+
impl<C> FilterValue<C> for chrono_internal::NaiveDateTime {
9390
type RawValue = Self;
9491
type AdditionalFilter = ();
9592
}
9693

9794
#[cfg(feature = "chrono")]
98-
impl<O, C> FilterValue<C> for self::chrono::DateTime<O>
95+
impl<O, C> FilterValue<C> for chrono_internal::DateTime<O>
9996
where
100-
O: self::chrono::TimeZone,
97+
O: chrono_internal::TimeZone,
10198
Self: ToInputValue<WundergraphScalarValue>
10299
+ FromInputValue<WundergraphScalarValue>
103100
+ FromLookAheadValue,
@@ -107,16 +104,13 @@ where
107104
}
108105

109106
#[cfg(feature = "chrono")]
110-
impl<C> FilterValue<C> for self::chrono::NaiveDate {
107+
impl<C> FilterValue<C> for chrono_internal::NaiveDate {
111108
type RawValue = Self;
112109
type AdditionalFilter = ();
113110
}
114111

115112
#[cfg(feature = "uuid")]
116-
extern crate uuid;
117-
118-
#[cfg(feature = "uuid")]
119-
impl<C> FilterValue<C> for self::uuid::Uuid {
113+
impl<C> FilterValue<C> for uuid_internal::Uuid {
120114
type RawValue = Self;
121115
type AdditionalFilter = ();
122116
}

wundergraph/src/helper/from_lookahead.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ static RFC3339_PARSE_FORMAT: &'static str = "%+";
130130
#[cfg(feature = "chrono")]
131131
static RFC3339_FORMAT: &'static str = "%Y-%m-%dT%H:%M:%S%.f%:z";
132132

133-
#[cfg(feature = "chrono")]
134-
extern crate chrono;
135133

136134
#[cfg(feature = "chrono")]
137-
impl FromLookAheadValue for self::chrono::NaiveDateTime {
135+
impl FromLookAheadValue for chrono_internal::NaiveDateTime {
138136
fn from_look_ahead(v: &LookAheadValue<'_, WundergraphScalarValue>) -> Option<Self> {
139137
if let LookAheadValue::Scalar(WundergraphScalarValue::String(ref s)) = *v {
140138
Self::parse_from_str(s, RFC3339_PARSE_FORMAT).ok()
@@ -145,7 +143,7 @@ impl FromLookAheadValue for self::chrono::NaiveDateTime {
145143
}
146144

147145
#[cfg(feature = "chrono")]
148-
impl FromLookAheadValue for self::chrono::DateTime<self::chrono::Utc> {
146+
impl FromLookAheadValue for chrono_internal::DateTime<chrono_internal::Utc> {
149147
fn from_look_ahead(v: &LookAheadValue<'_, WundergraphScalarValue>) -> Option<Self> {
150148
if let LookAheadValue::Scalar(WundergraphScalarValue::String(ref s)) = *v {
151149
s.parse().ok()
@@ -156,7 +154,7 @@ impl FromLookAheadValue for self::chrono::DateTime<self::chrono::Utc> {
156154
}
157155

158156
#[cfg(feature = "chrono")]
159-
impl FromLookAheadValue for self::chrono::DateTime<self::chrono::FixedOffset> {
157+
impl FromLookAheadValue for chrono_internal::DateTime<chrono_internal::FixedOffset> {
160158
fn from_look_ahead(v: &LookAheadValue<'_, WundergraphScalarValue>) -> Option<Self> {
161159
if let LookAheadValue::Scalar(WundergraphScalarValue::String(ref s)) = *v {
162160
Self::parse_from_rfc3339(s).ok()
@@ -167,7 +165,7 @@ impl FromLookAheadValue for self::chrono::DateTime<self::chrono::FixedOffset> {
167165
}
168166

169167
#[cfg(feature = "chrono")]
170-
impl FromLookAheadValue for self::chrono::NaiveDate {
168+
impl FromLookAheadValue for chrono_internal::NaiveDate {
171169
fn from_look_ahead(v: &LookAheadValue<'_, WundergraphScalarValue>) -> Option<Self> {
172170
if let LookAheadValue::Scalar(WundergraphScalarValue::String(ref s)) = *v {
173171
Self::parse_from_str(s, RFC3339_FORMAT).ok()
@@ -178,10 +176,7 @@ impl FromLookAheadValue for self::chrono::NaiveDate {
178176
}
179177

180178
#[cfg(feature = "uuid")]
181-
extern crate uuid;
182-
183-
#[cfg(feature = "uuid")]
184-
impl FromLookAheadValue for self::uuid::Uuid {
179+
impl FromLookAheadValue for uuid_internal::Uuid {
185180
fn from_look_ahead(v: &LookAheadValue<'_, WundergraphScalarValue>) -> Option<Self> {
186181
if let LookAheadValue::Scalar(WundergraphScalarValue::String(ref s)) = *v {
187182
Self::parse_str(s).ok()

wundergraph/src/helper/nameable.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,30 @@ impl Nameable for () {
109109
}
110110

111111
#[cfg(feature = "chrono")]
112-
extern crate chrono;
113-
114-
#[cfg(feature = "chrono")]
115-
impl Nameable for self::chrono::NaiveDateTime {
112+
impl Nameable for chrono_internal::NaiveDateTime {
116113
fn name() -> String {
117114
String::from("NaiveDateTime")
118115
}
119116
}
120117

121118
#[cfg(feature = "chrono")]
122-
impl<O> Nameable for self::chrono::DateTime<O>
119+
impl<O> Nameable for chrono_internal::DateTime<O>
123120
where
124-
O: self::chrono::TimeZone,
121+
O: chrono_internal::TimeZone,
125122
{
126123
fn name() -> String {
127124
String::from("DateTime")
128125
}
129126
}
130127
#[cfg(feature = "chrono")]
131-
impl Nameable for self::chrono::NaiveDate {
128+
impl Nameable for chrono_internal::NaiveDate {
132129
fn name() -> String {
133130
String::from("Date")
134131
}
135132
}
136133

137134
#[cfg(feature = "uuid")]
138-
extern crate uuid;
139-
140-
#[cfg(feature = "uuid")]
141-
impl Nameable for self::uuid::Uuid {
135+
impl Nameable for uuid_internal::Uuid {
142136
fn name() -> String {
143137
String::from("Uuid")
144138
}

wundergraph/src/helper/primary_keys.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,15 @@ macro_rules! primary_key_input_object_impl {
188188
__diesel_for_each_tuple!(primary_key_input_object_impl);
189189

190190
#[derive(Debug)]
191-
pub struct PrimaryKeyInfo(String);
191+
pub struct PrimaryKeyInfo<T>(String, PhantomData<T>);
192192

193-
impl PrimaryKeyInfo {
194-
pub fn new<T>(table: &T) -> Self
195-
where
196-
T: QuerySource<FromClause = Identifier<'static>>,
197-
{
198-
Self(format!("{}Key", table.from_clause().0))
193+
impl<T> Default for PrimaryKeyInfo<T>
194+
where
195+
T: QuerySource<FromClause = Identifier<'static>> + HasTable<Table = T> + Table,
196+
{
197+
fn default() -> Self {
198+
let table = T::table();
199+
Self(format!("{}Key", table.from_clause().0), PhantomData)
199200
}
200201
}
201202

@@ -226,7 +227,7 @@ where
226227
V: UnRef<'a>,
227228
{
228229
type Context = Ctx;
229-
type TypeInfo = PrimaryKeyInfo;
230+
type TypeInfo = PrimaryKeyInfo<T>;
230231

231232
fn name(info: &Self::TypeInfo) -> Option<&str> {
232233
Some(&info.0)

wundergraph/src/lib.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
clippy::unnecessary_unwrap,
2828
clippy::unseparated_literal_suffix,
2929
clippy::wildcard_dependencies
30-
3130
)]
3231
#![allow(clippy::type_complexity)]
3332

@@ -60,7 +59,6 @@ pub mod helper;
6059
pub mod mutations;
6160
pub mod order;
6261
pub mod query_helper;
63-
//pub mod query_modifier;
6462
pub mod scalar;
6563
#[macro_use]
6664
mod macros;
@@ -69,22 +67,32 @@ pub mod graphql_type;
6967
use self::error::WundergraphError;
7068
use self::helper::FromLookAheadValue;
7169
use self::scalar::WundergraphScalarValue;
72-
70+
use crate::diesel_ext::BoxableFilter;
71+
use crate::filter::build_filter::BuildFilter;
72+
use crate::filter::inner_filter::InnerFilter;
73+
use crate::filter::Filter;
7374
use crate::helper::primary_keys::{PrimaryKeyArgument, UnRef};
75+
use crate::query_helper::order::BuildOrder;
7476
use crate::query_helper::placeholder::*;
77+
use crate::query_helper::select::BuildSelect;
78+
use crate::query_helper::tuple::IsPrimaryKeyIndex;
7579
use diesel::associations::HasTable;
7680
use diesel::backend::Backend;
7781
use diesel::dsl::SqlTypeOf;
7882
use diesel::expression::NonAggregate;
7983
use diesel::query_builder::{BoxedSelectStatement, QueryFragment};
8084
use diesel::query_dsl::methods::BoxedDsl;
85+
use diesel::query_dsl::methods::FilterDsl;
8186
use diesel::query_dsl::methods::{LimitDsl, OffsetDsl, SelectDsl};
8287
use diesel::r2d2;
88+
use diesel::sql_types::{Bool, HasSqlType};
89+
use diesel::BoxableExpression;
8390
use diesel::EqAll;
8491
use diesel::Identifiable;
8592
use diesel::QuerySource;
8693
use diesel::{AppearsOnTable, Connection, QueryDsl, Table};
8794
use failure::Error;
95+
use juniper::LookAheadValue;
8896
use juniper::{Executor, LookAheadSelection, Selection};
8997

9098
pub trait WundergraphContext {
@@ -161,18 +169,6 @@ where
161169
}
162170
}
163171

164-
use crate::diesel_ext::BoxableFilter;
165-
use crate::filter::build_filter::BuildFilter;
166-
use crate::filter::inner_filter::InnerFilter;
167-
use crate::filter::Filter;
168-
use crate::query_helper::order::BuildOrder;
169-
use crate::query_helper::select::BuildSelect;
170-
use crate::query_helper::tuple::IsPrimaryKeyIndex;
171-
use diesel::query_dsl::methods::FilterDsl;
172-
use diesel::sql_types::{Bool, HasSqlType};
173-
use diesel::BoxableExpression;
174-
use juniper::LookAheadValue;
175-
176172
pub trait LoadingHandler<DB, Ctx>: HasTable + Sized
177173
where
178174
DB: Backend + ApplyOffset + 'static,

0 commit comments

Comments
 (0)