graphql-engine
graphql-engine copied to clipboard
reuse enum types in actions
Current behavior
I have an enum table userGender
with a correctly set foreign key on table user
and column gender
. The generated insert_user_one
then expects a custom type userGender_enum
, that's kinda cool and works well with a codegen.
I have also a mutation action signUp
that accepts the gender of the user on the input and calls (among others) a generated mutation insert_user_one
. When I want to specify generated userGender_enum
for the input it won't allow it.
validation for the given custom types failed because the type "userGender_enum" for field "gender" in input object type "SignUpInput" does not exist
Expected behavior
I know that in practice, this doesn't matter that much because the underlying foreign key will still check the input. It's definitely nicer for GraphiQL and others to make writing queries for actions easier if they are correctly type-checked.
Unfortunately, it's a problem with the generated typescript code. It causes inconsistency in data type String
on input (from SignUpInput
) and data type for inserting users which is based on the enum.
I expect that enum table type can be used in the custom input type for an action.
Came across this issue today as well, particularly the typescript part where 2 enums (enum and type defined in custom action types) conflict between each other.
Up
Up If we can use enum tables as the source of truth for actions then we can reduce a lot of manual code. Currently, we are using enum tables as a source of truth in both frontend and backend with help of graphql-codegen
There are couple of architectural complexities involved with this capability:
- Enum types can come from remote schemas which have permissions
- Enum types from Postgres do not have permissions but may have it in the future
- Referencing enum types (which are generated during runtime) in action definitions may be an anti-pattern (since there is no way to validate the source)
Hence, this should be tackled along with https://github.com/hasura/graphql-engine/issues/5001
Thank you for the request and comments for this feature. We would like to inform you that this is on our roadmap. We’ll get started in the next few months - would love to get you as a design partner when we get started, so please let us know if you are interested to collaborate.
We are thinking of extending the custom_types
metadata to have an import_enums_from_table
field which can take a list of enum tables. Those enums will be available to automatically use in Actions.
Are there any updates on this issue? We are also looking to reuse existing enums (and type) in actions.
@rahulagarwal13 Is there an update on the timeline when this will be available?