-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Do not allow users to apply fold, recurse and transform directives to properties #457
Conversation
trustfall_core/test_data/tests/frontend_errors/transform_used_on_property.frontend-error.ron
Outdated
Show resolved
Hide resolved
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.
Nice work! Uncovered a bit of a design question in the process, which I'm sure should be possible to overcome without too much trouble.
trustfall_core/src/frontend/error.rs
Outdated
#[error( | ||
"The field \"{0}\" is a property but the query uses @fold.\ | ||
Only edges can be used with @fold." | ||
)] | ||
FoldOnProperty(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.
A few questions here. I genuinely don't know the answer to these off the top of my head, but we probably want to consider them so as to make consistent and intuitive choices:
- What error does the frontend raise for other edge-only directives (
@optional
/@recurse
) is used on a property? (Not sure if we already have test cases for these, but we should add them if we don't!) - Would it make sense to use a more general variant for all such directives that are invalid on properties, like a
UnsupportedDirectiveOnProperty
? (Name subject to workshopping, open to ideas.)
Also, a couple of nits:
- We are not guaranteeing enum variant order, so let's try to group this variant near other variants for related errors instead.
- The error message is a bit unclear: for example, it only says that
@fold
was used by never says the actual problem — that it was used by applying it to a property. The existing error messages here are also not good, but good diagnostics are super important so we should try to start raising the quality bar if at all possible.
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.
What error does the frontend raise for other edge-only directives (
@optional
/@recurse
) is used on a property? (Not sure if we already have test cases for these, but we should add them if we don't!)
Unless the playground is outdated and validations were added after, those do not raise any errors. So it feels like this change should include those directives as well and use naming like you proposed (UnsupportedDirectiveOnProperty
)
We are not guaranteeing enum variant order, so let's try to group this variant near other variants for related errors instead.
The error message is a bit unclear: for example, it only says that@fold
was used by never says the actual problem — that it was used by applying it to a property. The existing error messages here are also not good, but good diagnostics are super important so we should try to start raising the quality bar if at all possible.
I will send out a version with a little better wording, but I will sleep on it to see if I can improve 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.
I don't think any validations have been added in a while. Oops! Great catch, thanks for finding this!
trustfall_core/test_data/tests/frontend_errors/transform_used_on_property.frontend-error.ron
Outdated
Show resolved
Hide resolved
@@ -1104,6 +1103,30 @@ where | |||
{ | |||
// Processing a property. | |||
|
|||
// @fold is not allowed on a property | |||
if connection.fold.is_some() { |
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 is some code duplication around here, but at least the signatures I thought about would keep things highly coupled with the context of this method. So I kept the code duplication because I thought it was the cleaner version of the code. Let me know if you have ideas for making this better.
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 is totally fine. Not all duplication is bad, and in this case the duplicated code is fairly short and very clear. Anything less duplicated would be way more convoluted and less readable.
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 looks great, I'd be happy to merge as soon as the fix for that one test case is in 🎉
@@ -1104,6 +1103,30 @@ where | |||
{ | |||
// Processing a property. | |||
|
|||
// @fold is not allowed on a property | |||
if connection.fold.is_some() { |
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 is totally fine. Not all duplication is bad, and in this case the duplicated code is fairly short and very clear. Anything less duplicated would be way more convoluted and less readable.
trustfall_core/test_data/tests/frontend_errors/recurse_used_on_property.graphql.ron
Outdated
Show resolved
Hide resolved
…_property.graphql.ron Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Also remember to update the PR title and description to include the other directives being handled! |
Ah the failing lints are because we got a new Rust stable today. I'll push a fix real quick, sorry about that. |
Ah thanks for clarifying, I was almost rolling back the last changes to see if the problem would remain :D |
Marked for merge as soon as CI approves! 🎉 Have you already picked out the next thing to tackle, or would you like some ideas for things to look at? Assuming you still have time to contribute, of course no pressure. |
Fix #450
Validates on the frontend if the query applies
@fold
,@recurse
or@transform
on a property returning a new error (UnsupportedDirectiveOnProperty
) if so.