Skip to content

Resolve some todos in async-await branch #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
dd424f3
Bubble up scalar error (#434)
andy128k Oct 24, 2019
9be274a
Update CHANGELOG.md
LegNeato Oct 24, 2019
8628ddd
Make EmptyMutation `Send`
LegNeato Oct 24, 2019
6b7977b
Update CHANGELOG.md
LegNeato Oct 24, 2019
252f7b4
Release juniper_codegen 0.14.1
LegNeato Oct 24, 2019
c434bdd
Release juniper 0.14.1
LegNeato Oct 24, 2019
012c0b1
Release juniper_hyper 0.5.1
LegNeato Oct 24, 2019
0421f9a
Release juniper_iron 0.6.1
LegNeato Oct 24, 2019
7c98eaf
Release juniper_rocket 0.5.1
LegNeato Oct 24, 2019
91a9752
Release juniper_warp 0.5.1
LegNeato Oct 24, 2019
bd3d289
Resolve RFC 2565 related todos
nWacky Nov 1, 2019
0f4e998
Remove __juniper_extract_generic macro
nWacky Nov 1, 2019
13bbbe2
Start adding `async-trait` to `GraphQLTypeAsync`
nWacky Nov 1, 2019
563e44c
Merge remote-tracking branch 'upstream/async-await' into async-await
nWacky Nov 1, 2019
737c4c7
Add `resolve_into_type_async`
nWacky Nov 1, 2019
9e2a63a
Refactor `GraphQLTypeAsync` to use `async-trait`
nWacky Nov 1, 2019
9478b6c
Remove useless todo
nWacky Nov 4, 2019
91dc55b
Resolve better error message with field/type name todo, update other …
nWacky Nov 4, 2019
afd92cd
Format
nWacky Nov 4, 2019
2404b81
Rebase onto master
nWacky Nov 4, 2019
09d1077
Merge branch 'async-await-resolve-some-todos' of https://github.com/i…
nWacky Nov 4, 2019
503bb63
Format
nWacky Nov 4, 2019
e2ebaee
Merge import in `async_await`
nWacky Nov 4, 2019
3e5e2ae
Format
nWacky Nov 4, 2019
779208e
Bubble up scalar error (#434)
andy128k Oct 24, 2019
7230efc
Update CHANGELOG.md
LegNeato Oct 24, 2019
665c3d2
Make EmptyMutation `Send`
LegNeato Oct 24, 2019
bb99076
Update CHANGELOG.md
LegNeato Oct 24, 2019
7b18bd2
Release juniper_codegen 0.14.1
LegNeato Oct 24, 2019
191468b
Release juniper 0.14.1
LegNeato Oct 24, 2019
fed6950
Release juniper_hyper 0.5.1
LegNeato Oct 24, 2019
bf88826
Release juniper_iron 0.6.1
LegNeato Oct 24, 2019
c298697
Release juniper_rocket 0.5.1
LegNeato Oct 24, 2019
c24687d
Release juniper_warp 0.5.1
LegNeato Oct 24, 2019
d22b5c6
Resolve RFC 2565 related todos
nWacky Nov 1, 2019
bfe6c7a
Remove __juniper_extract_generic macro
nWacky Nov 1, 2019
e03e525
Start adding `async-trait` to `GraphQLTypeAsync`
nWacky Nov 1, 2019
820f472
Add `resolve_into_type_async`
nWacky Nov 1, 2019
52c3e28
Refactor `GraphQLTypeAsync` to use `async-trait`
nWacky Nov 1, 2019
b1970ae
Remove useless todo
nWacky Nov 4, 2019
00dd1dc
Resolve better error message with field/type name todo, update other …
nWacky Nov 4, 2019
e3c12e3
Format
nWacky Nov 4, 2019
dbcaf30
Rebase onto master
nWacky Nov 4, 2019
554ba34
Format
nWacky Nov 4, 2019
9506272
Merge import in `async_await`
nWacky Nov 4, 2019
7135c07
Format
nWacky Nov 4, 2019
ec76bf5
Fix cargo.toml in `warp_async`
nWacky Nov 5, 2019
99c0d26
Comment out `attr_arg_descr` and `attr_arg_descr_collapse` tests
nWacky Nov 5, 2019
e151026
Merge branch 'async-await-resolve-some-todos' of https://github.com/i…
nWacky Nov 5, 2019
4834349
Rebase onto `async-await`
nWacky Nov 6, 2019
09d9513
Rebase onto `master`
nWacky Nov 6, 2019
e344f1c
Merge branch 'async-await-resolve-some-todos' of https://github.com/i…
nWacky Nov 6, 2019
778606c
Fix bad merge [skip ci]
nWacky Nov 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.1)

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

# [[0.14.0] 2019-09-29](https://github.com/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://github.com/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://github.com/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://github.com/rust-lang/rust/issues/60406) is implemented
// TODO: enable once [parameter attributes are supported by proc macros]
// (https://github.com/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://github.com/rust-lang/rust/issues/60406) is implemented
// TODO: enable once [parameter attributes are supported by proc macros]
// (https://github.com/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