-
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
Using params in functions (E.g. *[] | order($orderBy)
)
#103
Comments
@m4rrc0 Did you ever end finding a workaround that let's you dynamically set I'm have this exact same case and currently am stuck trying trying to get a dynamic
|
Further discussion here in the Sanity slack: https://sanity-io-land.slack.com/archives/C011CAT70DD/p1717972385870249 The conclusion here seems that this is not possible right now. This would be a massive help for us and our project especially with the new launch of the sanity-typegen workflow. Splitting up our query and using string interpolation breaks typegen for this query. We'd really prefer to avoid losing type safety since this is a core query in our app. |
I'm currently facing this same issue on a project I am working on. It would help greatly if we could parametrize the sort order while keeping type safety in this type of workflow. |
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:
(context: I am using the plugin
sanity-plugin-documents-pane
and the Sanity studio crashed when trying to do the same forasc
)This is deeply impractical.
Improvements I can come up with:
*[] | order(unquote($orderBy))
*[] | order(@[$orderBy])
Or
The text was updated successfully, but these errors were encountered: