Joystream / Joystream/hydra

Ordering by values in union fields

Open
#196 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement low-prio low-prio-feature question
Dominant language
TypeScript
Stars
50
Forks
43
PR merge metrics
No merged PRs in 30d

Description

We can do filtering by values in union fields, but not ordering.

So assume we had something like


type Starting @variant {
  started: Int!
  money: Int!
  }
  
 type Voting @variant {
  time: Int!
  }

union ProposalState = Starting | Voting

type  Proposal @entity {
  my_state_fied: ProposalState
}

Then we would get something like


enum ProposalStateOrderByInput {
  Starting_started_ASC
  Starting_started_DESC
  Starting_money_ASC
  Starting_money_DESC
  Voting_time_ASC
  Voting_time_DESC
}

Should obviously generalize to arbitrary nesting of union types, but idea is the same, in the end you get one big enum with finite number of paths.

PostgreSQL itself seems well equipped to execute such ordering also

https://stackoverflow.com/questions/25967778/order-by-json-data-type-postgres

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the existing union-field filtering and order-by generation paths first, then review how PostgreSQL JSON ordering could support nested union values. Done means generating finite order-by enum paths for union fields, including arbitrary nesting, and applying the selected ascending or descending ordering correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, postgresql, typescript
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.