Skip to content

Commit a5ab663

Browse files
committed
Cargo fix + cargo clippy for wundergraph_example
1 parent 60181dd commit a5ab663

File tree

4 files changed

+91
-122
lines changed

4 files changed

+91
-122
lines changed

wundergraph_example/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readme = "../README.md"
99
keywords = ["GraphQL", "ORM", "PostgreSQL", "SQLite"]
1010
categories = ["database", "web-programming"]
1111
description = "A GraphQL ORM build on top of diesel"
12+
edition = "2018"
1213

1314
[dependencies]
1415
diesel = { version = "1.4.0", features = ["r2d2", "sqlite", "chrono", "postgres"]}

wundergraph_example/src/bin/main.rs

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,42 @@
11
#![deny(missing_debug_implementations, missing_copy_implementations)]
2-
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
3-
#![cfg_attr(feature = "cargo-clippy", warn(clippy))]
4-
// Clippy lints
5-
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
6-
#![cfg_attr(
7-
feature = "cargo-clippy",
8-
warn(
9-
wrong_pub_self_convention,
10-
used_underscore_binding,
11-
use_self,
12-
use_debug,
13-
unseparated_literal_suffix,
14-
unnecessary_unwrap,
15-
unimplemented,
16-
single_match_else,
17-
shadow_unrelated,
18-
option_map_unwrap_or_else,
19-
option_map_unwrap_or,
20-
needless_continue,
21-
mutex_integer,
22-
needless_borrow,
23-
items_after_statements,
24-
filter_map,
25-
expl_impl_clone_on_copy,
26-
else_if_without_else,
27-
doc_markdown,
28-
default_trait_access,
29-
option_unwrap_used,
30-
result_unwrap_used,
31-
wrong_pub_self_convention,
32-
mut_mut,
33-
non_ascii_literal,
34-
similar_names,
35-
unicode_not_nfc,
36-
enum_glob_use,
37-
if_not_else,
38-
items_after_statements,
39-
used_underscore_binding
40-
)
2+
#![warn(
3+
clippy::option_unwrap_used,
4+
clippy::result_unwrap_used,
5+
clippy::print_stdout,
6+
clippy::wrong_pub_self_convention,
7+
clippy::mut_mut,
8+
clippy::non_ascii_literal,
9+
clippy::similar_names,
10+
clippy::unicode_not_nfc,
11+
clippy::enum_glob_use,
12+
clippy::if_not_else,
13+
clippy::items_after_statements,
14+
clippy::used_underscore_binding,
15+
clippy::cargo_common_metadata,
16+
clippy::dbg_macro,
17+
clippy::doc_markdown,
18+
clippy::filter_map,
19+
clippy::map_flatten,
20+
clippy::match_same_arms,
21+
clippy::needless_borrow,
22+
clippy::needless_pass_by_value,
23+
clippy::option_map_unwrap_or,
24+
clippy::option_map_unwrap_or_else,
25+
clippy::redundant_clone,
26+
clippy::result_map_unwrap_or_else,
27+
clippy::unnecessary_unwrap,
28+
clippy::unseparated_literal_suffix,
29+
clippy::wildcard_dependencies
4130
)]
4231

43-
extern crate actix;
44-
extern crate actix_web;
45-
extern crate diesel;
46-
extern crate diesel_migrations;
47-
extern crate failure;
48-
extern crate juniper;
49-
extern crate wundergraph;
32+
use actix;
33+
5034
#[macro_use]
5135
extern crate serde;
52-
extern crate env_logger;
53-
extern crate futures;
54-
extern crate serde_json;
55-
extern crate structopt;
56-
extern crate wundergraph_example;
36+
use env_logger;
37+
38+
use serde_json;
39+
use structopt;
5740

5841
use actix::prelude::*;
5942
use actix_web::{
@@ -147,6 +130,7 @@ fn graphql((st, data): (State<AppState>, Json<GraphQLData>)) -> FutureResponse<H
147130
.responder()
148131
}
149132

