Skip to content
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

Merged
merged 3 commits into from
Jan 23, 2023

Conversation

goto-bus-stop
Copy link
Member

@goto-bus-stop goto-bus-stop commented Jan 20, 2023

Noticed a small improvement opportunity while merging main into #414

OperationType already has a Display impl, so we don't actually need a separate Into<String>: users can do ty.to_string() and it will use Display.

DirectiveLocation also has a Into<String> impl. If we use a Display impl instead, we can print DirectiveLocations directly in format strings. Then we can also just stick the DirectiveLocation value into our diagnostics, instead of stringifying them first, which makes the diagnostic more programmatically useful.


#[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)]
Copy link
Member Author

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"

Copy link
Member Author

@goto-bus-stop goto-bus-stop Jan 20, 2023

Choose a reason for hiding this comment

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

I guess the thing is that the label is more visually prominent than the "main" error message, and our "main" message contains the important information.
image

Copy link
Member

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!

Comment on lines -320 to -331
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()
}
}
}

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 removing this is technically a breaking change eh?

Copy link
Member Author

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

Copy link
Member

@lrlna lrlna left a 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!

@goto-bus-stop goto-bus-stop merged commit 631896e into main Jan 23, 2023
@goto-bus-stop goto-bus-stop deleted the display-directive-location branch January 23, 2023 08:44
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.

2 participants