Skip to content

Commit 488e1b8

Browse files
committed
Write documentation + small API fixes
1 parent a87df35 commit 488e1b8

Some content is hidden

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

83 files changed

+25727
-24208
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
**/target/
33
**/*.rs.bk
44
Cargo.lock
5-
*~

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Wundergraph provides a platform to easily expose your database through a GraphQL
1212
For a full example application see the [example project](https://github.com/weiznich/wundergraph/tree/master/wundergraph_example/src/main.rs)
1313

1414
```rust
15+
#[macro_use] extern crate diesel;
16+
use wundergraph::prelude::*;
1517

1618
table! {
1719
heros {
@@ -29,34 +31,29 @@ table! {
2931
}
3032
}
3133

32-
#[derive(Clone, Debug, Identifiable, Hash, Eq, PartialEq, Queryable, WundergraphEntity,
33-
WundergraphFilter, Associations)]
34+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
3435
#[table_name = "heros"]
35-
#[belongs_to(Species, foreign_key = "species)]
3636
pub struct Hero {
3737
id: i32,
3838
name: String,
3939
hair_color: Option<String>,
4040
species: HasOne<i32, Species>,
4141
}
4242

43-
#[derive(Clone, Debug, Identifiable, Hash, Eq, PartialEq, Queryable, WundergraphEntity,
44-
WundergraphFilter)]
43+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
4544
#[table_name = "species"]
4645
pub struct Species {
4746
id: i32,
4847
name: String,
49-
#[diesel(default)]
50-
heros: HasMany<Hero>,
48+
heros: HasMany<Hero, heros::species>,
5149
}
5250

53-
wundergraph_query_object!{
51+
wundergraph::query_object!{
5452
Query {
55-
Heros(Hero, filter = HeroFilter),
56-
Species(Species, filter = SpeciesFilter),
57-
}
53+
Hero,
54+
Species,
55+
}
5856
}
59-
6057
```
6158

6259
## License

clippy.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
cyclomatic-complexity-threshold = 30
1+
cognitive-complexity-threshold = 30
22
doc-valid-idents = [
33
"MiB", "GiB", "TiB", "PiB", "EiB",
44
"DirectX", "OpenGL", "TrueType",
55
"GPLv2", "GPLv3",
66
"GitHub",
77
"IPv4", "IPv6",
88
"JavaScript", "NaN", "OAuth",
9-
"SQLite", "PostgreSQL", "MySQL"
9+
"SQLite", "PostgreSQL", "MySQL",
10+
"GraphQL"
1011
]

rust-toolchain

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

wundergraph/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ description = "A GraphQL ORM build on top of diesel"
1414
[dependencies]
1515
serde = "1"
1616
diesel = { version = "1.4", features = ["r2d2"]}
17-
juniper = "0.12"
17+
juniper = "0.14"
1818
indexmap = "1"
1919
wundergraph_derive = { path = "../wundergraph_derive" }
2020
uuid_internal = { version = "0.7", optional = true, package = "uuid" }
2121
chrono_internal = { version = "0.4", optional = true, package = "chrono" }
22-
failure = "0.1"
23-
log = "0.4"
22+
log = { version = "0.4", optional = true }
2423
paste = "0.1"
24+
thiserror = "1"
2525

2626
[dev-dependencies]
2727
wundergraph_example = { path = "../wundergraph_example", default-features = false }
2828
wundergraph_bench = { path = "../wundergraph_bench", default-features = false }
2929
diesel_migrations = "1.4.0"
3030
serde_json = "1"
31-
criterion = "0.2"
31+
criterion = "0.3"
3232
lazy_static = "1"
33-
insta = "0.8"
33+
insta = "0.12"
3434

3535
[features]
36-
default = ["postgres", "extras"]
37-
debug = ["wundergraph_derive/debug"]
36+
default = []
37+
debug = ["wundergraph_derive/debug", "log"]
3838
sqlite = ["diesel/sqlite", "wundergraph_derive/sqlite"]
3939
postgres = ["diesel/postgres", "wundergraph_derive/postgres"]
40-
extras = ["chrono", "uuid"]
40+
extras = ["uuid", "chrono"]
4141
uuid = ["uuid_internal", "diesel/uuidv07"]
4242
chrono = ["chrono_internal", "diesel/chrono"]
4343

wundergraph/bench/queries.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use wundergraph_bench::Schema;
2828
const QUERIES: &[&str] = &[
2929
r#"query albums_tracks_genre_all {
3030
Albums {
31-
id
31+
album_id
3232
title
3333
tracks {
34-
id
34+
track_id
3535
name
3636
genre_id {
3737
name
@@ -40,11 +40,11 @@ const QUERIES: &[&str] = &[
4040
}
4141
}"#,
4242
r#"query albums_tracks_genre_some {
43-
Albums(filter: {artist_id: {id: {eq: 127}}}) {
44-
id
43+
Albums(filter: {artist_id: {artist_id: {eq: 127}}}) {
44+
album_id
4545
title
4646
tracks {
47-
id
47+
track_id
4848
name
4949
genre_id {
5050
name
@@ -54,7 +54,7 @@ const QUERIES: &[&str] = &[
5454
}"#,
5555
r#"query tracks_media_all {
5656
Tracks {
57-
id
57+
track_id
5858
name
5959
media_type_id {
6060
name
@@ -63,10 +63,10 @@ const QUERIES: &[&str] = &[
6363
}"#,
6464
r#"query tracks_media_some {
6565
Tracks (filter: {composer: {eq: "Kurt Cobain"}}){
66-
id
66+
track_id
6767
name
6868
album_id {
69-
id
69+
album_id
7070
title
7171
}
7272
media_type_id {
@@ -77,13 +77,13 @@ const QUERIES: &[&str] = &[
7777
r#"query artists_collaboration {
7878
Artists(filter: {albums: {tracks: {composer: {eq: "Ludwig van Beethoven"}}}})
7979
{
80-
id
80+
artist_id
8181
name
8282
}
8383
}"#,
8484
r#"query artistByArtistId {
85-
Artists(filter: {id: {eq:3}}) {
86-
id
85+
Artists(filter: {artist_id: {eq:3}}) {
86+
artist_id
8787
name
8888
}
8989
}"#,
@@ -95,7 +95,6 @@ fn query(
9595
ctx: &PooledConnection<ConnectionManager<DbConnection>>,
9696
) {
9797
let res = helper::execute_query(&schema, &ctx, query);
98-
9998
assert!(res.is_ok());
10099
}
101100

wundergraph/src/context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
use diesel::{r2d2, Connection};
1+
use diesel::Connection;
22

3+
/// A trait for types that could be used as context types for wundergraph
34
pub trait WundergraphContext {
5+
6+
/// The underlying connection type
47
type Connection: Connection + 'static;
8+
9+
/// Get a connection from the context
510
fn get_connection(&self) -> &Self::Connection;
611
}
712

8-
impl<Conn> WundergraphContext for r2d2::PooledConnection<r2d2::ConnectionManager<Conn>>
13+
impl<Conn> WundergraphContext for Conn
914
where
1015
Conn: Connection + 'static,
11-
Self: Connection<Backend = Conn::Backend>,
1216
{
1317
type Connection = Self;
1418

wundergraph/src/diesel_ext.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
//! A module containing extension traits for various diesel types
12
23
use diesel::backend::Backend;
34
use diesel::expression::{AppearsOnTable, Expression, NonAggregate, SelectableExpression};
45
use diesel::query_builder::{AstPass, QueryFragment, QueryId};
56
use diesel::result::QueryResult;
67
use diesel::sql_types::IntoNullable;
78

9+
/// A helper trait used when boxing filters
10+
///
11+
/// In Rust you cannot create a trait object with more than one trait.
12+
/// This type has all of the additional traits you would want when using
13+
/// `Box<Expression>` as a single trait object. This type is comparable to
14+
/// diesels `BoxableExpression`, but allows to use non select able expressions,
15+
/// which is mainly useful for constructing filters.
16+
///
17+
/// This is typically used as the return type of a function or as associated
18+
/// types in traits.
819
pub trait BoxableFilter<QS, DB>
920
where
1021
DB: Backend,
@@ -25,9 +36,12 @@ where
2536
{
2637
}
2738

39+
/// A diesel helper type that indicates if null or some expression selected
2840
#[derive(Debug)]
2941
pub enum MaybeNull<T> {
42+
/// Select the expression
3043
Expr(T),
44+
/// Select a null value
3145
Null,
3246
}
3347

wundergraph/src/error.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
//! This module contains all error handling related functionality in wundergraph
22
33
use crate::scalar::WundergraphScalarValue;
4+
use thiserror::Error;
45

56
/// The main error type of wundergraph
6-
#[derive(Debug, Fail)]
7+
#[derive(Debug, Error)]
78
pub enum WundergraphError {
89
/// Indicates that it was not possible to build a filter from the given
910
/// graphql arguments
10-
#[fail(display = "Could not build filter from arguments")]
11+
#[error("Could not build filter from arguments")]
1112
CouldNotBuildFilterArgument,
1213
/// Indicates that a unknown database field name was passed into
1314
/// wundergraph
14-
#[fail(display = "Requested unkown field {}", name)]
15+
#[error("Requested unkown field {name}")]
1516
UnknownDatabaseField {
1617
///The name of the unknown database field
1718
name: String,
1819
},
19-
#[fail(display = "Could not build primary key filter from arguments")]
20+
/// Indicates that a primary key filter could not be build from the
21+
/// given arguments
22+
#[error("Could not build primary key filter from arguments")]
2023
NoPrimaryKeyArgumentFound,
21-
#[fail(display = "Failed to build a return value")]
24+
/// Indicates that building a graphql return value failed
25+
#[error("Failed to build a return value")]
2226
JuniperError {
27+
/// Error returned from juniper
2328
inner: juniper::FieldError<WundergraphScalarValue>,
2429
},
30+
/// Indicates that executing a database query failed
31+
#[error("Failed to execute query")]
32+
DieselError {
33+
/// Error returned from diesel
34+
#[from]
35+
inner: diesel::result::Error,
36+
},
2537
}
38+
39+
/// Commonly used result type
40+
pub type Result<T> = std::result::Result<T, WundergraphError>;

wundergraph/src/graphql_type.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use diesel::QuerySource;
77
use juniper::{meta, GraphQLType, Registry};
88
use std::marker::PhantomData;
99

10+
/// A helper type to automatically provide `juniper::GraphQLObject` implementation
11+
/// for types that also implement `LoadingHandler`
1012
#[derive(Debug)]
1113
pub struct GraphqlWrapper<T, DB, Ctx>(T, PhantomData<(DB, Ctx)>);
1214

@@ -40,6 +42,7 @@ where
4042
}
4143
}
4244

45+
#[doc(hidden)]
4346
pub trait WundergraphGraphqlMapper<DB, Ctx> {
4447
type GraphQLType: GraphQLType<WundergraphScalarValue, TypeInfo = ()>;
4548

@@ -58,6 +61,7 @@ where
5861
type GraphQLType = Self;
5962
}
6063

64+
#[doc(hidden)]
6165
pub trait WundergraphGraphqlHelper<L, DB, Ctx> {
6266
fn object_meta<'r, T>(
6367
names: &[&str],
@@ -105,7 +109,7 @@ macro_rules! wundergraph_graphql_helper_impl {
105109
&(),
106110
&fields,
107111
);
108-
if let Some(doc) = Loading::type_description() {
112+
if let Some(doc) = Loading::TYPE_DESCRIPTION {
109113
ty = ty.description(doc);
110114
}
111115
meta::MetaType::Object(ty)

0 commit comments

Comments
 (0)