-
Notifications
You must be signed in to change notification settings - Fork 434
Drop Rustc Serialization Support #43
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
Drop Rustc Serialization Support #43
Conversation
src/integrations/iron_handlers.rs
Outdated
|
||
use ::{InputValue, GraphQLType, RootNode, Variables, execute}; | ||
use ::{InputValue, GraphQLType, RootNode, Variables, execute as execute_query}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name of this in order to clarify the difference between the execute function that exists in the iron_handlers file vs the execute function that resides in the lib.rs file.
src/integrations/iron_handlers.rs
Outdated
|
||
match result { | ||
Ok((result, errors)) => { | ||
map.insert("data".to_owned(), result.to_json()); | ||
let response_data = serde_json::to_value(result) | ||
.expect("Failed to convert response data to JSON."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure how you, @mhallin, wanted handed handle errors at this points especially since the response has probably been parsed already and should only fail if the developer messes up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if things fail here the only way out is to fail - whether through a clean exit or a panic which Iron will handle anyway doesn't really matter.
src/integrations/serde.rs
Outdated
/// Converts serde_json::Value to juniper::InputValue | ||
pub fn from_json(json: Json) -> InputValue { | ||
match json { | ||
Json::Number(num) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Serde doesn't have I64 etc but just a general number it is unclear whether u64 should be converted to an i64 as well. Please note if you want me to handle this case differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've got two options: either add u64
to InputValue
and Value
, or convert it to either i64
or f64
if it's larger than i64::MAX
.
BTW, I think it would be cleaner if this code read like:
if let Some(num) = num.as_i64() {
InputValue::int(num)
}
else if let Some(num) = num.as_f64() {
InputValue::float(num)
}
src/integrations/iron_handlers.rs
Outdated
if k == "query" { | ||
query = serde_json::to_string(&v) | ||
.ok() | ||
.map(|query| query.replace("\"", "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sede_json::to_string will convert the query value to something like this. "\"{hero{name}}\"" thus the need to replace it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a case of double encoding - what happens if you send {droid(id: "1001"){name}}
?
- Added a GraphQlIronError - Changed execute from lib.rs to execute_query
@mhallin I made the appropriate changes, let me know if you want anythings else to be altered. |
src/integrations/iron_handlers.rs
Outdated
query = v.as_string().map(|s| s.to_owned()); | ||
let mut request_payload = String::new(); | ||
itry!(req.body.read_to_string(&mut request_payload)); | ||
let json_data = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section can be simplified by using serde's derive macro for deserialization instead of manually pulling out values, e.g., https://github.com/zaeleus/juniper/blob/a321204cfc8d378fe3d8d9af2c817476cba1211d/examples/rocket/src/graphql.rs#L32-L67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also ended up taking your WrappedGraphQlResult idea and placed both it and the GraphQlQuery into the serde module. Let me know if you have any more suggestions on how to improve the code.
src/integrations/serde.rs
Outdated
|
||
impl InputValue { | ||
/// Converts serde_json::Value to juniper::InputValue | ||
pub fn from_json(json: Json) -> InputValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deserialization is already implemented for InputValue
. Why not use it?
…ait and added a serialization implementation for the graphql result.
…erage the GraphQlQuery struct. Added a couple more tests for get requests.
Ahhh, I forgot serde_derive is only support for rust 1.15 and greater. So I can either drop serde_derive as a dependency and manually implement serialization or support for rust 1.13 and rust 1.14 can be dropped. If the former let me know @mhallin and I will make the appropriate changes. |
I'd vote for just dropping older Rust versions. |
Yeah, I think this is where we drop 1.14 and older :) The reason I let Travis test on older Rust versions is to not accidentally dropping support for older versions. |
From my reading, this seems to be ready. And this would fix Travis failing for the serde 1.0 PR as well, since that was only failing on <=1.14. If this PR is left stale for too long, forks may appear that will cause fragmentation of the codebase. |
This will close #36.
One notable change is the
GraphQlIronError
enum I added. The purpose of this enum was to capture any serde or IO errors and log the error instead of making the thread panic if serde failed or the user failed to put in a valid JSON object.