Skip to content

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

Merged
merged 11 commits into from
Jun 14, 2017
Merged

Drop Rustc Serialization Support #43

merged 11 commits into from
Jun 14, 2017

Conversation

TheServerAsterisk
Copy link
Contributor

@TheServerAsterisk TheServerAsterisk commented Apr 25, 2017

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.


use ::{InputValue, GraphQLType, RootNode, Variables, execute};
use ::{InputValue, GraphQLType, RootNode, Variables, execute as execute_query};
Copy link
Contributor Author

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.


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.");
Copy link
Contributor Author

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.

Copy link
Member

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.

/// Converts serde_json::Value to juniper::InputValue
pub fn from_json(json: Json) -> InputValue {
match json {
Json::Number(num) => {
Copy link
Contributor Author

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.

Copy link
Member

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)
}

if k == "query" {
query = serde_json::to_string(&v)
.ok()
.map(|query| query.replace("\"", ""));
Copy link
Contributor Author

@TheServerAsterisk TheServerAsterisk Apr 25, 2017

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.

Copy link
Member

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}}?

@TheServerAsterisk
Copy link
Contributor Author

@mhallin I made the appropriate changes, let me know if you want anythings else to be altered.

@TheServerAsterisk TheServerAsterisk changed the title WIP: Drop rustc serialization Drop rustc serialization May 4, 2017
@TheServerAsterisk TheServerAsterisk changed the title Drop rustc serialization Drop Rustc Serialization Support May 4, 2017
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 =
Copy link
Contributor

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

Copy link
Contributor Author

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.


impl InputValue {
/// Converts serde_json::Value to juniper::InputValue
pub fn from_json(json: Json) -> InputValue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheServerAsterisk
Copy link
Contributor Author

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.

@theduke
Copy link
Member

theduke commented May 15, 2017

I'd vote for just dropping older Rust versions.

@mhallin
Copy link
Member

mhallin commented May 18, 2017

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.

@norcalli
Copy link

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.

@mhallin mhallin merged commit 80de43e into graphql-rust:master Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop rustc-serialize support
5 participants