Skip to content

Commit 09d9513

Browse files
committed
Rebase onto master
1 parent 4834349 commit 09d9513

File tree

21 files changed

+219
-50
lines changed

21 files changed

+219
-50
lines changed

benches/bench.rs

Lines changed: 127 additions & 0 deletions
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);

juniper/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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,7 +33,7 @@ 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

3838
async-trait = "0.1.16"
3939
chrono = { version = "0.4.0", optional = true }

juniper/src/executor/mod.rs

Lines changed: 0 additions & 14 deletions
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

Lines changed: 4 additions & 3 deletions
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)]
@@ -151,6 +151,7 @@ mod executor_tests;
151151
pub use crate::util::to_camel_case;
152152

153153
use crate::{
154+
executor::{execute_validated_query, execute_validated_query_async},
154155
introspection::{INTROSPECTION_QUERY, INTROSPECTION_QUERY_WITHOUT_DESCRIPTIONS},
155156
parser::{parse_document_source, ParseError, Spanning},
156157
validation::{validate_input_values, visit_all_rules, ValidatorContext},
@@ -227,7 +228,7 @@ where
227228
}
228229
}
229230

230-
executor::execute_validated_query(document, operation_name, root_node, variables, context)
231+
execute_validated_query(document, operation_name, root_node, variables, context)
231232
}
232233

233234
/// Execute a query in a provided schema
@@ -267,7 +268,7 @@ where
267268
}
268269
}
269270

270-
executor::execute_validated_query_async(document, operation_name, root_node, variables, context)
271+
execute_validated_query_async(document, operation_name, root_node, variables, context)
271272
.await
272273
}
273274

juniper/src/parser/parser.rs

Lines changed: 4 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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+
}

juniper/src/parser/value.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,33 +210,36 @@ fn parse_scalar_literal_by_infered_type<'a, 'b, S>(
210210
where
211211
S: ScalarValue,
212212
{
213-
match token {
213+
let result = match token {
214214
ScalarToken::String(_) => {
215215
if let Some(&MetaType::Scalar(ref s)) = schema.concrete_type_by_name("String") {
216-
(s.parse_fn)(token)
217-
.map(|s| Spanning::start_end(start, end, InputValue::Scalar(s)))
218-
.map_err(|e| Spanning::start_end(start, end, e))
216+
(s.parse_fn)(token).map(InputValue::Scalar)
219217
} else {
220-
panic!("There needs to be a String type")
218+
Err(ParseError::ExpectedScalarError(
219+
"There needs to be a String type",
220+
))
221221
}
222222
}
223223
ScalarToken::Int(_) => {
224224
if let Some(&MetaType::Scalar(ref s)) = schema.concrete_type_by_name("Int") {
225-
(s.parse_fn)(token)
226-
.map(|s| Spanning::start_end(start, end, InputValue::Scalar(s)))
227-
.map_err(|e| Spanning::start_end(start, end, e))
225+
(s.parse_fn)(token).map(InputValue::Scalar)
228226
} else {
229-
panic!("There needs to be a Int type")
227+
Err(ParseError::ExpectedScalarError(
228+
"There needs to be an Int type",
229+
))
230230
}
231231
}
232232
ScalarToken::Float(_) => {
233233
if let Some(&MetaType::Scalar(ref s)) = schema.concrete_type_by_name("Float") {
234-
(s.parse_fn)(token)
235-
.map(|s| Spanning::start_end(start, end, InputValue::Scalar(s)))
236-
.map_err(|e| Spanning::start_end(start, end, e))
234+
(s.parse_fn)(token).map(InputValue::Scalar)
237235
} else {
238-
panic!("There needs to be a Float type")
236+
Err(ParseError::ExpectedScalarError(
237+
"There needs to be a Float type",
238+
))
239239
}
240240
}
241-
}
241+
};
242+
result
243+
.map(|s| Spanning::start_end(start, end, s))
244+
.map_err(|e| Spanning::start_end(start, end, e))
242245
}

juniper/src/types/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ where
343343
}
344344
}
345345

346-
pub fn resolve_selection_set_into<T, CtxT, S>(
346+
pub(crate) fn resolve_selection_set_into<T, CtxT, S>(
347347
instance: &T,
348348
info: &T::TypeInfo,
349349
selection_set: &[Selection<S>],

juniper/src/types/scalars.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ impl<T> EmptyMutation<T> {
308308
}
309309
}
310310

311+
// This is safe due to never using `T`.
312+
unsafe impl<T> Send for EmptyMutation<T> {}
313+
311314
impl<S, T> GraphQLType<S> for EmptyMutation<T>
312315
where
313316
S: ScalarValue,
@@ -343,7 +346,7 @@ where
343346

344347
#[cfg(test)]
345348
mod tests {
346-
use super::ID;
349+
use super::{EmptyMutation, ID};
347350
use crate::{
348351
parser::ScalarToken,
349352
value::{DefaultScalarValue, ParseScalarValue},
@@ -390,4 +393,10 @@ mod tests {
390393
"unicode \u{1234}\u{5678}\u{90ab}\u{cdef}",
391394
);
392395
}
396+
397+
#[test]
398+
fn empty_mutation_is_send() {
399+
fn check_if_send<T: Send>() {}
400+
check_if_send::<EmptyMutation<()>>();
401+
}
393402
}

juniper/src/value/scalar.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ pub enum DefaultScalarValue {
260260
Boolean(bool),
261261
}
262262

263-
trait S: Send + Sync {}
264-
265263
impl ScalarValue for DefaultScalarValue {
266264
type Visitor = DefaultScalarValueVisitor;
267265

juniper_codegen/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "juniper_codegen"
3-
version = "0.14.0"
3+
version = "0.14.1"
44
authors = [
55
"Magnus Hallin <[email protected]>",
66
"Christoph Herzog <[email protected]>",
@@ -24,7 +24,7 @@ quote = "1.0.2"
2424
proc-macro-error = "0.3.4"
2525

2626
[dev-dependencies]
27-
juniper = { version = "0.14.0", path = "../juniper" }
27+
juniper = { version = "0.14.1", path = "../juniper" }
2828

2929
[badges]
3030
travis-ci = { repository = "graphql-rust/juniper" }

juniper_hyper/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
- Compatibility with the latest `juniper`.
44

5+
# [[0.5.1] 2019-10-24](https://github.com/graphql-rust/juniper/releases/tag/juniper_hyper-0.5.1)
6+
7+
- Compatibility with the latest `juniper`.
8+
59
# [[0.5.0] 2019-09-29](https://github.com/graphql-rust/juniper/releases/tag/juniper_hyper-0.5.0)
610

711
- Compatibility with the latest `juniper`.

0 commit comments

Comments
 (0)