133+
#[allow(clippy::print_stdout)]
150134
fn main() {
151135
let opt = Opt::from_args();
152136
::std::env::set_var("RUST_LOG", "actix_web=info");
@@ -156,8 +140,8 @@ fn main() {
156140
.max_size(1)
157141
.build(manager)
158142
.expect("Failed to init pool");
159-
// ::diesel_migrations::run_pending_migrations(&pool.get().expect("Failed to get db connection"))
160-
// .expect("Failed to run migrations");
143+
::diesel_migrations::run_pending_migrations(&pool.get().expect("Failed to get db connection"))
144+
.expect("Failed to run migrations");
161145

162146
let query = Query::<MyContext<DBConnection>>::default();
163147
// let mutation = juniper::EmptyMutation::new();

wundergraph_example/src/lib.rs

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,41 @@
1-
#![feature(trace_macros)]
21
#![deny(missing_debug_implementations, missing_copy_implementations)]
3-
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
4-
#![cfg_attr(feature = "cargo-clippy", warn(clippy))]
5-
// Clippy lints
6-
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
7-
#![cfg_attr(
8-
feature = "cargo-clippy",
9-
warn(
10-
wrong_pub_self_convention,
11-
used_underscore_binding,
12-
use_self,
13-
use_debug,
14-
unseparated_literal_suffix,
15-
unnecessary_unwrap,
16-
unimplemented,
17-
single_match_else,
18-
shadow_unrelated,
19-
option_map_unwrap_or_else,
20-
option_map_unwrap_or,
21-
needless_continue,
22-
mutex_integer,
23-
needless_borrow,
24-
items_after_statements,
25-
filter_map,
26-
expl_impl_clone_on_copy,
27-
else_if_without_else,
28-
doc_markdown,
29-
default_trait_access,
30-
option_unwrap_used,
31-
result_unwrap_used,
32-
print_stdout,
33-
wrong_pub_self_convention,
34-
mut_mut,
35-
non_ascii_literal,
36-
similar_names,
37-
unicode_not_nfc,
38-
enum_glob_use,
39-
if_not_else,
40-
items_after_statements,
41-
used_underscore_binding
42-
)
2+
#![warn(
3+
clippy::option_unwrap_used,
4+
clippy::result_unwrap_used,
5+
clippy::print_stdout,
6+
clippy::wrong_pub_self_convention,
7+
clippy::mut_mut,
8+
clippy::non_ascii_literal,
9+
clippy::similar_names,
10+
clippy::unicode_not_nfc,
11+
clippy::enum_glob_use,
12+
clippy::if_not_else,
13+
clippy::items_after_statements,
14+
clippy::used_underscore_binding,
15+
clippy::cargo_common_metadata,
16+
clippy::dbg_macro,
17+
clippy::doc_markdown,
18+
clippy::filter_map,
19+
clippy::map_flatten,
20+
clippy::match_same_arms,
21+
clippy::needless_borrow,
22+
clippy::needless_pass_by_value,
23+
clippy::option_map_unwrap_or,
24+
clippy::option_map_unwrap_or_else,
25+
clippy::redundant_clone,
26+
clippy::result_map_unwrap_or_else,
27+
clippy::unnecessary_unwrap,
28+
clippy::unseparated_literal_suffix,
29+
clippy::wildcard_dependencies
30+
4331
)]
4432

4533
#[macro_use]
4634
extern crate diesel;
4735
#[macro_use]
4836
extern crate juniper;
49-
extern crate failure;
50-
extern crate indexmap;
51-
extern crate wundergraph;
37+
38+
use wundergraph;
5239

5340
use diesel::backend::Backend;
5441
use diesel::deserialize::{self, FromSql};
@@ -62,13 +49,13 @@ use std::io::Write;
6249
use wundergraph::query_helper::{HasMany, HasOne};
6350
use wundergraph::scalar::WundergraphScalarValue;
6451
use wundergraph::WundergraphContext;
65-
use wundergraph::{BoxedQuery, LoadingHandler, QueryModifier, ApplyOffset};
52+
use wundergraph::{ApplyOffset, BoxedQuery, LoadingHandler, QueryModifier};
6653
use wundergraph::{WundergraphEntity, WundergraphValue};
6754

6855
pub mod mutations;
6956
use self::mutations::*;
7057

