Skip to content

fix: sort on TableEntries

When sorting a table answer by another key then the id, the sort is not global, but local:

If we want to sort by guide id, we can do the following query

query Query($options: TableEntryOptions, $guideOptions: GuideOptions) {
  tableEntries(options: $options) {
    id
    guide(options: $guideOptions) {
      id
    }
    modification {
      id
    }
  }
}

with data

{
  "options": {
    "limit": 4
  },
  "guideOptions": {
    "sort": [
      {
        "id": null
      }
    ]
  }
}

But we get

{
  "data": {
    "tableEntries": [
      {
        "id": "fde39680-70e7-422a-865c-528d077dd9fc",
        "guide": {
          "id": "GD_00000"
        }
      },
      {
        "id": "8708de15-da6f-4200-8a8b-987ef0ca4ff0",
        "guide": {
          "id": "GD_00008"
        }
      },
      {
        "id": "34de509e-2142-449f-b464-5b5a6156a128",
        "guide": {
          "id": "GD_00000"
        }
      },
      {
        "id": "bd134624-97cd-4024-af75-4bd20dd4dea2",
        "guide": {
          "id": "GD_00008"
        }
      }
    ]
  }
}

We want something more like:

query Query($options: TableEntryOptions) {
  tableEntries(options: $options) {
    id
    guide {
      id
    }
  }
}

with data

{
  "options": {
    "limit": 4
  },
  "guideOptions": {
    "sort": [
      {
        "guide": {
           id": null
        }
      }
    ]
  }
}