Description
Current Behaviour
We have to explicitly define action types for inputs and outputs, even if we are returning types that already exist (i.e. want to return characters
type associated to already existing characters
table, yet have to type it all out manually in action as a new type).
This creates few barriers, especially when we have to type out larger responses. It creates a lot of duplicate types, which get in the way when using tools like https://graphql-code-generator.com
And makes it really hard to work with typescript, where it expects some values to be of enum type, but we can't re-use enums in actions (See #4513)
Right now this is a single peace of functionality in hasura (at least for our team) that requires a lot of manual work / workarounds to get them working correctly with typescript and apolo cache (apollo cache doesn't get updated correctly as actions don't return existing types we use with queries for example).
Right now editing / deleting custom types doesn't update hasura's hdb_custom_types
correctly as well, making this issue of "a lot of unnecessary types" even worse (See #4967)
Doing so with approach described here https://hasura.io/docs/1.0/graphql/manual/actions/reuse-types-actions.html is viable, but perhaps a simpler method where we just define return types would be better?
Expected Behaviour
Actions should allow access to all types that already exist in our graphql schema (those generated when we create tables / enums etc...). We should be able to create actions without defining any custom types if action output uses already existing type (i.e. see characters
example above). When "Derive Action" option is clicked from Graphiql, generated action should reuse types from the code we typed out in Graphiql instead of creating it's own custom types. Generated action schema should have correctly inherited __typename
fields, so if it returns an existing type it will work correctly with tools like apollo cache.
I am not sure about this one, but it would add to dev experience if we could get type auto completion in actions text fields as well.