Hasura GraphQL query order by nested array relationships (with only one element)?

1.1k views Asked by At

From the Hasura documentation is not possible to order by nested array relationships, the thing is I'm using that relation to get only one element from the array (e.g. the latest entry in that table). There is any way to transform that array (with one element) into an object to be able to perform order by in the root query?. Example:

query GetMachinesQuery {
    machines {
        machine_id
        machine_detail
        last_upgrade: upgrades(order_by: { created_at: desc }, limit: 1) {
            upgrade_state {
                updated_at
                status
            }
        }
    }
}

Do I have any way to sort the root query by any of the fields (e.g. status) present in the last_upgrade? The possible workaround is create a view (doing the joins to get latest upgrade info for each machine) and then I can use an object relationship, any other alternatives with hasura?

Thank you !

0

There are 0 answers