-
Notifications
You must be signed in to change notification settings - Fork 45
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
chore(compiler): use Display impls for OperationType, DirectiveLocation #435
Conversation
|
||
#[source_code] | ||
pub src: Arc<str>, | ||
|
||
#[label("{} is not a valid location", self.dir_loc)] | ||
#[label("{} is not a valid location for this directive", self.dir_loc)] |
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.
didn't catch this in review earlier but I think this message could be improved a bit … maybe something like "cannot use directive @xyz
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.
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.
oh yea this is nicer ty!
crates/apollo-compiler/test_data/diagnostics/0050_directives_in_invalid_locations.txt
Show resolved
Hide resolved
impl From<OperationType> for String { | ||
fn from(op_type: OperationType) -> Self { | ||
if op_type.is_subscription() { | ||
"Subscription".to_string() | ||
} else if op_type.is_mutation() { | ||
"Mutation".to_string() | ||
} else { | ||
"Query".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.
i think removing this is technically a breaking change eh?
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.
Yes you can no longer do op_type.into()
, you have to do op_type.to_string()
instead. So very minor but breaking nonetheless
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.
looks good, thank you!
Noticed a small improvement opportunity while merging
main
into #414…OperationType
already has aDisplay
impl, so we don't actually need a separateInto<String>
: users can doty.to_string()
and it will useDisplay
.DirectiveLocation
also has aInto<String>
impl. If we use aDisplay
impl instead, we can printDirectiveLocation
s directly in format strings. Then we can also just stick theDirectiveLocation
value into our diagnostics, instead of stringifying them first, which makes the diagnostic more programmatically useful.