graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

reuse enum types in actions

Open danielkcz opened this issue 4 years ago • 8 comments

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.

danielkcz avatar Apr 22 '20 12:04 danielkcz

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.

xzilja avatar Jun 01 '20 13:06 xzilja

Up

pacoccino avatar Feb 13 '21 08:02 pacoccino

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

amal-chandran avatar Dec 09 '21 00:12 amal-chandran

There are couple of architectural complexities involved with this capability:

  1. Enum types can come from remote schemas which have permissions
  2. Enum types from Postgres do not have permissions but may have it in the future
  3. 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

tirumaraiselvan avatar Apr 05 '22 09:04 tirumaraiselvan

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.

rahulagarwal13 avatar Dec 20 '22 02:12 rahulagarwal13

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.

tirumaraiselvan avatar Feb 09 '23 12:02 tirumaraiselvan

Are there any updates on this issue? We are also looking to reuse existing enums (and type) in actions.

raulelba avatar Sep 19 '23 14:09 raulelba

@rahulagarwal13 Is there an update on the timeline when this will be available?

aravindjaimon avatar Jan 03 '24 05:01 aravindjaimon