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

Do not allow users to apply fold, recurse and transform directives to properties #457

Merged
merged 13 commits into from
Aug 24, 2023

Conversation

era
Copy link
Contributor

@era era commented Aug 21, 2023

Fix #450

Validates on the frontend if the query applies @fold, @recurse or @transform on a property returning a new error (UnsupportedDirectiveOnProperty) if so.

@era era marked this pull request as ready for review August 21, 2023 16:52
@era era changed the title Does not allow properties to use fold Do not allow properties to use fold Aug 21, 2023
Copy link
Owner

@obi1kenobi obi1kenobi left a 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.

Comment on lines 112 to 117
#[error(
"The field \"{0}\" is a property but the query uses @fold.\
Only edges can be used with @fold."
)]
FoldOnProperty(String),

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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!

@@ -1104,6 +1103,30 @@ where
{
// Processing a property.

// @fold is not allowed on a property
if connection.fold.is_some() {
Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Owner

@obi1kenobi obi1kenobi left a 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() {
Copy link
Owner

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/src/frontend/error.rs Outdated Show resolved Hide resolved
era and others added 2 commits August 24, 2023 15:00
…_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>
@obi1kenobi
Copy link
Owner

Also remember to update the PR title and description to include the other directives being handled!

@obi1kenobi obi1kenobi added A-errors Area: external-facing error functionality R-relnotes Release: document this in the release notes of the next release labels Aug 24, 2023
@era era changed the title Do not allow properties to use fold Do not allow properties to use fold, recurse and transform Aug 24, 2023
@era era changed the title Do not allow properties to use fold, recurse and transform Do not allow properties to use fold, recurse and transform directives Aug 24, 2023
@era era changed the title Do not allow properties to use fold, recurse and transform directives Do not allow users to apply fold, recurse and transform directives on properties Aug 24, 2023
@era era changed the title Do not allow users to apply fold, recurse and transform directives on properties Do not allow users to apply fold, recurse and transform directives to properties Aug 24, 2023
@obi1kenobi
Copy link
Owner

Ah the failing lints are because we got a new Rust stable today. I'll push a fix real quick, sorry about that.

@era
Copy link
Contributor Author

era commented Aug 24, 2023

Ah thanks for clarifying, I was almost rolling back the last changes to see if the problem would remain :D

@obi1kenobi obi1kenobi enabled auto-merge (squash) August 24, 2023 14:37
@obi1kenobi
Copy link
Owner

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.

@obi1kenobi obi1kenobi merged commit ef9790c into obi1kenobi:main Aug 24, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-errors Area: external-facing error functionality R-relnotes Release: document this in the release notes of the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query accepting properties with @transform
2 participants