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

Using params in functions (E.g. *[] | order($orderBy)) #103

Open
m4rrc0 opened this issue Mar 31, 2023 · 0 comments
Open

Using params in functions (E.g. *[] | order($orderBy)) #103

m4rrc0 opened this issue Mar 31, 2023 · 0 comments

Comments

@m4rrc0
Copy link

m4rrc0 commented Mar 31, 2023

I have been looking for a solution for this but it is apparently impossible (or at least very impractical; see below).

For example:
*[] | order($orderBy)
With params
{ "orderBy": "createdAt"}

The only "not-really-a-solution" I found is this:

*[] | order(select(
  $orderBy == "_createdAt" => _createdAt,
  _id
))

(context: I am using the plugin sanity-plugin-documents-pane and the Sanity studio crashed when trying to do the same for asc)

This is deeply impractical.

Improvements I can come up with:

  • A function or specific syntax to unquote strings. E.g. *[] | order(unquote($orderBy))
  • Being able to lookup a scope for a dot-notation path.

*[] | order(@[$orderBy])

Or

*[]
{
  ...@,
  "temp": @[$orderBy],
}
| order(temp)
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

No branches or pull requests

1 participant