Fix #[Object] macro panic with default u32. #361
This commit is contained in:
parent
6b10e90de0
commit
8f32e8e81e
|
@ -309,11 +309,11 @@ fn generate_default_value(lit: &Lit) -> GeneratorResult<TokenStream> {
|
||||||
}
|
}
|
||||||
Lit::Int(value) => {
|
Lit::Int(value) => {
|
||||||
let value = value.base10_parse::<i32>()?;
|
let value = value.base10_parse::<i32>()?;
|
||||||
Ok(quote!({ #value as ::std::primitive::i32 }))
|
Ok(quote!({ ::std::convert::TryInto::try_into(#value).unwrap() }))
|
||||||
}
|
}
|
||||||
Lit::Float(value) => {
|
Lit::Float(value) => {
|
||||||
let value = value.base10_parse::<f64>()?;
|
let value = value.base10_parse::<f64>()?;
|
||||||
Ok(quote!({ #value as ::std::primitive::f64 }))
|
Ok(quote!({ ::std::convert::TryInto::try_into(#value) }))
|
||||||
}
|
}
|
||||||
Lit::Bool(value) => {
|
Lit::Bool(value) => {
|
||||||
let value = value.value;
|
let value = value.value;
|
||||||
|
|
|
@ -17,9 +17,13 @@ pub async fn test_default_value_arg() {
|
||||||
async fn value3(&self, #[graphql(default_with = "1 + 2 + 3")] input: i32) -> i32 {
|
async fn value3(&self, #[graphql(default_with = "1 + 2 + 3")] input: i32) -> i32 {
|
||||||
input
|
input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn value4(&self, #[graphql(default = 100)] input: u32) -> u32 {
|
||||||
|
input
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query = "{ value1 value2 value3 }";
|
let query = "{ value1 value2 value3 value4 }";
|
||||||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
schema.execute(query).await.data,
|
schema.execute(query).await.data,
|
||||||
|
@ -27,6 +31,7 @@ pub async fn test_default_value_arg() {
|
||||||
"value1": 100,
|
"value1": 100,
|
||||||
"value2": 0,
|
"value2": 0,
|
||||||
"value3": 6,
|
"value3": 6,
|
||||||
|
"value4": 100,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user