hasura / hasura/graphql-engine
Enum-valued computed fields
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
I would like to use computed fields to expose derived data, such as entity status (e.g. how far along is the user in a sign-up flow). With scalar computed fields, I have to use some loose type (usually text or numeric) instead of some kind of table-based enum.
### Describe the solution you'd like
Example: given a `user` table and a `user_status` enum table, I'd like to be able to define `CREATE FUNCTION user_status (user user) RETURNS user_status` and use it in a computed column with the correct type.
### Describe alternatives you've considered
- Non-computed column kept up to date with an update trigger at the SQL level: I'd rather not persist derived data. This is also unworkable if the computation is based on values in other tables.
- Postgres-level generated columns: suffers from the same limitation (can't use data from other tables).
- Use a custom scalar computed field and override the type in the generated code in `codegen.yml`: works if you're using `graphql-codegen`, and might be what we'll go for
### If the feature is approved, would you be willing to submit a PR?
I'd need substantial guidance, but yes.
Contributor guide
Assessment
This issue has not been assessed yet.