sanity-plugin-documents-pane
sanity-plugin-documents-pane copied to clipboard
Question: how to pass an <expression> as param?
Hey. I am trying to use an input field from my document to specify the ordering of the query.
The order()
function takes an <expr>
apparently and I cannot find a way to pass an <expr>
from the params...
Am I missing something?
I would like to accomplish something like that:
{
query: `*[_type == "mytype"] | order($sortProp $sortDirection)`,
params: { sortProp: "name", sortDirection: "asc" }
}
I think the easiest way to accomplish what I want would be to be able to pass a function to query
so that we could compose the query easily with template literals.
It’s not possible with GROQ to use a variable for a key name, unfortunately
Ok, that is what I thought.
In this plugin specifically, would it be possible to have the query
parameter accept a function so that we can modify it manually?
I am thinking something like this:
{
query: ({ params, ...maybeSomethingElse }) => `*[_type == "mytype"] | order(${params.sortProp} ${params.sortDirection})`,
params: { sortProp: "name", sortDirection: "asc" }
}
For reference, I suggested adding a feature on the GROQ spec Github here.