71-
#[derive(Debug, Copy, Clone, AsExpression, FromSqlRow, GraphQLEnum, WundergraphValue)]
58+
#[derive(Debug, Copy, Clone, AsExpression, FromSqlRow, GraphQLEnum, WundergraphValue, Eq, PartialEq, Hash)]
7259
#[sql_type = "SmallInt"]
7360
pub enum Episode {
7461
NEWHOPE = 1,
@@ -81,7 +68,7 @@ where
8168
DB: Backend,
8269
i16: ToSql<SmallInt, DB>,
8370
{
84-
fn to_sql<W: Write>(&self, out: &mut serialize::Output<W, DB>) -> serialize::Result {
71+
fn to_sql<W: Write>(&self, out: &mut serialize::Output<'_, W, DB>) -> serialize::Result {
8572
(*self as i16).to_sql(out)
8673
}
8774
}
@@ -141,7 +128,7 @@ table! {
141128
}
142129

143130
#[derive(Clone, Debug, Identifiable, Queryable, WundergraphEntity)]
144-
#[primary_key(hero_id)]
131+
#[primary_key(hero_id, episode)]
145132
#[table_name = "appears_in"]
146133
pub struct AppearsIn {
147134
hero_id: HasOne<i32, Hero>,
@@ -150,7 +137,7 @@ pub struct AppearsIn {
150137

151138
#[derive(Clone, Debug, Queryable, Eq, PartialEq, Hash, WundergraphEntity, Identifiable)]
152139
#[table_name = "friends"]
153-
#[primary_key(hero_id)]
140+
#[primary_key(hero_id, friend_id)]
154141
pub struct Friend {
155142
#[wundergraph(skip)]
156143
hero_id: i32,
@@ -210,9 +197,13 @@ pub struct Species {
210197
}
211198

212199
wundergraph::query_object! {
200+
/// Global query object for the schema
213201
Query {
202+
/// Access to Heros
214203
Hero,
204+
/// Access to Species
215205
Species,
206+
/// Access to HomeWorlds
216207
HomeWorld,
217208
}
218209
}
@@ -247,9 +238,8 @@ where
247238
_select: &LookAheadSelection<'_, WundergraphScalarValue>,
248239
query: BoxedQuery<'a, T, DB, Self>,
249240
) -> Result<BoxedQuery<'a, T, DB, Self>, Error> {
250-
dbg!(T::TYPE_NAME);
251241
match T::TYPE_NAME {
252-
// "Heros" => Err(Error::from_boxed_compat(String::from("Is user").into())),
242+
// "Heros" => Err(Error::from_boxed_compat(String::from("Is user").into())),
253243
_ => Ok(query),
254244
}
255245
}

wundergraph_example/src/mutations.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
use super::appears_in;
2-
//use super::friends;
2+
use super::friends;
33
use super::heros;
44
use super::home_worlds;
55
use super::species;
6-
//use super::AppearsIn;
6+
use super::AppearsIn;
77
use super::Episode;
8-
//use super::Friend;
9-
//use super::DBConnection;
8+
use super::Friend;
109
use super::Hero;
1110
use super::HomeWorld;
12-
//use super::MyContext;
1311
use super::Species;
14-
//use diesel::sqlite::Sqlite;
1512
use juniper::*;
16-
//use wundergraph::scalar::WundergraphScalarValue;
1713

1814
#[derive(Insertable, GraphQLInputObject, Clone, Debug)]
1915
#[table_name = "heros"]
@@ -60,12 +56,12 @@ pub struct HomeWorldChangeset {
6056
name: Option<String>,
6157
}
6258

63-
// #[derive(Insertable, GraphQLInputObject, Debug, Copy, Clone)]
64-
// #[table_name = "friends"]
65-
// pub struct NewFriend {
66-
// hero_id: i32,
67-
// friend_id: i32,
68-
// }
59+
#[derive(Insertable, GraphQLInputObject, Debug, Copy, Clone)]
60+
#[table_name = "friends"]
61+
pub struct NewFriend {
62+
hero_id: i32,
63+
friend_id: i32,
64+
}
6965

7066
#[derive(Insertable, GraphQLInputObject, Debug, Copy, Clone)]
7167
#[table_name = "appears_in"]
@@ -74,15 +70,13 @@ pub struct NewAppearsIn {
7470
episode: Episode,
7571
}
7672

77-
//trace_macros!(true);
7873
wundergraph::mutation_object! {
79-
/// Mutations docs
74+
/// Global mutation object for the schema
8075
Mutation {
8176
Hero(insert = NewHero, update = HeroChangeset,),
8277
Species(insert = NewSpecies, update = SpeciesChangeset,),
8378
HomeWorld(insert = NewHomeWorld, update = HomeWorldChangeset,),
84-
// Friend( insert = NewFriend,),
85-
// AppearsIn(insert = NewAppearsIn,),
79+
Friend( insert = NewFriend,),
80+
AppearsIn(insert = NewAppearsIn,),
8681
}
8782
}
88-
trace_macros!(false);

0 commit comments

Comments
 (0)