-
Notifications
You must be signed in to change notification settings - Fork 766
Add convert_choices_to_enum
option on DjangoObjectType Meta class
#674
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good feature!
That setting to an empty list is the same as setting the value as False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach. Perhaps a similar tact could be used for specifying explicit enums
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well documented and tested - thanks @jkimbo. LGTM.
Hello! is it possible that this same thing happens when using an Enum (TemplateType) as an argument in a query and the same Enum as a parameter in a mutation ? Example:
and
gets: A provisional fix was to define the argument in a global variable and pass that to the query and mutation. |
@rhigueraa I'm assuming that I guess it could have some kind of cache built in so that the same class would result in the same enum but I'm not sure it's a good idea to implement caching behaviour unless it's absolutely necessary because it can lead to unexpected outcomes. |
@jkimbo Hi there. Regarding the cache solution i don't really know how the library is built, so i don't know if that could be a good solution but the way it is right now is not allowing us to implement a proper solution while using enums. So it would be nice if you could take a look around that cache solution. |
@kbelter can you explain more why "it wont scale in a long term solution"? Converting an enum to a graphene enum once and then exposing that result so that it can be reused in multiple places seems like a fine solution to me. |
@jkimbo
Also is not really snazzy to approach the feature this way and in the future other developers may have the same problem, so it's not really an intuitive solution. I know this is an open source library and i really appreciate the time and effort that all of you guys are putting into this project, this is just a constructive comment. |
@jkimbo have you thought about what i told you in the above comment? |
You have some good points @kbelter that I hadn’t considered. Consider my mind changed! Could you create a PR that implements this and I’ll happily review and get it merged? It will have to be on the graphene repo since the enum conversion lives there. |
@jkimbo Is a global flag currently being worked on? We got blocked upgrading from 2.5->2.6 because we've already built a more complex enum recognition system and never want to go through this codepath. It would be nice if we didn't have to rewrite my whole codebase to account for this. I can put in a PR if necessary. |
This PR adds a new option to the
DjangoObjectType
Meta
class:convert_choices_to_enum
. This option (which defaults toTrue
) can be set toFalse
to disable all automatic choices to Enum conversions on that ObjectType. Or set to a list of field names to be automatically converted to Enums.The aim of this new feature is provide a quick way to disable the automatic Enum conversion for fields that have choices. There are a lot of issues with the automatic conversion currently and hopefully this feature can alleviate some of those issues.