Well, we met the problems with enums when we started using automatic type generation from GraphQL-schema.
The server application types are defined separately from the auto-generated types to allow TS to perform typecheking in the GQL-resolvers.
We need it to be sure that we don't return an unexpected (undeclared) error code to clients and we correctly interpret the GQL-parameters received from the clients.
Two enums separaterly declared couldn't be substituted one with another even if they have the same list of pairs name -> value.
enumEFFECT1_FAILURE_CODE{ERROR_1='EEFF_ERROR_1',ERROR_2='EEFF_ERROR_2'}enumEFFECT2_FAILURE_CODE{ERROR_1='EEFF_ERROR_1',ERROR_2='EEFF_ERROR_2',}declarefunctionf(failure:EFFECT1_FAILURE_CODE):void;functiong(failure:EFFECT2_FAILURE_CODE){f(failure);// Argument of type 'EFFECT2_FAILURE_CODE' is not// assignable to parameter of type 'EFFECT1_FAILURE_CODE'}
So, on the application level we had to refactor our enums to the UNIONS. And we re-configured typegeneration to emit the unions for GQL enums. And that's it -- everything works.
Well, we met the problems with enums when we started using automatic type generation from GraphQL-schema.
The server application types are defined separately from the auto-generated types to allow TS to perform typecheking in the GQL-resolvers.
We need it to be sure that we don't return an unexpected (undeclared) error code to clients and we correctly interpret the GQL-parameters received from the clients.
Two enums separaterly declared couldn't be substituted one with another even if they have the same list of pairs
name -> value.So, on the application level we had to refactor our enums to the UNIONS. And we re-configured typegeneration to emit the unions for GQL enums. And that's it -- everything works.
So. NO ENUMS any more!
nice real life example !