-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make the generated enums real enums #297
Comments
So, this project used built_value to generate immutable objects, which support ==/hashCode and json serialization. Now, built_value was written before Dart 2.0 and Dart enums have improved since then. So possibly, the authors would take a different decision if they were designed built_value today. So, generating Dart enums and making them work with built_value serialization is not trivial and I'm not sure if it's even possible. So I'm afraid this is not something that is feasible at the moment. If someone wants to work on this, PR's are welcome though (preferably with a switch so we can support both the current behavior and standard enums to avoid a breaking change). If in the future, built_value properly supports Dart enums, I will reconsider. |
There's an issue for that on built_value: google/built_value.dart#1171 |
Another note: consider using enum fallbacks (see https://pub.dev/packages/gql_build#provided-builders ). Otherwise, if the server adds an additional enum in the future and the client is not updated with the latest schema, parsing the response with the unknown enum value would fail. This is also something that built_value provides out of the box. |
Right now, the generated enums are not "real" dart enums, it is a class with
static const
s:The issue is that, when doing a
switch
/case
, dart complains because it doesn't know I've specified all the possible cases, and I lint errors. As an example the code bellow gets an analysis error:which wouldn't happen if
GMyEnum
was a proper dart enum.Is there a reason it cannot be made as a "real" enum ?
If you need properties or getters on the entries, you could generate
extension
s on the generated enum.The text was updated successfully, but these errors were encountered: