Clippy cleanup (#579)

This commit is contained in:
Gero Posmyk-Leinemann 2020-03-20 17:11:06 +01:00 committed by GitHub
parent a275c8dcc2
commit 5f777e8a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 119 additions and 68 deletions

View file

@ -1,4 +1,5 @@
#[macro_use] extern crate bencher;
#[macro_use]
extern crate bencher;
extern crate juniper;
use bencher::Bencher;

View file

@ -144,9 +144,7 @@ async fn main() {
let homepage = warp::path::end().map(|| {
Response::builder()
.header("content-type", "text/html")
.body(format!(
"<html><h1>juniper_subscriptions demo</h1><div>visit <a href=\"/playground\">graphql playground</a></html>"
))
.body("<html><h1>juniper_subscriptions demo</h1><div>visit <a href=\"/playground\">graphql playground</a></html>".to_string())
});
let qm_schema = schema();

View file

@ -9,6 +9,7 @@ enum UserKind {
}
struct User {
#[allow(dead_code)]
id: i32,
name: String,
kind: UserKind,

View file

@ -4,8 +4,6 @@ use fnv::FnvHashMap;
#[cfg(test)]
use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
use futures;
#[derive(juniper::GraphQLEnum, Debug, PartialEq)]
#[graphql(name = "Some", description = "enum descr")]
enum SomeEnum {

View file

@ -9,8 +9,6 @@ use juniper::{
self, execute, EmptyMutation, EmptySubscription, GraphQLType, RootNode, Value, Variables,
};
use futures;
#[derive(GraphQLObject, Debug, PartialEq)]
#[graphql(
name = "MyObj",
@ -333,7 +331,7 @@ async fn check_descriptions(
"#,
object_name
);
run_type_info_query(&doc, |(type_info, values)| {
let _result = run_type_info_query(&doc, |(type_info, values)| {
assert_eq!(
type_info.get_field_value("name"),
Some(&Value::scalar(object_name))

View file

@ -4,8 +4,6 @@ use juniper::{
Value, Variables,
};
use futures;
pub struct Query;
#[juniper::graphql_object]

View file

@ -1,5 +1,3 @@
use futures;
// Trait.
#[derive(juniper::GraphQLObject)]

View file

@ -1,5 +1,4 @@
use fnv::FnvHashMap;
use futures;
use juniper::{DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
#[derive(juniper::GraphQLScalarValue, PartialEq, Eq, Debug)]

View file

@ -1,7 +1,5 @@
extern crate serde_json;
use futures;
use juniper::{
execute,
parser::{ParseError, ScalarToken, Spanning, Token},

View file

@ -1,8 +1,6 @@
// Original author of this test is <https://github.com/davidpdrsn>.
use juniper::*;
use futures;
pub struct Context;
impl juniper::Context for Context {}

View file

@ -1,8 +1,6 @@
// Original author of this test is <https://github.com/davidpdrsn>.
use juniper::*;
use futures;
struct Query;
#[juniper::graphql_object]

View file

@ -4,11 +4,23 @@ extern crate juniper;
use bencher::Bencher;
use juniper::{execute_sync, tests::model::Database, EmptyMutation, RootNode, Variables};
use juniper::{
execute_sync, tests::model::Database, DefaultScalarValue, EmptyMutation, EmptySubscription,
RootNode, Variables,
};
fn query_type_name(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
let schema: RootNode<
&Database,
EmptyMutation<Database>,
EmptySubscription<Database>,
DefaultScalarValue,
> = RootNode::new(
&database,
EmptyMutation::<Database>::new(),
EmptySubscription::<Database>::new(),
);
let doc = r#"
query IntrospectionQueryTypeQuery {
@ -24,7 +36,16 @@ fn query_type_name(b: &mut Bencher) {
fn introspection_query(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
let schema: RootNode<
&Database,
EmptyMutation<Database>,
EmptySubscription<Database>,
DefaultScalarValue,
> = RootNode::new(
&database,
EmptyMutation::<Database>::new(),
EmptySubscription::<Database>::new(),
);
let doc = r#"
query IntrospectionQuery {

View file

@ -8,6 +8,7 @@ enum UserKind {
}
struct User {
#[allow(dead_code)]
id: i32,
name: String,
kind: UserKind,
@ -24,14 +25,13 @@ impl User {
}
async fn friends(&self) -> Vec<User> {
let friends = (0..10)
(0..10)
.map(|index| User {
id: index,
name: format!("user{}", index),
kind: UserKind::User,
})
.collect();
friends
.collect()
}
async fn kind(&self) -> &UserKind {

View file

@ -13,6 +13,7 @@
| | | resolution. |
*/
#![allow(clippy::needless_lifetimes)]
use chrono::prelude::*;
use crate::{
@ -255,7 +256,7 @@ mod integration_test {
Value::object(
vec![
("exampleNaiveDate", Value::scalar("2015-03-14")),
("exampleNaiveDateTime", Value::scalar(1467969011.0)),
("exampleNaiveDateTime", Value::scalar(1_467_969_011.0)),
(
"exampleDateTimeFixedOffset",
Value::scalar("1996-12-19T16:39:57-08:00"),

View file

@ -434,7 +434,7 @@ mod tests {
// large value without a decimal part is also float
assert_eq!(
from_str::<InputValue<DefaultScalarValue>>("123567890123").unwrap(),
InputValue::scalar(123567890123.0)
InputValue::scalar(123_567_890_123.0)
);
}

View file

@ -1,3 +1,5 @@
#![allow(unused)]
use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject;
use crate::{

View file

@ -96,11 +96,11 @@ impl Root {
}
fn with_return() -> i32 {
return 0;
0
}
fn with_return_field_result() -> FieldResult<i32> {
return Ok(0);
Ok(0)
}
}

View file

@ -1,4 +1,5 @@
//! Query parser and language utilities
#![allow(clippy::module_inception)]
mod document;
mod lexer;

View file

@ -1,3 +1,5 @@
#![allow(clippy::module_inception)]
pub mod meta;
pub mod model;
pub mod schema;

View file

@ -106,6 +106,29 @@ pub struct Database {
droids: HashMap<String, DroidData>,
}
use crate::{
executor::Registry, schema::meta::MetaType, types::base::GraphQLType, value::ScalarValue,
};
impl<S> GraphQLType<S> for Database
where
S: ScalarValue,
{
type Context = Self;
type TypeInfo = ();
fn name(_: &()) -> Option<&str> {
Some("_Database")
}
fn meta<'r>(_: &(), registry: &mut Registry<'r, S>) -> MetaType<'r, S>
where
S: 'r,
{
registry.build_object_type::<Self>(&(), &[]).into_meta()
}
}
impl HumanData {
pub fn new(
id: &str,

View file

@ -1,8 +1,8 @@
extern crate juniper_benchmarks;
use criterion::{black_box, criterion_group, criterion_main, Criterion, ParameterizedBenchmark};
use criterion::{criterion_group, criterion_main, Criterion, ParameterizedBenchmark};
use juniper::{graphql_value, InputValue, ToInputValue, Value};
use juniper::InputValue;
use juniper_benchmarks as j;
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {

View file

@ -1,3 +1,4 @@
#![allow(clippy::match_wild_err_arm)]
use std::str::FromStr;
use proc_macro2::{Span, TokenStream};

View file

@ -1,3 +1,5 @@
#![allow(clippy::collapsible_if)]
use crate::util;
use proc_macro::TokenStream;
use quote::quote;

View file

@ -1,3 +1,5 @@
#![allow(clippy::single_match)]
pub mod parse_impl;
use quote::quote;
@ -1264,7 +1266,7 @@ mod test {
fn strs_to_strings(source: Vec<&str>) -> Vec<String> {
source
.iter()
.map(|x| x.to_string())
.map(|x| (*x).to_string())
.collect::<Vec<String>>()
}
@ -1281,7 +1283,7 @@ mod test {
#[test]
fn test_single() {
let result = get_doc_strings(&vec![MetaNameValue {
let result = get_doc_strings(&[MetaNameValue {
path: ident("doc").into(),
eq_token: Default::default(),
lit: litstr("foo"),
@ -1294,7 +1296,7 @@ mod test {
#[test]
fn test_many() {
let result = get_doc_strings(&vec![
let result = get_doc_strings(&[
MetaNameValue {
path: ident("doc").into(),
eq_token: Default::default(),
@ -1319,7 +1321,7 @@ mod test {
#[test]
fn test_not_doc() {
let result = get_doc_strings(&vec![MetaNameValue {
let result = get_doc_strings(&[MetaNameValue {
path: ident("blah").into(),
eq_token: Default::default(),
lit: litstr("foo"),

View file

@ -1,4 +1,5 @@
//! Parse impl blocks.
#![allow(clippy::or_fun_call)]
use proc_macro::TokenStream;
use quote::quote;

View file

@ -15,8 +15,8 @@ use serde_json::error::Error as SerdeError;
use std::{error::Error, fmt, string::FromUtf8Error, sync::Arc};
use url::form_urlencoded;
pub async fn graphql<CtxT, QueryT, MutationT, SubscrtipionT, S>(
root_node: Arc<RootNode<'static, QueryT, MutationT, SubscrtipionT, S>>,
pub async fn graphql<CtxT, QueryT, MutationT, SubscriptionT, S>(
root_node: Arc<RootNode<'static, QueryT, MutationT, SubscriptionT, S>>,
context: Arc<CtxT>,
request: Request<Body>,
) -> Result<Response<Body>, hyper::Error>
@ -25,10 +25,10 @@ where
CtxT: Send + Sync + 'static,
QueryT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
MutationT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
SubscrtipionT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
SubscriptionT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscrtipionT::TypeInfo: Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
{
match *request.method() {
Method::GET => {
@ -61,7 +61,7 @@ where
CtxT: Send + Sync + 'static,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
SubscriptionT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
SubscriptionT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
@ -120,11 +120,14 @@ pub async fn graphiql(graphql_endpoint: &str) -> Result<Response<Body>, hyper::E
Ok(resp)
}
pub async fn playground(graphql_endpoint: &str) -> Result<Response<Body>, hyper::Error> {
pub async fn playground(
graphql_endpoint: &str,
subscriptions_endpoint: Option<&str>,
) -> Result<Response<Body>, hyper::Error> {
let mut resp = new_html_response(StatusCode::OK);
*resp.body_mut() = Body::from(juniper::http::playground::playground_source(
graphql_endpoint,
None,
subscriptions_endpoint,
));
Ok(resp)
}
@ -176,7 +179,7 @@ where
CtxT: Send + Sync + 'static,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
SubscriptionT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
SubscriptionT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
@ -322,7 +325,7 @@ where
S: Send + Sync,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
SubscriptionT: GraphQLType<S, Context = CtxT> + Send + Sync,
SubscriptionT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
@ -330,7 +333,7 @@ where
{
match self {
GraphQLRequest::Single(request) => {
let res = request.execute(&root_node, &context).await;
let res = request.execute(&*root_node, &context).await;
let is_ok = res.is_ok();
let body = Body::from(serde_json::to_string_pretty(&res).unwrap());
(is_ok, body)
@ -338,7 +341,7 @@ where
GraphQLRequest::Batch(requests) => {
let futures = requests
.iter()
.map(|request| request.execute(&root_node, &context))
.map(|request| request.execute(&*root_node, &context))
.collect::<Vec<_>>();
let results = futures::future::join_all(futures).await;
@ -389,7 +392,6 @@ impl Error for GraphQLRequestError {
#[cfg(test)]
mod tests {
use futures;
use hyper::{
service::{make_service_fn, service_fn},
Body, Method, Response, Server, StatusCode,

View file

@ -226,6 +226,7 @@ pub struct GraphiQLHandler {
/// Handler that renders `GraphQL Playground` - a graphical query editor interface
pub struct PlaygroundHandler {
graphql_url: String,
subscription_url: Option<String>,
}
fn get_single_value<T>(mut values: Vec<T>) -> IronResult<T> {
@ -262,9 +263,9 @@ where
impl<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
GraphQLHandler<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
where
S: ScalarValue + 'a,
S: ScalarValue + Send + Sync + 'static,
CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + Send + Sync + 'static,
CtxT: 'static,
CtxT: Send + Sync + 'static,
Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
Mutation: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
Subscription: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
@ -348,9 +349,10 @@ impl PlaygroundHandler {
///
/// The provided URL should point to the URL of the attached `GraphQLHandler`. It can be
/// relative, so a common value could be `"/graphql"`.
pub fn new(graphql_url: &str) -> PlaygroundHandler {
pub fn new(graphql_url: &str, subscription_url: Option<&str>) -> PlaygroundHandler {
PlaygroundHandler {
graphql_url: graphql_url.to_owned(),
subscription_url: subscription_url.map(|s| s.to_owned()),
}
}
}
@ -360,7 +362,7 @@ impl<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S> Handler
where
S: ScalarValue + Sync + Send + 'static,
CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + Send + Sync + 'static,
CtxT: 'static,
CtxT: Send + Sync + 'static,
Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
Mutation: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
Subscription: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
@ -398,7 +400,10 @@ impl Handler for PlaygroundHandler {
Ok(Response::with((
content_type,
status::Ok,
juniper::http::playground::playground_source(&self.graphql_url, None),
juniper::http::playground::playground_source(
&self.graphql_url,
self.subscription_url.as_deref(),
),
)))
}
}
@ -462,7 +467,7 @@ mod tests {
let path: String = url
.path()
.iter()
.map(|x| x.to_string())
.map(|x| (*x).to_string())
.collect::<Vec<String>>()
.join("/");
format!(

View file

@ -148,10 +148,13 @@ pub fn graphiql_source(graphql_endpoint_url: &str) -> content::Html<String> {
}
/// Generate an HTML page containing GraphQL Playground
pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> {
pub fn playground_source(
graphql_endpoint_url: &str,
subscriptions_endpoint: Option<&str>,
) -> content::Html<String> {
content::Html(juniper::http::playground::playground_source(
graphql_endpoint_url,
None,
subscriptions_endpoint,
))
}

View file

@ -240,12 +240,12 @@ where
}
});
let obj = Object::from_iter(ready_vec_iterator);
return Poll::Ready(Some(GraphQLResponse::from_result(Ok((
Poll::Ready(Some(GraphQLResponse::from_result(Ok((
Value::Object(obj),
vec![],
)))));
)))))
} else {
return Poll::Pending;
Poll::Pending
}
},
);

View file

@ -75,11 +75,11 @@ where
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
{
match self {
&GraphQLBatchRequest::Single(ref request) => {
match *self {
GraphQLBatchRequest::Single(ref request) => {
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
}
&GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
requests
.iter()
.map(|request| request.execute_sync(root_node, context))
@ -103,12 +103,12 @@ where
CtxT: Send + Sync,
S: Send + Sync,
{
match self {
&GraphQLBatchRequest::Single(ref request) => {
match *self {
GraphQLBatchRequest::Single(ref request) => {
let res = request.execute(root_node, context).await;
GraphQLBatchResponse::Single(res)
}
&GraphQLBatchRequest::Batch(ref requests) => {
GraphQLBatchRequest::Batch(ref requests) => {
let futures = requests
.iter()
.map(|request| request.execute(root_node, context))
@ -265,7 +265,7 @@ where
};
let get_filter = warp::get()
.and(context_extractor.clone())
.and(context_extractor)
.and(warp::filters::query::query())
.and_then(handle_get_request);
@ -731,7 +731,7 @@ mod tests {
EmptySubscription::<Database>::new(),
);
let state = warp::any().map(move || Database::new());
let state = warp::any().map(Database::new);
let filter = warp::path("graphql2").and(make_graphql_filter(schema, state.boxed()));
let response = request()
@ -770,7 +770,7 @@ mod tests {
EmptySubscription::<Database>::new(),
);
let state = warp::any().map(move || Database::new());
let state = warp::any().map(Database::new);
let filter = warp::path("graphql2").and(make_graphql_filter(schema, state.boxed()));
let response = request()