-
Notifications
You must be signed in to change notification settings - Fork 15
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
Proposal: Array traversal by only supporting [] on attribute access #37
Comments
My concern is that we don't break referential transparency. Is this semantics change purely syntactical, or do "avalue" expressions create distinct values? For example, does |
This is purely syntactical and nothing is retained at runtime. |
I don't love that this breaks referential integrity, but I don't have very strong feelings about it. The most important thing is enabling the functionality we want. I just worry that it could cause problems down the line. This doesn't cover flattening semantics. Do we supply a |
Closed in favor of #42. |
Here's a proposal to specify array traversal at a grammar level. This means that the attribute access in
*[_type == "user"].name
becomes syntactically different from*[_type == "user"][0].name
. The rules are as follows:avalue
(array value) andvalue
.avalue
is the expressions which are guaranteed to return arrays:*
, filtering, and projection on anotheravalue
.value
is everything else.[]
is not a generic operator, but instead an optional postfix on attribute access:.foo[]
.foo
:value "." string
: This is a plain attribute access (foo.bar
)value "." string "[]"
: This is also a plain attribute access (foo.bar[]
), but the result is (syntactically) anavalue
which means that further attributes will be mapped (foo.bar[].baz
).avalue "." string
: This will map the attribute over the values (*._id
).avalue "." string "[]"
: This is a flat map over the attribute (*.books[]
)..foo
on avalue
is always a plain attribute access, while.foo
on aavalue
is always a mapping.Implications:
*[_type == "user"].name
is a mapping (since*[_type == "user"]
is anavalue
)*{"firstName": name.firstName}
is an attribute access*{"firstName": name[].firstName}
is a mapping*{"firstName": name{firstName}}
will filter thename
-object (and returnnull
if it's an array)*{"firstName": name[]{firstName}}
will filter over the entries of thename
-arrayExample which shows three of the different types:
Minimal grammar showing the example:
The text was updated successfully, but these errors were encountered: