FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
230 stars 16 forks source link

Support ordering by orderRank field #213

Closed yhunko closed 1 year ago

yhunko commented 1 year ago

According to the Orderable Document list plugin documentation, in order to order by the custom rank, we need to use it like so:

*[_type == "category"]|order(orderRank)

Which seems to not be supported as of now. Current workaround for now is the following usage:

export const getQuickAnswersQuery = q('*')
  .filterByType('quickAnswer')
  .grab(quickAnswerSelection)
  // @ts-ignore
  .order('orderRank');

Please correct me if I'm misunderstanding something. And if I'm not, it would be great to add a support.

gksander commented 1 year ago

You're absolutely right! Currently, the order method takes arguments with the following type: ${string} ${"asc" | "desc"}, but I think this is artificially limiting because the order method can take arguments beyond that. I think we probably should just use a string argument type for the order function.

I think this is a pretty easy change, since it's merely a type-level change. I can probably a fix for this released today!

gksander commented 1 year ago

Okay, this should be released in 0.15.9! Thanks for reporting this!