Skip to content

Commit b133a0f

Browse files
authored
Merge pull request #452 from instrumentisto/async-await-resolve-some-todos
Resolve some todos in async-await branch
2 parents 34c380b + 778606c commit b133a0f

File tree

32 files changed

+373
-184
lines changed

32 files changed

+373
-184
lines changed

benches/bench.rs

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#[macro_use] extern crate bencher;
2+
extern crate juniper;
3+
4+
use bencher::Bencher;
5+
6+
use juniper::{execute, RootNode, EmptyMutation, Variables};
7+
use juniper::tests::model::Database;
8+
9+
fn query_type_name(b: &mut Bencher) {
10+
let database = Database::new();
11+
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
12+
13+
let doc = r#"
14+
query IntrospectionQueryTypeQuery {
15+
__schema {
16+
queryType {
17+
name
18+
}
19+
}
20+
}"#;
21+
22+
b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
23+
}
24+
25+
fn introspection_query(b: &mut Bencher) {
26+
let database = Database::new();
27+
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
28+
29+
let doc = r#"
30+
query IntrospectionQuery {
31+
__schema {
32+
queryType { name }
33+
mutationType { name }
34+
subscriptionType { name }
35+
types {
36+
...FullType
37+
}
38+
directives {
39+
name
40+
description
41+
locations
42+
args {
43+
...InputValue
44+
}
45+
}
46+
}
47+
}
48+
49+
fragment FullType on __Type {
50+
kind
51+
name
52+
description
53+
fields(includeDeprecated: true) {
54+
name
55+
description
56+
args {
57+
...InputValue
58+
}
59+
type {
60+
...TypeRef
61+
}
62+
isDeprecated
63+
deprecationReason
64+
}
65+
inputFields {
66+
...InputValue
67+
}
68+
interfaces {
69+
...TypeRef
70+
}
71+
enumValues(includeDeprecated: true) {
72+
name
73+
description
74+
isDeprecated
75+
deprecationReason
76+
}
77+
possibleTypes {
78+
...TypeRef
79+
}
80+
}
81+
82+
fragment InputValue on __InputValue {
83+
name
84+
description
85+
type { ...TypeRef }
86+
defaultValue
87+
}
88+
89+
fragment TypeRef on __Type {
90+
kind
91+
name
92+
ofType {
93+
kind
94+
name
95+
ofType {
96+
kind
97+
name
98+
ofType {
99+
kind
100+
name
101+
ofType {
102+
kind
103+
name
104+
ofType {
105+
kind
106+
name
107+
ofType {
108+
kind
109+
name
110+
ofType {
111+
kind
112+
name
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
121+
"#;
122+
123+
b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
124+
}
125+
126+
benchmark_group!(queries, query_type_name, introspection_query);
127+
benchmark_main!(queries);

examples/warp_async/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl User {
4343
}
4444
}
4545

46-
struct Query;
46+
struct Query;
4747

4848
#[juniper::object(Context = Context)]
4949
impl Query {

juniper/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
- No changes yet
44

5+
# [[0.14.1] 2019-10-24](https://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.1)
6+
7+
- Fix panic when an invalid scalar is used by a client [#434](https://github.com/graphql-rust/juniper/pull/434)
8+
- `EmptyMutation` now implements `Send` [#443](https://github.com/graphql-rust/juniper/pull/443)
9+
510
# [[0.14.0] 2019-09-29](https://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.0)
611

712
- Require `url` 2.x if `url` feature is enabled.

juniper/Cargo.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "juniper"
3-
version = "0.14.0"
3+
version = "0.14.1"
44
authors = [
55
"Magnus Hallin <[email protected]>",
66
"Christoph Herzog <[email protected]>",
@@ -33,20 +33,19 @@ default = [
3333
]
3434

3535
[dependencies]
36-
juniper_codegen = { version = "0.14.0", path = "../juniper_codegen" }
36+
juniper_codegen = { version = "0.14.1", path = "../juniper_codegen" }
3737

38+
async-trait = "0.1.16"
39+
chrono = { version = "0.4.0", optional = true }
3840
fnv = "1.0.3"
41+
futures-preview = { version = "=0.3.0-alpha.19", optional = true }
3942
indexmap = { version = "1.0.0", features = ["serde-1"] }
4043
serde = { version = "1.0.8" }
4144
serde_derive = { version = "1.0.2" }
42-
43-
chrono = { version = "0.4.0", optional = true }
4445
serde_json = { version="1.0.2", optional = true }
4546
url = { version = "2", optional = true }
4647
uuid = { version = "0.7", optional = true }
4748

48-
futures-preview = { version = "=0.3.0-alpha.19", optional = true }
49-
5049
[dev-dependencies]
5150
bencher = "0.1.2"
5251
serde_json = { version = "1.0.2" }

juniper/src/executor/mod.rs

-14
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,6 @@ impl<S> FieldError<S> {
210210
/// The result of resolving the value of a field of type `T`
211211
pub type FieldResult<T, S = DefaultScalarValue> = Result<T, FieldError<S>>;
212212

213-
/*
214-
pub enum ResolvedValue<'a, S = DefaultScalarValue> {
215-
Value(Value<S>),
216-
Future(crate::BoxFuture<'a, Value<S>>),
217-
}
218-
219-
impl<'a, S> From<Value<S>> for ResolvedValue<'a, S> {
220-
#[inline]
221-
fn from(value: Value<S>) -> Self {
222-
ResolvedValue::Value(value)
223-
}
224-
}
225-
*/
226-
227213
/// The result of resolving an unspecified field
228214
pub type ExecutionResult<S = DefaultScalarValue> = Result<Value<S>, FieldError<S>>;
229215

juniper/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected.
8888
[chrono]: https://crates.io/crates/chrono
8989
9090
*/
91-
#![doc(html_root_url = "https://docs.rs/juniper/0.14.0")]
91+
#![doc(html_root_url = "https://docs.rs/juniper/0.14.1")]
9292
#![warn(missing_docs)]
9393

9494
#[doc(hidden)]

juniper/src/macros/common.rs

-19
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,6 @@ macro_rules! __juniper_insert_generic {
9696
};
9797
}
9898

99-
// TODO: remove me.
100-
#[doc(hidden)]
101-
#[macro_export]
102-
macro_rules! __juniper_extract_generic {
103-
(<$name:ident>) => {
104-
$name
105-
};
106-
(
107-
<$generic:tt $(: $bound: tt)*>
108-
) => {
109-
$generic
110-
};
111-
(
112-
$scalar: ty
113-
) => {
114-
$scalar
115-
};
116-
}
117-
11899
#[doc(hidden)]
119100
#[macro_export]
120101
macro_rules! __juniper_parse_object_header {

juniper/src/macros/scalar.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,16 @@ macro_rules! graphql_scalar {
423423
)
424424
{
425425

426-
fn resolve_async<'a>(
426+
fn resolve_async<'a, 'async_trait>(
427427
&'a self,
428428
info: &'a Self::TypeInfo,
429-
selection_set: Option<&'a [$crate::Selection<$crate::__juniper_insert_generic!($($scalar)+)>]>,
430-
executor: &'a $crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
431-
) -> futures::future::BoxFuture<'a, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>> {
429+
selection_set: Option<&'a [$crate::Selection<'a, $crate::__juniper_insert_generic!($($scalar)+)>]>,
430+
executor: &'a $crate::Executor<'a, Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
431+
) -> futures::future::BoxFuture<'async_trait, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>>
432+
where
433+
'a: 'async_trait,
434+
Self: 'async_trait,
435+
{
432436
use $crate::GraphQLType;
433437
use futures::future;
434438
let v = self.resolve(info, selection_set, executor);

juniper/src/macros/tests/args.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ impl Root {
7373
0
7474
}
7575

76-
// TODO: enable once [RFC 2565](https://github.com/rust-lang/rust/issues/60406) is implemented
77-
// fn attr_arg_descr(#[doc = "The arg"] arg: i32) -> i32 { 0 }
78-
// fn attr_arg_descr_collapse(
79-
// #[doc = "The arg"]
80-
// #[doc = "and more details"]
81-
// arg: i32,
82-
// ) -> i32 { 0 }
76+
// TODO: enable once [parameter attributes are supported by proc macros]
77+
// (https://github.com/graphql-rust/juniper/pull/441)
78+
// fn attr_arg_descr(
79+
// #[graphql(description = "The arg")]
80+
// arg: i32) -> i32
81+
// { 0 }
82+
// fn attr_arg_descr_collapse(
83+
// #[graphql(description = "The first arg")]
84+
// #[graphql(description = "and more details")]
85+
// arg: i32,
86+
// ) -> i32 { 0 }
8387

8488
#[graphql(arguments(arg(default = 123,),))]
8589
fn arg_with_default(arg: i32) -> i32 {
@@ -559,7 +563,8 @@ fn introspect_field_multi_args_descr_trailing_comma() {
559563
});
560564
}
561565

562-
// TODO: enable once [RFC 2565](https://github.com/rust-lang/rust/issues/60406) is implemented
566+
// TODO: enable once [parameter attributes are supported by proc macros]
567+
// (https://github.com/graphql-rust/juniper/pull/441)
563568
// #[test]
564569
// fn introspect_field_attr_arg_descr() {
565570
// run_args_info_query("attrArgDescr", |args| {
@@ -593,7 +598,8 @@ fn introspect_field_multi_args_descr_trailing_comma() {
593598
// });
594599
// }
595600

596-
// TODO: enable once [RFC 2565](https://github.com/rust-lang/rust/issues/60406) is implemented
601+
// TODO: enable once [parameter attributes are supported by proc macros]
602+
// (https://github.com/graphql-rust/juniper/pull/441)
597603
// #[test]
598604
// fn introspect_field_attr_arg_descr_collapse() {
599605
// run_args_info_query("attrArgDescrCollapse", |args| {

juniper/src/parser/parser.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub enum ParseError<'a> {
1313

1414
/// An error during tokenization occurred
1515
LexerError(LexerError),
16+
17+
/// A scalar of unexpected type occurred in the source
18+
ExpectedScalarError(&'static str),
1619
}
1720

1821
#[doc(hidden)]
@@ -196,6 +199,7 @@ impl<'a> fmt::Display for ParseError<'a> {
196199
ParseError::UnexpectedToken(ref token) => write!(f, "Unexpected \"{}\"", token),
197200
ParseError::UnexpectedEndOfFile => write!(f, "Unexpected end of input"),
198201
ParseError::LexerError(ref err) => err.fmt(f),
202+
ParseError::ExpectedScalarError(err) => err.fmt(f),
199203
}
200204
}
201205
}

juniper/src/parser/tests/document.rs

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
},
55
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
66
schema::model::SchemaType,
7+
types::scalars::EmptyMutation,
78
validation::test_harness::{MutationRoot, QueryRoot},
89
value::{DefaultScalarValue, ScalarRefValue, ScalarValue},
910
};
@@ -145,3 +146,23 @@ fn errors() {
145146
)
146147
);
147148
}
149+
150+
#[test]
151+
fn issue_427_panic_is_not_expected() {
152+
struct QueryWithoutFloat;
153+
154+
#[crate::object_internal]
155+
impl QueryWithoutFloat {
156+
fn echo(value: String) -> String {
157+
value
158+
}
159+
}
160+
161+
let schema = SchemaType::new::<QueryWithoutFloat, EmptyMutation<()>>(&(), &());
162+
let parse_result = parse_document_source(r##"{ echo(value: 123.0) }"##, &schema);
163+
164+
assert_eq!(
165+
parse_result.unwrap_err().item,
166+
ParseError::ExpectedScalarError("There needs to be a Float type")
167+
);
168+
}

0 commit comments

Comments
 (0)