You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array traversals aren't yet defined in the spec (see #2), but the intended semantics have been implemented in e.g. groq-js. As I've been thinking and implementing these semantics I've found that they are a bit inconsistent and hard to work with. This issue is intending to make them more consistent and easy to implement.
These are the new proposed rules:
Every expression is (at a syntactical level) has a traverse behavior which is either none, implicit or explicit.
* and array constructor ([…]) have explicit traverse behavior .
The postfix projection operator (base[]) works as follows:
If the base has no or implicit traversal behavior, then it converts it to explicit traversal behavior.
If the base has explicit traversal behavior, then it applies a flatten operation.
The grouping expression ((…)) has no traverse behavior, regardless of what's inside it.
Filtering (base[foo > 1]) and slicing (base[1..5]) preserves the traverse behavior of the base.
Attribute access (base.foo), dereferencing (base->) and projection (base{bar}) have the following semantics:
If the base has either implicit or explicit traverse behavior, then it's being applied for each element in the base (e.g. *{bar} will project {bar} on each element). The returned expression has the same implicit/explicit traverse behavior as the base.
If the base has no traverse behavior, then it's being applied directly to the base.
Element access (base[5]) has the following semantics:
If the base has explicit traverse behavior, then it's being applied for each element in the base.
Otherwise, then it's being applied directly to the base while preserving the traverse behavior.
All other expressions have no traverse behavior.
Implications:
*[_type == "bar"]{baz} still works as expected
*[_type == "bar"]{users[]{name}}: The [] is needed when projecting over arrays.
Nested traversals still work as expected: *[_type == "bar"]{"avatars": users[].avatar.url}
Array traversals aren't yet defined in the spec (see #2), but the intended semantics have been implemented in e.g. groq-js. As I've been thinking and implementing these semantics I've found that they are a bit inconsistent and hard to work with. This issue is intending to make them more consistent and easy to implement.
These are the new proposed rules:
*
and array constructor ([…]
) have explicit traverse behavior .base[]
) works as follows:(…)
) has no traverse behavior, regardless of what's inside it.base[foo > 1]
) and slicing (base[1..5]
) preserves the traverse behavior of the base.base.foo
), dereferencing (base->
) and projection (base{bar}
) have the following semantics:*{bar}
will project{bar}
on each element). The returned expression has the same implicit/explicit traverse behavior as the base.base[5]
) has the following semantics:Implications:
*[_type == "bar"]{baz}
still works as expected*[_type == "bar"]{users[]{name}}
: The[]
is needed when projecting over arrays.*[_type == "bar"]{"avatars": users[].avatar.url}
Implementations:
The text was updated successfully, but these errors were encountered: