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

type evaluator: Add support for delta mode queries #276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sgulseth
Copy link
Member

No description provided.

@sgulseth sgulseth requested a review from judofyr February 28, 2025 18:58
t.test('delta mode', (t) => {
const variants = [
{
query: `*[_type == "author" && before()._type == "other"]`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't really how before() should be used though. It's technically a correct example, but it doesn't use the scope, but rather refers to the before/after values in the context.

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, but we operate on the types and not values. The only case where we can know the value if it's a string literal. I get that comparing _type like this is not realistic per se, but I wanted to test wether it would exclude all types, practically the same as _type == "author" && _type == "other" which would always return an empty set.

switch (node.key) {
case 'before':
case 'after': {
return scope.value
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks a bit off. before() and after() shouldn't refer to scope. It just uses the context: https://spec.groq.dev/draft/#global_before(). We can maybe assume that it's an element of schema, although technically we should probably rather introduce a new option to typeEvaluate which lets you specify the type of this value.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not retuning the scope, it's returning the current value that's in the scope. Which is the current schema that hasn't been filtered out

@sgulseth sgulseth requested a review from judofyr March 5, 2025 09:21
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