Hotchocolate: Preserve sort argument order when using variables?

Created on 6 Nov 2019  路  2Comments  路  Source: ChilliCream/hotchocolate

In cases where multiple order_by fields are specified, it seems that there is not a way to specify or guarantee order when provided as a query variable.

For example, the following query maintains the order of name first, then id.

query {
  companies (
    order_by: {
      name: ASC
      id: ASC
    }
  ) {
    ...company
  }
}

However, if the order_by provided as a query variable, the order cannot be preserved and would end executing as id first, then name.

query {
  companies($orderBy: CompanySort) (
    order_by: $orderBy
  ) {
    ...company
  }
}

Is there any way to maintain the order_by order using the variable approach?

bug

Most helpful comment

Oh, you are right :) This will actually be fixed with version 11. The issue here is that with V10 the variables are kept in a dictionary structure. The default dictionary has no order since it is basically a hashtable.

The literals on the other hands are kept as object literals which have a field order.

With the next version we have unified this, so it should be fixed then.

All 2 comments

Oh, you are right :) This will actually be fixed with version 11. The issue here is that with V10 the variables are kept in a dictionary structure. The default dictionary has no order since it is basically a hashtable.

The literals on the other hands are kept as object literals which have a field order.

With the next version we have unified this, so it should be fixed then.

btw, thank you for filing this issue :) 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RohrerF picture RohrerF  路  3Comments

marcin-janiak picture marcin-janiak  路  4Comments

lTimeless picture lTimeless  路  5Comments

mortzi picture mortzi  路  4Comments

sergeyshaykhullin picture sergeyshaykhullin  路  3Comments