Clippy cleanup (#579)
This commit is contained in:
parent
a275c8dcc2
commit
5f777e8a6d
30 changed files with 119 additions and 68 deletions
benches
examples/warp_subscriptions/src
integration_tests
async_await/src
juniper_tests/src
juniper
benches
src
juniper_benchmarks/benches
juniper_codegen/src
juniper_hyper/src
juniper_iron/src
juniper_rocket/src
juniper_subscriptions/src
juniper_warp/src
|
@ -1,4 +1,5 @@
|
||||||
#[macro_use] extern crate bencher;
|
#[macro_use]
|
||||||
|
extern crate bencher;
|
||||||
extern crate juniper;
|
extern crate juniper;
|
||||||
|
|
||||||
use bencher::Bencher;
|
use bencher::Bencher;
|
||||||
|
|
|
@ -144,9 +144,7 @@ async fn main() {
|
||||||
let homepage = warp::path::end().map(|| {
|
let homepage = warp::path::end().map(|| {
|
||||||
Response::builder()
|
Response::builder()
|
||||||
.header("content-type", "text/html")
|
.header("content-type", "text/html")
|
||||||
.body(format!(
|
.body("<html><h1>juniper_subscriptions demo</h1><div>visit <a href=\"/playground\">graphql playground</a></html>".to_string())
|
||||||
"<html><h1>juniper_subscriptions demo</h1><div>visit <a href=\"/playground\">graphql playground</a></html>"
|
|
||||||
))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let qm_schema = schema();
|
let qm_schema = schema();
|
||||||
|
|
|
@ -9,6 +9,7 @@ enum UserKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
|
#[allow(dead_code)]
|
||||||
id: i32,
|
id: i32,
|
||||||
name: String,
|
name: String,
|
||||||
kind: UserKind,
|
kind: UserKind,
|
||||||
|
|
|
@ -4,8 +4,6 @@ use fnv::FnvHashMap;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
|
use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
#[derive(juniper::GraphQLEnum, Debug, PartialEq)]
|
#[derive(juniper::GraphQLEnum, Debug, PartialEq)]
|
||||||
#[graphql(name = "Some", description = "enum descr")]
|
#[graphql(name = "Some", description = "enum descr")]
|
||||||
enum SomeEnum {
|
enum SomeEnum {
|
||||||
|
|
|
@ -9,8 +9,6 @@ use juniper::{
|
||||||
self, execute, EmptyMutation, EmptySubscription, GraphQLType, RootNode, Value, Variables,
|
self, execute, EmptyMutation, EmptySubscription, GraphQLType, RootNode, Value, Variables,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
#[derive(GraphQLObject, Debug, PartialEq)]
|
#[derive(GraphQLObject, Debug, PartialEq)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
name = "MyObj",
|
name = "MyObj",
|
||||||
|
@ -333,7 +331,7 @@ async fn check_descriptions(
|
||||||
"#,
|
"#,
|
||||||
object_name
|
object_name
|
||||||
);
|
);
|
||||||
run_type_info_query(&doc, |(type_info, values)| {
|
let _result = run_type_info_query(&doc, |(type_info, values)| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("name"),
|
type_info.get_field_value("name"),
|
||||||
Some(&Value::scalar(object_name))
|
Some(&Value::scalar(object_name))
|
||||||
|
|
|
@ -4,8 +4,6 @@ use juniper::{
|
||||||
Value, Variables,
|
Value, Variables,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
|
||||||
#[juniper::graphql_object]
|
#[juniper::graphql_object]
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use futures;
|
|
||||||
|
|
||||||
// Trait.
|
// Trait.
|
||||||
|
|
||||||
#[derive(juniper::GraphQLObject)]
|
#[derive(juniper::GraphQLObject)]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use futures;
|
|
||||||
use juniper::{DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
|
use juniper::{DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};
|
||||||
|
|
||||||
#[derive(juniper::GraphQLScalarValue, PartialEq, Eq, Debug)]
|
#[derive(juniper::GraphQLScalarValue, PartialEq, Eq, Debug)]
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute,
|
execute,
|
||||||
parser::{ParseError, ScalarToken, Spanning, Token},
|
parser::{ParseError, ScalarToken, Spanning, Token},
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
// Original author of this test is <https://github.com/davidpdrsn>.
|
// Original author of this test is <https://github.com/davidpdrsn>.
|
||||||
use juniper::*;
|
use juniper::*;
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
pub struct Context;
|
pub struct Context;
|
||||||
|
|
||||||
impl juniper::Context for Context {}
|
impl juniper::Context for Context {}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
// Original author of this test is <https://github.com/davidpdrsn>.
|
// Original author of this test is <https://github.com/davidpdrsn>.
|
||||||
use juniper::*;
|
use juniper::*;
|
||||||
|
|
||||||
use futures;
|
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::graphql_object]
|
#[juniper::graphql_object]
|
||||||
|
|
|
@ -4,11 +4,23 @@ extern crate juniper;
|
||||||
|
|
||||||
use bencher::Bencher;
|
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) {
|
fn query_type_name(b: &mut Bencher) {
|
||||||
let database = Database::new();
|
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#"
|
let doc = r#"
|
||||||
query IntrospectionQueryTypeQuery {
|
query IntrospectionQueryTypeQuery {
|
||||||
|
@ -24,7 +36,16 @@ fn query_type_name(b: &mut Bencher) {
|
||||||
|
|
||||||
fn introspection_query(b: &mut Bencher) {
|
fn introspection_query(b: &mut Bencher) {
|
||||||
let database = Database::new();
|
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#"
|
let doc = r#"
|
||||||
query IntrospectionQuery {
|
query IntrospectionQuery {
|
||||||
|
|
|
@ -8,6 +8,7 @@ enum UserKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
|
#[allow(dead_code)]
|
||||||
id: i32,
|
id: i32,
|
||||||
name: String,
|
name: String,
|
||||||
kind: UserKind,
|
kind: UserKind,
|
||||||
|
@ -24,14 +25,13 @@ impl User {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn friends(&self) -> Vec<User> {
|
async fn friends(&self) -> Vec<User> {
|
||||||
let friends = (0..10)
|
(0..10)
|
||||||
.map(|index| User {
|
.map(|index| User {
|
||||||
id: index,
|
id: index,
|
||||||
name: format!("user{}", index),
|
name: format!("user{}", index),
|
||||||
kind: UserKind::User,
|
kind: UserKind::User,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect()
|
||||||
friends
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn kind(&self) -> &UserKind {
|
async fn kind(&self) -> &UserKind {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
| | | resolution. |
|
| | | resolution. |
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#![allow(clippy::needless_lifetimes)]
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -255,7 +256,7 @@ mod integration_test {
|
||||||
Value::object(
|
Value::object(
|
||||||
vec![
|
vec![
|
||||||
("exampleNaiveDate", Value::scalar("2015-03-14")),
|
("exampleNaiveDate", Value::scalar("2015-03-14")),
|
||||||
("exampleNaiveDateTime", Value::scalar(1467969011.0)),
|
("exampleNaiveDateTime", Value::scalar(1_467_969_011.0)),
|
||||||
(
|
(
|
||||||
"exampleDateTimeFixedOffset",
|
"exampleDateTimeFixedOffset",
|
||||||
Value::scalar("1996-12-19T16:39:57-08:00"),
|
Value::scalar("1996-12-19T16:39:57-08:00"),
|
||||||
|
|
|
@ -434,7 +434,7 @@ mod tests {
|
||||||
// large value without a decimal part is also float
|
// large value without a decimal part is also float
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<InputValue<DefaultScalarValue>>("123567890123").unwrap(),
|
from_str::<InputValue<DefaultScalarValue>>("123567890123").unwrap(),
|
||||||
InputValue::scalar(123567890123.0)
|
InputValue::scalar(123_567_890_123.0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject;
|
use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -96,11 +96,11 @@ impl Root {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_return() -> i32 {
|
fn with_return() -> i32 {
|
||||||
return 0;
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_return_field_result() -> FieldResult<i32> {
|
fn with_return_field_result() -> FieldResult<i32> {
|
||||||
return Ok(0);
|
Ok(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Query parser and language utilities
|
//! Query parser and language utilities
|
||||||
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
mod document;
|
mod document;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
pub mod meta;
|
pub mod meta;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
|
|
|
@ -106,6 +106,29 @@ pub struct Database {
|
||||||
droids: HashMap<String, DroidData>,
|
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 {
|
impl HumanData {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: &str,
|
id: &str,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
extern crate juniper_benchmarks;
|
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;
|
use juniper_benchmarks as j;
|
||||||
|
|
||||||
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(clippy::match_wild_err_arm)]
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::collapsible_if)]
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::single_match)]
|
||||||
|
|
||||||
pub mod parse_impl;
|
pub mod parse_impl;
|
||||||
|
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
@ -1264,7 +1266,7 @@ mod test {
|
||||||
fn strs_to_strings(source: Vec<&str>) -> Vec<String> {
|
fn strs_to_strings(source: Vec<&str>) -> Vec<String> {
|
||||||
source
|
source
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| (*x).to_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1281,7 +1283,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_single() {
|
fn test_single() {
|
||||||
let result = get_doc_strings(&vec![MetaNameValue {
|
let result = get_doc_strings(&[MetaNameValue {
|
||||||
path: ident("doc").into(),
|
path: ident("doc").into(),
|
||||||
eq_token: Default::default(),
|
eq_token: Default::default(),
|
||||||
lit: litstr("foo"),
|
lit: litstr("foo"),
|
||||||
|
@ -1294,7 +1296,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_many() {
|
fn test_many() {
|
||||||
let result = get_doc_strings(&vec![
|
let result = get_doc_strings(&[
|
||||||
MetaNameValue {
|
MetaNameValue {
|
||||||
path: ident("doc").into(),
|
path: ident("doc").into(),
|
||||||
eq_token: Default::default(),
|
eq_token: Default::default(),
|
||||||
|
@ -1319,7 +1321,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_not_doc() {
|
fn test_not_doc() {
|
||||||
let result = get_doc_strings(&vec![MetaNameValue {
|
let result = get_doc_strings(&[MetaNameValue {
|
||||||
path: ident("blah").into(),
|
path: ident("blah").into(),
|
||||||
eq_token: Default::default(),
|
eq_token: Default::default(),
|
||||||
lit: litstr("foo"),
|
lit: litstr("foo"),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Parse impl blocks.
|
//! Parse impl blocks.
|
||||||
|
#![allow(clippy::or_fun_call)]
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
|
@ -15,8 +15,8 @@ use serde_json::error::Error as SerdeError;
|
||||||
use std::{error::Error, fmt, string::FromUtf8Error, sync::Arc};
|
use std::{error::Error, fmt, string::FromUtf8Error, sync::Arc};
|
||||||
use url::form_urlencoded;
|
use url::form_urlencoded;
|
||||||
|
|
||||||
pub async fn graphql<CtxT, QueryT, MutationT, SubscrtipionT, S>(
|
pub async fn graphql<CtxT, QueryT, MutationT, SubscriptionT, S>(
|
||||||
root_node: Arc<RootNode<'static, QueryT, MutationT, SubscrtipionT, S>>,
|
root_node: Arc<RootNode<'static, QueryT, MutationT, SubscriptionT, S>>,
|
||||||
context: Arc<CtxT>,
|
context: Arc<CtxT>,
|
||||||
request: Request<Body>,
|
request: Request<Body>,
|
||||||
) -> Result<Response<Body>, hyper::Error>
|
) -> Result<Response<Body>, hyper::Error>
|
||||||
|
@ -25,10 +25,10 @@ where
|
||||||
CtxT: Send + Sync + 'static,
|
CtxT: Send + Sync + 'static,
|
||||||
QueryT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
|
QueryT: GraphQLType<S, Context = CtxT> + Send + Sync + 'static,
|
||||||
MutationT: 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,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
MutationT::TypeInfo: Send + Sync,
|
MutationT::TypeInfo: Send + Sync,
|
||||||
SubscrtipionT::TypeInfo: Send + Sync,
|
SubscriptionT::TypeInfo: Send + Sync,
|
||||||
{
|
{
|
||||||
match *request.method() {
|
match *request.method() {
|
||||||
Method::GET => {
|
Method::GET => {
|
||||||
|
@ -61,7 +61,7 @@ where
|
||||||
CtxT: Send + Sync + 'static,
|
CtxT: Send + Sync + 'static,
|
||||||
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
|
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
|
||||||
MutationT: 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,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
MutationT::TypeInfo: Send + Sync,
|
MutationT::TypeInfo: Send + Sync,
|
||||||
SubscriptionT::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)
|
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);
|
let mut resp = new_html_response(StatusCode::OK);
|
||||||
*resp.body_mut() = Body::from(juniper::http::playground::playground_source(
|
*resp.body_mut() = Body::from(juniper::http::playground::playground_source(
|
||||||
graphql_endpoint,
|
graphql_endpoint,
|
||||||
None,
|
subscriptions_endpoint,
|
||||||
));
|
));
|
||||||
Ok(resp)
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
@ -176,7 +179,7 @@ where
|
||||||
CtxT: Send + Sync + 'static,
|
CtxT: Send + Sync + 'static,
|
||||||
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
|
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync + 'static,
|
||||||
MutationT: 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,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
MutationT::TypeInfo: Send + Sync,
|
MutationT::TypeInfo: Send + Sync,
|
||||||
SubscriptionT::TypeInfo: Send + Sync,
|
SubscriptionT::TypeInfo: Send + Sync,
|
||||||
|
@ -322,7 +325,7 @@ where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
||||||
MutationT: 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,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
MutationT::TypeInfo: Send + Sync,
|
MutationT::TypeInfo: Send + Sync,
|
||||||
SubscriptionT::TypeInfo: Send + Sync,
|
SubscriptionT::TypeInfo: Send + Sync,
|
||||||
|
@ -330,7 +333,7 @@ where
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
GraphQLRequest::Single(request) => {
|
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 is_ok = res.is_ok();
|
||||||
let body = Body::from(serde_json::to_string_pretty(&res).unwrap());
|
let body = Body::from(serde_json::to_string_pretty(&res).unwrap());
|
||||||
(is_ok, body)
|
(is_ok, body)
|
||||||
|
@ -338,7 +341,7 @@ where
|
||||||
GraphQLRequest::Batch(requests) => {
|
GraphQLRequest::Batch(requests) => {
|
||||||
let futures = requests
|
let futures = requests
|
||||||
.iter()
|
.iter()
|
||||||
.map(|request| request.execute(&root_node, &context))
|
.map(|request| request.execute(&*root_node, &context))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let results = futures::future::join_all(futures).await;
|
let results = futures::future::join_all(futures).await;
|
||||||
|
|
||||||
|
@ -389,7 +392,6 @@ impl Error for GraphQLRequestError {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use futures;
|
|
||||||
use hyper::{
|
use hyper::{
|
||||||
service::{make_service_fn, service_fn},
|
service::{make_service_fn, service_fn},
|
||||||
Body, Method, Response, Server, StatusCode,
|
Body, Method, Response, Server, StatusCode,
|
||||||
|
|
|
@ -226,6 +226,7 @@ pub struct GraphiQLHandler {
|
||||||
/// Handler that renders `GraphQL Playground` - a graphical query editor interface
|
/// Handler that renders `GraphQL Playground` - a graphical query editor interface
|
||||||
pub struct PlaygroundHandler {
|
pub struct PlaygroundHandler {
|
||||||
graphql_url: String,
|
graphql_url: String,
|
||||||
|
subscription_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_single_value<T>(mut values: Vec<T>) -> IronResult<T> {
|
fn get_single_value<T>(mut values: Vec<T>) -> IronResult<T> {
|
||||||
|
@ -262,9 +263,9 @@ where
|
||||||
impl<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
|
impl<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
|
||||||
GraphQLHandler<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
|
GraphQLHandler<'a, CtxFactory, Query, Mutation, Subscription, CtxT, S>
|
||||||
where
|
where
|
||||||
S: ScalarValue + 'a,
|
S: ScalarValue + Send + Sync + 'static,
|
||||||
CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + 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,
|
Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
|
||||||
Mutation: 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,
|
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
|
/// The provided URL should point to the URL of the attached `GraphQLHandler`. It can be
|
||||||
/// relative, so a common value could be `"/graphql"`.
|
/// 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 {
|
PlaygroundHandler {
|
||||||
graphql_url: graphql_url.to_owned(),
|
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
|
where
|
||||||
S: ScalarValue + Sync + Send + 'static,
|
S: ScalarValue + Sync + Send + 'static,
|
||||||
CtxFactory: Fn(&mut Request) -> IronResult<CtxT> + 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,
|
Query: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
|
||||||
Mutation: 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,
|
Subscription: GraphQLType<S, Context = CtxT, TypeInfo = ()> + Send + Sync + 'static,
|
||||||
|
@ -398,7 +400,10 @@ impl Handler for PlaygroundHandler {
|
||||||
Ok(Response::with((
|
Ok(Response::with((
|
||||||
content_type,
|
content_type,
|
||||||
status::Ok,
|
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
|
let path: String = url
|
||||||
.path()
|
.path()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| (*x).to_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("/");
|
.join("/");
|
||||||
format!(
|
format!(
|
||||||
|
|
|
@ -148,10 +148,13 @@ pub fn graphiql_source(graphql_endpoint_url: &str) -> content::Html<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate an HTML page containing GraphQL Playground
|
/// 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(
|
content::Html(juniper::http::playground::playground_source(
|
||||||
graphql_endpoint_url,
|
graphql_endpoint_url,
|
||||||
None,
|
subscriptions_endpoint,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,12 +240,12 @@ where
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let obj = Object::from_iter(ready_vec_iterator);
|
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),
|
Value::Object(obj),
|
||||||
vec![],
|
vec![],
|
||||||
)))));
|
)))))
|
||||||
} else {
|
} else {
|
||||||
return Poll::Pending;
|
Poll::Pending
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -75,11 +75,11 @@ where
|
||||||
SubscriptionT::TypeInfo: Send + Sync,
|
SubscriptionT::TypeInfo: Send + Sync,
|
||||||
CtxT: Send + Sync,
|
CtxT: Send + Sync,
|
||||||
{
|
{
|
||||||
match self {
|
match *self {
|
||||||
&GraphQLBatchRequest::Single(ref request) => {
|
GraphQLBatchRequest::Single(ref request) => {
|
||||||
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
|
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
|
||||||
}
|
}
|
||||||
&GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
|
GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
|
||||||
requests
|
requests
|
||||||
.iter()
|
.iter()
|
||||||
.map(|request| request.execute_sync(root_node, context))
|
.map(|request| request.execute_sync(root_node, context))
|
||||||
|
@ -103,12 +103,12 @@ where
|
||||||
CtxT: Send + Sync,
|
CtxT: Send + Sync,
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
{
|
{
|
||||||
match self {
|
match *self {
|
||||||
&GraphQLBatchRequest::Single(ref request) => {
|
GraphQLBatchRequest::Single(ref request) => {
|
||||||
let res = request.execute(root_node, context).await;
|
let res = request.execute(root_node, context).await;
|
||||||
GraphQLBatchResponse::Single(res)
|
GraphQLBatchResponse::Single(res)
|
||||||
}
|
}
|
||||||
&GraphQLBatchRequest::Batch(ref requests) => {
|
GraphQLBatchRequest::Batch(ref requests) => {
|
||||||
let futures = requests
|
let futures = requests
|
||||||
.iter()
|
.iter()
|
||||||
.map(|request| request.execute(root_node, context))
|
.map(|request| request.execute(root_node, context))
|
||||||
|
@ -265,7 +265,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let get_filter = warp::get()
|
let get_filter = warp::get()
|
||||||
.and(context_extractor.clone())
|
.and(context_extractor)
|
||||||
.and(warp::filters::query::query())
|
.and(warp::filters::query::query())
|
||||||
.and_then(handle_get_request);
|
.and_then(handle_get_request);
|
||||||
|
|
||||||
|
@ -731,7 +731,7 @@ mod tests {
|
||||||
EmptySubscription::<Database>::new(),
|
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 filter = warp::path("graphql2").and(make_graphql_filter(schema, state.boxed()));
|
||||||
|
|
||||||
let response = request()
|
let response = request()
|
||||||
|
@ -770,7 +770,7 @@ mod tests {
|
||||||
EmptySubscription::<Database>::new(),
|
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 filter = warp::path("graphql2").and(make_graphql_filter(schema, state.boxed()));
|
||||||
|
|
||||||
let response = request()
|
let response = request()
|
||||||
|
|
Loading…
Add table
Reference in a new issue