Skip to content

Commit 8107f3a

Browse files
committed
Refactor everything to a more modular structure
Moving all pieces into a more sensible module structure
1 parent 87a45c5 commit 8107f3a

File tree

122 files changed

+7522
-2746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+7522
-2746
lines changed

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2019-03-06
1+
nightly-2019-05-31

wundergraph/src/context.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use diesel::{r2d2, Connection};
2+
3+
pub trait WundergraphContext {
4+
type Connection: Connection + 'static;
5+
fn get_connection(&self) -> &Self::Connection;
6+
}
7+
8+
impl<Conn> WundergraphContext for r2d2::PooledConnection<r2d2::ConnectionManager<Conn>>
9+
where
10+
Conn: Connection + 'static,
11+
Self: Connection<Backend = Conn::Backend>,
12+
{
13+
type Connection = Self;
14+
15+
fn get_connection(&self) -> &Self {
16+
self
17+
}
18+
}

wundergraph/src/diesel_ext.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
use diesel::backend::Backend;
2-
use diesel::expression::NonAggregate;
3-
use diesel::query_builder::QueryFragment;
4-
use diesel::{AppearsOnTable, Expression};
3+
use diesel::expression::{AppearsOnTable, Expression, NonAggregate, SelectableExpression};
4+
use diesel::query_builder::{AstPass, QueryFragment, QueryId};
5+
use diesel::result::QueryResult;
6+
use diesel::sql_types::IntoNullable;
57

68
pub trait BoxableFilter<QS, DB>
79
where
@@ -22,3 +24,45 @@ where
2224
T: QueryFragment<DB>,
2325
{
2426
}
27+
28+
#[derive(Debug)]
29+
pub enum MaybeNull<T> {
30+
Expr(T),
31+
Null,
32+
}
33+
34+
impl<T> Expression for MaybeNull<T>
35+
where
36+
T: Expression,
37+
T::SqlType: IntoNullable,
38+
{
39+
type SqlType = <T::SqlType as IntoNullable>::Nullable;
40+
}
41+
42+
impl<T, DB> QueryFragment<DB> for MaybeNull<T>
43+
where
44+
DB: Backend,
45+
T: QueryFragment<DB>,
46+
{
47+
fn walk_ast(&self, mut pass: AstPass<'_, DB>) -> QueryResult<()> {
48+
match self {
49+
MaybeNull::Expr(e) => e.walk_ast(pass)?,
50+
MaybeNull::Null => pass.push_sql(" NULL "),
51+
}
52+
Ok(())
53+
}
54+
}
55+
56+
impl<ST> QueryId for MaybeNull<ST>
57+
where
58+
ST: QueryId,
59+
{
60+
type QueryId = ();
61+
const HAS_STATIC_QUERY_ID: bool = false;
62+
}
63+
64+
impl<T> NonAggregate for MaybeNull<T> {}
65+
66+
impl<T, QS> AppearsOnTable<QS> for MaybeNull<T> where Self: Expression {}
67+
68+
impl<T, ST> SelectableExpression<T> for MaybeNull<ST> where Self: Expression {}

wundergraph/src/graphql_type.rs

Lines changed: 3 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
use crate::query_helper::placeholder::FieldListExtractor;
1+
use crate::query_builder::selection::offset::ApplyOffset;
2+
use crate::query_builder::selection::LoadingHandler;
23
use crate::scalar::WundergraphScalarValue;
3-
use crate::{LoadingHandler, ApplyOffset};
44
use diesel::backend::Backend;
55
use diesel::query_builder::QueryFragment;
66
use diesel::QuerySource;
7-
use juniper::{meta, FromInputValue, GraphQLType, Registry};
7+
use juniper::{meta, GraphQLType, Registry};
88
use std::marker::PhantomData;
99

1010
#[derive(Debug)]
1111
pub struct GraphqlWrapper<T, DB, Ctx>(T, PhantomData<(DB, Ctx)>);
1212

13-
#[derive(Debug)]
14-
pub struct GraphqlOrderWrapper<T, DB, Ctx>(PhantomData<(T, DB, Ctx)>);
15-
1613
impl<T, DB, Ctx> GraphQLType<WundergraphScalarValue> for GraphqlWrapper<T, DB, Ctx>
1714
where
1815
DB: Backend + ApplyOffset + 'static,
@@ -43,68 +40,6 @@ where
4340
}
4441
}
4542

