-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added CaseIterable
to EnumType
.
#2547
feat: added CaseIterable
to EnumType
.
#2547
Conversation
👷 Deploy request for apollo-ios-docs pending review.Visit the deploys page to approve it
|
Adds an explicit `allCases` list when the enum contains cases that have a deprecation annotation. In that case, the compiler cannot synthesize the list automatically as usual, requiring the codegen to provide an explicit list.
Thanks for the PR!
We also found this out the hard way. And tried solving it the exact same way as you! The issue we had with that solution is, if the It's also unclear if users are going to want the deprecated cases included in I'm not super happy with that. Very willing to consider other options here. We're looking for feedback on this still. Would love your opinion. |
It seems the best solution is adding one more options to the codegen:
This option should only be in effect if both deprecated cases and deprecation warnings are included. In my case I'd prefer to deal with the warnings than not having the deprecated cases, but I understand that this is highly dependent on the specific situation. If you approve of this, I can add the option tomorrow (CET-wise). As a side note, very nice work on the codegen 👍. It seems a bit much in some points, but I'm sure you had your reasons. Blog post when? 😄 |
This is what we considered but I'm not a big fan of options that only work in some cases or conflict with others in non-obvious ways.
This comes down to preference, but I'm happy to learn more what the wider community finds valuable.
Soon™ - lol. We've got a long list of documentation and articles still to publish. |
@calvincestari and I spoke about this in depth. After reflecting on it, we feel that having deprecation warnings on enum cases doesn't make sense. For fields and input parameters that are deprecated, you are choosing to fetch them in your operations client-side. Deprecations are actionable -- you should remove the field from your operation and implement usage of the alternative for the deprecation (or whatever other appropriate steps there are to take). For enum cases, just because the case has been deprecated does not mean you should necessarily stop supporting it. Your server may still send you deprecated enum types in a response for objects created in the past. You still need to handle the cases where that deprecated value is in a response object. The only place that the deprecation is actionable on the client is when used as an input value for a parameter of that enum type. Most of the actionable steps here are server-side. We are going to move the warning from being an In that case, we can take action on this PR, and will also make the change to the generated warnings for enum case deprecations. I'll get that resolved ASAP and merge this PR. Thanks @TizianoCoroneo. |
Closing this in favor of #2579 which includes the fix for this! |
Thank you for the quick response! I agree with all of the above 👌 |
In the previous incarnation of the codegen enums implemented
CaseIterable
. We have some code that relies on this behavior.This PR adds back
CaseIterable
to theEnumType
protocol.Update:
I found out (the hard way) that the compiler will not automatically synthesize the
allCases
requirement ofCaseIterable
if the enum contains cases with deprecation annotations. I modified theEnumTemplate
to generate anallCases
computed variable in this case; other enums rely on the automatic synthesis by the compiler.