-
Notifications
You must be signed in to change notification settings - Fork 273
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
fix: indent and commas #101
Conversation
While formatting .graphql files, my linter added commas and newlines around. Although this is allowed in the spec, and the parser handles it correctly, we weren't able to handle it when gathering endpoint names and urls. This commits fixes this, and adds various indents and commas in the routing_urls test.
marking it back as draft, until apollo-rs provides us with a nice api that avoids the temporary workaround :) |
let arg_value = | ||
argument.value().and_then(|s| { | ||
s.to_string() | ||
.trim_end() | ||
.strip_prefix('"') | ||
.and_then(|s| s.strip_suffix('"')) | ||
.map(|s| s.to_owned()) | ||
// This is a temporary workaround until we have nice semantic analysis | ||
s.syntax() | ||
.green() | ||
.children() | ||
.next() | ||
.and_then(|it| it.into_token()) | ||
.map(|token| { | ||
token | ||
.text() | ||
.trim() | ||
.trim_start_matches('"') | ||
.trim_end_matches('"') | ||
.trim() | ||
.to_string() | ||
}) | ||
}); |
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.
if you update to the latest apollo-rs
commit you can get the STRING_VALUE as rust's String
type:
if let ast::Value::StringValue(val) =
argument.value().expect("Cannot get argument value.")
{
let s: String = val.into();
}
It should help you eliminate this green node manipulation happening here.
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.
^ It is still preferable that you match on the variants of argument.value()
, as not all variants implement casting to native rust types (they are not likely to in the future either).
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.
it works! 🙌 thank you! 🚀
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.
ahhh very nice! i like the way this looks.
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.
LGTM though I don't have opinion on styling XD
While formatting .graphql files, my linter added commas and newlines around. Although this is allowed in the spec, and the parser handles it correctly, we weren't able to handle it when gathering endpoint names and urls.
This commits fixes this, and adds various indents and commas in the routing_urls test.