Skip to content

Commit 5f17d0b

Browse files
committed
Fix errors indroduced by the rebase
1 parent b762d4e commit 5f17d0b

File tree

20 files changed

+330
-205
lines changed

20 files changed

+330
-205
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ members = [
66
"juniper_hyper",
77
"juniper_iron",
88
"juniper_rocket",
9+
"juniper_warp",
10+
"juniper_warp/examples/warp_server/",
911
]

juniper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ expose-test-schema = []
2828
default = [
2929
"chrono",
3030
"url",
31-
"uuid"
31+
"uuid",
3232
]
3333

3434
[dependencies]

juniper/src/integrations/serde.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,10 @@ where
394394
mod tests {
395395
use super::{ExecutionError, GraphQLError};
396396
use ast::InputValue;
397-
use executor::ExecutionError;
398397
use serde_json::from_str;
399398
use serde_json::to_string;
400-
use {FieldError, Value};
401399
use value::{DefaultScalarValue, Object};
400+
use {FieldError, Value};
402401

403402
#[test]
404403
fn int() {
@@ -431,8 +430,8 @@ mod tests {
431430

432431
#[test]
433432
fn error_extensions() {
434-
let mut obj = Object::with_capacity(1);
435-
obj.add_field("foo".to_string(), Value::String("bar".to_string()));
433+
let mut obj: Object<DefaultScalarValue> = Object::with_capacity(1);
434+
obj.add_field("foo".to_string(), Value::scalar("bar"));
436435
assert_eq!(
437436
to_string(&ExecutionError::at_origin(FieldError::new(
438437
"foo error",

juniper/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ where
211211
MutationT: GraphQLType<S, Context = CtxT>,
212212
{
213213
let document = parse_document_source(document_source, &root_node.schema)?;
214-
215214
{
216215
let errors = validate_input_values(variables, &document, &root_node.schema);
217216

juniper/src/macros/interface.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ macro_rules! graphql_interface {
147147
)*
148148
let fields = &[$(
149149
registry.field_convert::<$return_ty, _, Self::Context>(
150-
&$crate::to_camel_case(stringify!($fn_name)),
150+
&$crate::to_camel_case(__graphql__stringify!($fn_name)),
151151
info
152152
)
153153
$(.description($fn_description))*
@@ -180,13 +180,13 @@ macro_rules! graphql_interface {
180180
executor: &$crate::Executor<Self::Context, __juniper_insert_generic!($($scalar)+)>
181181
) -> $crate::ExecutionResult<__juniper_insert_generic!($($scalar)+)> {
182182
$(
183-
if field == &$crate::to_camel_case(stringify!($fn_name)) {
183+
if field == &$crate::to_camel_case(__graphql__stringify!($fn_name)) {
184184
let result: $return_ty = (|| {
185185
$(
186186
let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(stringify!($arg_name)))
187-
.expect(concat!(
187+
.expect(__graphql__concat!(
188188
"Argument ",
189-
stringify!($arg_name),
189+
__graphql__stringify!($arg_name),
190190
" missing - validation must have failed"
191191
));
192192
)*
@@ -209,7 +209,7 @@ macro_rules! graphql_interface {
209209
}
210210
)*
211211

212-
panic!("Field {} not found on type {}", field, $($outname)*)
212+
__graphql__panic!("Field {} not found on type {}", field, $($outname)*)
213213
}
214214

215215
#[allow(unused_variables)]
@@ -223,7 +223,7 @@ macro_rules! graphql_interface {
223223
}
224224
)*
225225

226-
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
226+
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
227227
}
228228

229229
fn resolve_into_type(
@@ -241,7 +241,7 @@ macro_rules! graphql_interface {
241241
}
242242
)*
243243

244-
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
244+
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
245245
}
246246
}
247247
);
@@ -265,7 +265,7 @@ macro_rules! graphql_interface {
265265
};
266266

267267
(@$($stuff:tt)*) => {
268-
compile_error!("Invalid syntax for `graphql_interface!`");
268+
__graphql__compile_error!("Invalid syntax for `graphql_interface!`");
269269
};
270270

271271
(

juniper/src/macros/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ macro_rules! __graphql__stringify {
1414

1515
#[doc(hidden)]
1616
#[macro_export]
17-
macro_rules! __graphql__vec {
18-
($($t:tt)*) => ( vec!($($t)*) );
17+
macro_rules! __graphql__concat {
18+
($($t:tt)*) => ( concat!($($t)*) );
19+
}
20+
21+
#[doc(hidden)]
22+
#[macro_export]
23+
macro_rules! __graphql__compile_error {
24+
($t:expr) => ( compile_error!($t) );
1925
}
2026

2127
#[macro_use]

juniper/src/macros/object.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ macro_rules! graphql_object {
321321
{
322322
let fields = &[$(
323323
registry.field_convert::<$return_ty, _, Self::Context>(
324-
&$crate::to_camel_case(stringify!($fn_name)),
324+
&$crate::to_camel_case(__graphql__stringify!($fn_name)),
325325
info
326326
)
327327
$(.description($fn_description))*
@@ -360,13 +360,13 @@ macro_rules! graphql_object {
360360
executor: &$crate::Executor<Self::Context, __juniper_insert_generic!($($scalar)+)>
361361
) -> $crate::ExecutionResult<__juniper_insert_generic!($($scalar)+)> {
362362
$(
363-
if field == &$crate::to_camel_case(stringify!($fn_name)) {
363+
if field == &$crate::to_camel_case(__graphql__stringify!($fn_name)) {
364364
let result: $return_ty = (|| {
365365
$(
366-
let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(stringify!($arg_name)))
367-
.expect(concat!(
366+
let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(__graphql__stringify!($arg_name)))
367+
.expect(__graphql__concat!(
368368
"Argument ",
369-
stringify!($arg_name),
369+
__graphql__stringify!($arg_name),
370370
" missing - validation must have failed"
371371
));
372372
)*
@@ -389,7 +389,7 @@ macro_rules! graphql_object {
389389
}
390390
)*
391391

392-
panic!("Field {} not found on type {}", field, $($outname)*);
392+
__graphql__panic!("Field {} not found on type {}", field, $($outname)*);
393393
}
394394
}
395395
);
@@ -472,7 +472,7 @@ macro_rules! graphql_object {
472472
};
473473

474474
(@$($stuff:tt)*) => {
475-
compile_error!("Invalid syntax for `graphql_object!`");
475+
__graphql__compile_error!("Invalid syntax for `graphql_object!`");
476476
};
477477

478478
(

juniper/src/macros/scalar.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ macro_rules! graphql_scalar {
5959
resolve = {
6060
self_var = $resolve_self_var:ident,
6161
body = $resolve_body: block,
62+
return_type = $resolve_retun_type: ty,
6263
},
6364
from_input_value = {
6465
arg = $from_input_value_arg: ident,
@@ -134,12 +135,6 @@ macro_rules! graphql_scalar {
134135
}
135136
}
136137
);
137-
138-
impl $crate::FromInputValue for $name {
139-
fn from_input_value($fiv_arg: &$crate::InputValue) -> $fiv_result {
140-
$fiv_body
141-
}
142-
}
143138
};
144139

145140
// No more items to parse
@@ -182,7 +177,7 @@ macro_rules! graphql_scalar {
182177
$(from_str = {$($from_str_body:tt)+})*,
183178
rest =
184179
) => {
185-
compile_error!("Missing resolve function");
180+
__graphql__compile_error!("Missing resolve function");
186181
};
187182

188183
(
@@ -197,7 +192,7 @@ macro_rules! graphql_scalar {
197192
$(from_str = {$($from_str_body:tt)+})*,
198193
rest =
199194
) => {
200-
compile_error!("Missing from_input_value function");
195+
__graphql__compile_error!("Missing from_input_value function");
201196
};
202197

203198
(
@@ -212,7 +207,7 @@ macro_rules! graphql_scalar {
212207
from_input_value = {$($from_input_value_body:tt)+},
213208
rest =
214209
) =>{
215-
compile_error!("Missing from_str function");
210+
__graphql__compile_error!("Missing from_str function");
216211
};
217212

218213

@@ -223,14 +218,15 @@ macro_rules! graphql_scalar {
223218
$(resolve = {$($resolve_body:tt)+},)*
224219
$(from_input_value = {$($from_input_value_body:tt)+},)*
225220
$(from_str = {$($from_str_body:tt)+},)*
226-
rest = resolve(&$selfvar:ident) -> Value $body:block $($rest:tt)*
221+
rest = resolve(&$selfvar:ident) -> $return_ty:ty $body:block $($rest:tt)*
227222
) => {
228223
graphql_scalar!(
229224
@parse_functions,
230225
meta = {$($meta)*},
231226
resolve = {
232227
self_var = $selfvar,
233228
body = $body,
229+
return_type = $return_ty,
234230
},
235231
$(from_input_value = {$($from_input_value_body)+},)*
236232
$(from_str = {$($from_str_body)+},)*
@@ -335,7 +331,7 @@ macro_rules! graphql_scalar {
335331
};
336332

337333
(@$($stuff:tt)*) => {
338-
compile_error!("Invalid syntax for `graphql_scalar!`");
334+
__graphql__compile_error!("Invalid syntax for `graphql_scalar!`");
339335
};
340336

341337
($($rest:tt)*) => {

juniper/src/macros/tests/scalar.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,18 @@ where
112112
#[test]
113113
fn path_in_resolve_return_type() {
114114
struct ResolvePath(i32);
115+
115116
graphql_scalar!(ResolvePath {
116117
resolve(&self) -> self::Value {
117-
Value::int(self.0)
118+
Value::scalar(self.0)
118119
}
119120

120121
from_input_value(v: &InputValue) -> Option<ResolvePath> {
121-
v.as_int_value().map(|i| ResolvePath(i))
122+
v.as_scalar_value().map(|i: &i32| ResolvePath(*i))
123+
}
124+
125+
from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a> {
126+
<i32 as ParseScalarValue>::from_str(value)
122127
}
123128
});
124129
}

juniper/src/macros/union.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ macro_rules! graphql_union {
8383
}
8484
)*
8585

86-
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
86+
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
8787
}
8888

8989
fn resolve_into_type(
@@ -101,7 +101,7 @@ macro_rules! graphql_union {
101101
}
102102
)*
103103

104-
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
104+
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
105105
}
106106
}
107107
);
@@ -125,7 +125,7 @@ macro_rules! graphql_union {
125125
);
126126
};
127127
(@$($stuff:tt)*) => {
128-
compile_error!("Invalid syntax for `graphql_union!`");
128+
__graphql__compile_error!("Invalid syntax for `graphql_union!`");
129129
};
130130

131131
($($rest: tt)*) => {

juniper/src/validation/input_value.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use parser::SourcePosition;
77
use schema::meta::{EnumMeta, InputObjectMeta, MetaType, ScalarMeta};
88
use schema::model::{SchemaType, TypeType};
99
use validation::RuleError;
10-
use value::{ScalarValue, ScalarRefValue};
10+
use value::{ScalarRefValue, ScalarValue};
1111

1212
#[derive(Debug)]
1313
enum Path<'a> {
@@ -23,7 +23,7 @@ pub fn validate_input_values<S>(
2323
) -> Vec<RuleError>
2424
where
2525
S: ScalarValue,
26-
for<'b> &'b S: ScalarRefValue<'b>
26+
for<'b> &'b S: ScalarRefValue<'b>,
2727
{
2828
let mut errs = vec![];
2929

@@ -46,7 +46,7 @@ fn validate_var_defs<S>(
4646
errors: &mut Vec<RuleError>,
4747
) where
4848
S: ScalarValue,
49-
for<'b> &'b S: ScalarRefValue<'b>
49+
for<'b> &'b S: ScalarRefValue<'b>,
5050
{
5151
for &(ref name, ref def) in var_defs.iter() {
5252
let raw_type_name = def.var_type.item.innermost_name();
@@ -85,10 +85,10 @@ fn unify_value<'a, S>(
8585
meta_type: &TypeType<'a, S>,
8686
schema: &SchemaType<S>,
8787
path: Path<'a>,
88-
) -> Vec<RuleError>
89-
where
88+
) -> Vec<RuleError>
89+
where
9090
S: ScalarValue,
91-
for<'b> &'b S: ScalarRefValue<'b>
91+
for<'b> &'b S: ScalarRefValue<'b>,
9292
{
9393
let mut errors: Vec<RuleError> = vec![];
9494

@@ -173,7 +173,7 @@ fn unify_scalar<'a, S>(
173173
value: &InputValue<S>,
174174
meta: &ScalarMeta<S>,
175175
path: &Path<'a>,
176-
) -> Vec<RuleError>
176+
) -> Vec<RuleError>
177177
where
178178
S: fmt::Debug,
179179
{
@@ -212,15 +212,26 @@ fn unify_enum<'a, S>(
212212
value: &InputValue<S>,
213213
meta: &EnumMeta<S>,
214214
path: &Path<'a>,
215-
) -> Vec<RuleError>
215+
) -> Vec<RuleError>
216216
where
217217
S: ScalarValue,
218-
for<'b> &'b S: ScalarRefValue<'b>
218+
for<'b> &'b S: ScalarRefValue<'b>,
219219
{
220220
let mut errors: Vec<RuleError> = vec![];
221-
222221
match *value {
223-
InputValue::String(ref name) | InputValue::Enum(ref name) => {
222+
InputValue::Scalar(ref scalar) if scalar.is_type::<String>() => {
223+
if let Some(ref name) = <&S as Into<Option<&String>>>::into(scalar) {
224+
if !meta.values.iter().any(|ev| &ev.name == *name) {
225+
errors.push(unification_error(
226+
var_name,
227+
var_pos,
228+
path,
229+
&format!(r#"Invalid value for enum "{}""#, meta.name),
230+
))
231+
}
232+
}
233+
}
234+
InputValue::Enum(ref name) => {
224235
if !meta.values.iter().any(|ev| &ev.name == name) {
225236
errors.push(unification_error(
226237
var_name,
@@ -247,10 +258,10 @@ fn unify_input_object<'a, S>(
247258
meta: &InputObjectMeta<S>,
248259
schema: &SchemaType<S>,
249260
path: &Path<'a>,
250-
) -> Vec<RuleError>
261+
) -> Vec<RuleError>
251262
where
252263
S: ScalarValue,
253-
for<'b> &'b S: ScalarRefValue<'b>
264+
for<'b> &'b S: ScalarRefValue<'b>,
254265
{
255266
let mut errors: Vec<RuleError> = vec![];
256267

0 commit comments

Comments
 (0)