graphql-engine
graphql-engine copied to clipboard
Add support for sorting by json path
It would be nice to have the ability to sort the query results by a path of a JSON columns For example, for a table like
CREATE TABLE products (
id serial NOT NULL PRIMARY KEY,
translated_name jsonb NULL
);
I would like to have the ability to do something like
query productsSortedByName {
products(order_by: {translated_name: {path: "en", how: asc_nulls_last}}) {
id
name: translated_name (path: "en")
}
}
I second this request
At the very least, we should be able to sort by a named path
so for a data jsonb column like this
data: { "amount": 10 }
and a query like this
sometable { timestamp data amount: data(path: "amount") }
You could sort by this
"orderBy": [{"amount": "asc"}]
Any updates on this by chance? Currently this feature is the only thing missing in order to make the jump :(
I also vote for this feature. Thank you!
This feature is highly anticipated by our team, thank you.
Vote for this. Today we have to sort data (by translatable fields) on the client side.
Vote+1 this feature
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
We also need this feature.
Another plus one for this feature request.
I have a different use case though
I have object like this:
Person 0..1 -> 0..* Attributes(name, value)
Attribute is a simple label / value table, such as weight:65 pulse:86 etc.
I want to be able to order Person, where an attribute has a given name, so I can sort people by their weight, or heart rate.
A syntax might look something like:
Person.... order_by: { Attribute:{ name:{_eq: "weight"}, sort_value:{ value :asc}} }
Hey folks. As a little sneak preview: Native Queries will be out of beta and available in Hasura CE for PostgreSQL with the release of v2.28, which is imminent. Native Queries allow you to express your query as arbitrary SQL, while still getting all of the usual Hasura goodness.
While this isn't quite as trivial as being able to order by a computation, you might find it useful. You'd add your expected query:
SELECT id, translated_name -> "en" AS name
FROM products
ORDER BY translated_name -> "en" ASC NULLS LAST
Give it a name, then you can use Hasura to select as usual.
care to link to a PR# @manasag ?
Hi @jflambert, this issue is currently solved using Native Queries feature, as mentioned by Samir in the earlier comment. More direct support for this is not planned for current V2 of Hasura. We will revisit support for this in V3. I have created a new issue to track for V3 support #10018