Skip to content

Commit

Permalink
Merge pull request #452 from instrumentisto/async-await-resolve-some-…
Browse files Browse the repository at this point in the history
…todos

Resolve some todos in async-await branch
  • Loading branch information
LegNeato authored Nov 7, 2019
2 parents 34c380b + 778606c commit b133a0f
Show file tree
Hide file tree
Showing 32 changed files with 373 additions and 184 deletions.
127 changes: 127 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#[macro_use] extern crate bencher;
extern crate juniper;

use bencher::Bencher;

use juniper::{execute, RootNode, EmptyMutation, Variables};
use juniper::tests::model::Database;

fn query_type_name(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());

let doc = r#"
query IntrospectionQueryTypeQuery {
__schema {
queryType {
name
}
}
}"#;

b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
}

fn introspection_query(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());

let doc = r#"
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
"#;

b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
}

benchmark_group!(queries, query_type_name, introspection_query);
benchmark_main!(queries);
2 changes: 1 addition & 1 deletion examples/warp_async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl User {
}
}

struct Query;
struct Query;

#[juniper::object(Context = Context)]
impl Query {
Expand Down
5 changes: 5 additions & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

- No changes yet

# [[0.14.1] 2019-10-24](https:/graphql-rust/juniper/releases/tag/juniper-0.14.1)

- Fix panic when an invalid scalar is used by a client [#434](https:/graphql-rust/juniper/pull/434)
- `EmptyMutation` now implements `Send` [#443](https:/graphql-rust/juniper/pull/443)

# [[0.14.0] 2019-09-29](https:/graphql-rust/juniper/releases/tag/juniper-0.14.0)

- Require `url` 2.x if `url` feature is enabled.
Expand Down
11 changes: 5 additions & 6 deletions juniper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "juniper"
version = "0.14.0"
version = "0.14.1"
authors = [
"Magnus Hallin <[email protected]>",
"Christoph Herzog <[email protected]>",
Expand Down Expand Up @@ -33,20 +33,19 @@ default = [
]

[dependencies]
juniper_codegen = { version = "0.14.0", path = "../juniper_codegen" }
juniper_codegen = { version = "0.14.1", path = "../juniper_codegen" }

async-trait = "0.1.16"
chrono = { version = "0.4.0", optional = true }
fnv = "1.0.3"
futures-preview = { version = "=0.3.0-alpha.19", optional = true }
indexmap = { version = "1.0.0", features = ["serde-1"] }
serde = { version = "1.0.8" }
serde_derive = { version = "1.0.2" }

chrono = { version = "0.4.0", optional = true }
serde_json = { version="1.0.2", optional = true }
url = { version = "2", optional = true }
uuid = { version = "0.7", optional = true }

futures-preview = { version = "=0.3.0-alpha.19", optional = true }

[dev-dependencies]
bencher = "0.1.2"
serde_json = { version = "1.0.2" }
Expand Down
14 changes: 0 additions & 14 deletions juniper/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,6 @@ impl<S> FieldError<S> {
/// The result of resolving the value of a field of type `T`
pub type FieldResult<T, S = DefaultScalarValue> = Result<T, FieldError<S>>;

/*
pub enum ResolvedValue<'a, S = DefaultScalarValue> {
Value(Value<S>),
Future(crate::BoxFuture<'a, Value<S>>),
}
impl<'a, S> From<Value<S>> for ResolvedValue<'a, S> {
#[inline]
fn from(value: Value<S>) -> Self {
ResolvedValue::Value(value)
}
}
*/

/// The result of resolving an unspecified field
pub type ExecutionResult<S = DefaultScalarValue> = Result<Value<S>, FieldError<S>>;

Expand Down
2 changes: 1 addition & 1 deletion juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected.
[chrono]: https://crates.io/crates/chrono
*/
#![doc(html_root_url = "https://docs.rs/juniper/0.14.0")]
#![doc(html_root_url = "https://docs.rs/juniper/0.14.1")]
#![warn(missing_docs)]

#[doc(hidden)]
Expand Down
19 changes: 0 additions & 19 deletions juniper/src/macros/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,6 @@ macro_rules! __juniper_insert_generic {
};
}

// TODO: remove me.
#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_extract_generic {
(<$name:ident>) => {
$name
};
(
<$generic:tt $(: $bound: tt)*>
) => {
$generic
};
(
$scalar: ty
) => {
$scalar
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_parse_object_header {
Expand Down
12 changes: 8 additions & 4 deletions juniper/src/macros/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,16 @@ macro_rules! graphql_scalar {
)
{

fn resolve_async<'a>(
fn resolve_async<'a, 'async_trait>(
&'a self,
info: &'a Self::TypeInfo,
selection_set: Option<&'a [$crate::Selection<$crate::__juniper_insert_generic!($($scalar)+)>]>,
executor: &'a $crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
) -> futures::future::BoxFuture<'a, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>> {
selection_set: Option<&'a [$crate::Selection<'a, $crate::__juniper_insert_generic!($($scalar)+)>]>,
executor: &'a $crate::Executor<'a, Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
) -> futures::future::BoxFuture<'async_trait, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>>
where
'a: 'async_trait,
Self: 'async_trait,
{
use $crate::GraphQLType;
use futures::future;
let v = self.resolve(info, selection_set, executor);
Expand Down
24 changes: 15 additions & 9 deletions juniper/src/macros/tests/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ impl Root {
0
}

// TODO: enable once [RFC 2565](https:/rust-lang/rust/issues/60406) is implemented
// fn attr_arg_descr(#[doc = "The arg"] arg: i32) -> i32 { 0 }
// fn attr_arg_descr_collapse(
// #[doc = "The arg"]
// #[doc = "and more details"]
// arg: i32,
// ) -> i32 { 0 }
// TODO: enable once [parameter attributes are supported by proc macros]
// (https:/graphql-rust/juniper/pull/441)
// fn attr_arg_descr(
// #[graphql(description = "The arg")]
// arg: i32) -> i32
// { 0 }
// fn attr_arg_descr_collapse(
// #[graphql(description = "The first arg")]
// #[graphql(description = "and more details")]
// arg: i32,
// ) -> i32 { 0 }

#[graphql(arguments(arg(default = 123,),))]
fn arg_with_default(arg: i32) -> i32 {
Expand Down Expand Up @@ -559,7 +563,8 @@ fn introspect_field_multi_args_descr_trailing_comma() {
});
}

// TODO: enable once [RFC 2565](https:/rust-lang/rust/issues/60406) is implemented
// TODO: enable once [parameter attributes are supported by proc macros]
// (https:/graphql-rust/juniper/pull/441)
// #[test]
// fn introspect_field_attr_arg_descr() {
// run_args_info_query("attrArgDescr", |args| {
Expand Down Expand Up @@ -593,7 +598,8 @@ fn introspect_field_multi_args_descr_trailing_comma() {
// });
// }

// TODO: enable once [RFC 2565](https:/rust-lang/rust/issues/60406) is implemented
// TODO: enable once [parameter attributes are supported by proc macros]
// (https:/graphql-rust/juniper/pull/441)
// #[test]
// fn introspect_field_attr_arg_descr_collapse() {
// run_args_info_query("attrArgDescrCollapse", |args| {
Expand Down
4 changes: 4 additions & 0 deletions juniper/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub enum ParseError<'a> {

/// An error during tokenization occurred
LexerError(LexerError),

/// A scalar of unexpected type occurred in the source
ExpectedScalarError(&'static str),
}

#[doc(hidden)]
Expand Down Expand Up @@ -196,6 +199,7 @@ impl<'a> fmt::Display for ParseError<'a> {
ParseError::UnexpectedToken(ref token) => write!(f, "Unexpected \"{}\"", token),
ParseError::UnexpectedEndOfFile => write!(f, "Unexpected end of input"),
ParseError::LexerError(ref err) => err.fmt(f),
ParseError::ExpectedScalarError(err) => err.fmt(f),
}
}
}
21 changes: 21 additions & 0 deletions juniper/src/parser/tests/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
},
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
schema::model::SchemaType,
types::scalars::EmptyMutation,
validation::test_harness::{MutationRoot, QueryRoot},
value::{DefaultScalarValue, ScalarRefValue, ScalarValue},
};
Expand Down Expand Up @@ -145,3 +146,23 @@ fn errors() {
)
);
}

#[test]
fn issue_427_panic_is_not_expected() {
struct QueryWithoutFloat;

#[crate::object_internal]
impl QueryWithoutFloat {
fn echo(value: String) -> String {
value
}
}

let schema = SchemaType::new::<QueryWithoutFloat, EmptyMutation<()>>(&(), &());
let parse_result = parse_document_source(r##"{ echo(value: 123.0) }"##, &schema);

assert_eq!(
parse_result.unwrap_err().item,
ParseError::ExpectedScalarError("There needs to be a Float type")
);
}
Loading

0 comments on commit b133a0f

Please sign in to comment.