46-
#[derive(Debug)]
47-
pub struct OrderTypeInfo<L, DB, Ctx>(String, PhantomData<(L, DB, Ctx)>);
48-
49-
impl<L, DB, Ctx> Default for OrderTypeInfo<L, DB, Ctx>
50-
where
51-
DB: Backend + ApplyOffset + 'static,
52-
L::Table: 'static,
53-
<L::Table as QuerySource>::FromClause: QueryFragment<DB>,
54-
L: LoadingHandler<DB, Ctx>,
55-
DB::QueryBuilder: Default,
56-
{
57-
fn default() -> Self {
58-
Self(format!("{}Columns", L::TYPE_NAME), PhantomData)
59-
}
60-
}
61-
62-
impl<T, DB, Ctx> GraphQLType<WundergraphScalarValue> for GraphqlOrderWrapper<T, DB, Ctx>
63-
where
64-
DB: Backend + ApplyOffset + 'static,
65-
T::Table: 'static,
66-
<T::Table as QuerySource>::FromClause: QueryFragment<DB>,
67-
T: LoadingHandler<DB, Ctx>,
68-
T::FieldList: FieldListExtractor,
69-
<T::FieldList as FieldListExtractor>::Out: WundergraphGraphqlHelper<T, DB, Ctx>,
70-
DB::QueryBuilder: Default,
71-
{
72-
type Context = ();
73-
type TypeInfo = OrderTypeInfo<T, DB, Ctx>;
74-
75-
fn name(info: &Self::TypeInfo) -> Option<&str> {
76-
Some(&info.0)
77-
}
78-
79-
fn meta<'r>(
80-
info: &Self::TypeInfo,
81-
registry: &mut Registry<'r, WundergraphScalarValue>,
82-
) -> meta::MetaType<'r, WundergraphScalarValue>
83-
where
84-
WundergraphScalarValue: 'r,
85-
{
86-
use crate::query_helper::placeholder::WundergraphFieldList;
87-
88-
<<T::FieldList as FieldListExtractor>::Out as WundergraphGraphqlHelper<T, DB, Ctx>>::order_meta::<
89-
Self,
90-
_,
91-
>(
92-
info,
93-
|index| {
94-
T::FieldList::map_table_field(index, |index| T::FIELD_NAMES[index])
95-
.expect("Field is there")
96-
},
97-
registry,
98-
)
99-
}
100-
}
101-
102-
impl<T, DB, Ctx> FromInputValue<WundergraphScalarValue> for GraphqlOrderWrapper<T, DB, Ctx> {
103-
fn from_input_value(_: &juniper::InputValue<WundergraphScalarValue>) -> Option<Self> {
104-
Some(Self(PhantomData))
105-
}
106-
}
107-
10843
pub trait WundergraphGraphqlMapper<DB, Ctx> {
10944
type GraphQLType: GraphQLType<WundergraphScalarValue, TypeInfo = ()>;
11045

@@ -130,15 +65,6 @@ pub trait WundergraphGraphqlHelper<L, DB, Ctx> {
13065
) -> meta::MetaType<'r, WundergraphScalarValue>
13166
where
13267
T: GraphQLType<WundergraphScalarValue, TypeInfo = ()>;
133-
134-
fn order_meta<'r, T, F>(
135-
info: &T::TypeInfo,
136-
name: F,
137-
registry: &mut Registry<'r, WundergraphScalarValue>,
138-
) -> meta::MetaType<'r, WundergraphScalarValue>
139-
where
140-
T: GraphQLType<WundergraphScalarValue> + FromInputValue<WundergraphScalarValue>,
141-
F: Fn(usize) -> &'static str;
14268
}
14369

14470
macro_rules! wundergraph_graphql_helper_impl {
@@ -184,28 +110,6 @@ macro_rules! wundergraph_graphql_helper_impl {
184110
}
185111
meta::MetaType::Object(ty)
186112
}
187-
188-
fn order_meta<'r, Type, Fun>(
189-
info: &Type::TypeInfo,
190-
names: Fun,
191-
registry: &mut Registry<'r, WundergraphScalarValue>,
192-
) -> meta::MetaType<'r, WundergraphScalarValue>
193-
where
194-
Type: GraphQLType<WundergraphScalarValue> + FromInputValue<WundergraphScalarValue>,
195-
Fun: Fn(usize) -> &'static str,
196-
{
197-
use juniper::meta::EnumValue;
198-
let values = [
199-
$(
200-
EnumValue::new(names($idx)),
201-
)*
202-
];
203-
let e = registry.build_enum_type::<Type>(
204-
info,
205-
&values,
206-
);
207-
meta::MetaType::Enum(e)
208-
}
209113
}
210114
)*
211115
};

wundergraph/src/helper/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
//! Some helper functionality used to implement wundergraph
2-
//!
3-
//! Functionality from this module is only useful if you want to extend
4-
//! wundergraph to support additional types
5-
mod from_lookahead;
6-
mod nameable;
7-
#[doc(hidden)]
81
pub mod primary_keys;
9-
10-
pub use self::from_lookahead::FromLookAheadValue;
11-
pub use self::nameable::{NameBuilder, Nameable};
2+
pub mod tuple;

wundergraph/src/helper/primary_keys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::FromLookAheadValue;
1+
use crate::juniper_ext::FromLookAheadValue;
22
use crate::scalar::WundergraphScalarValue;
33
use diesel::associations::HasTable;
44
use diesel::query_builder::nodes::Identifier;

0 commit comments

Comments
 (0)