Skip to content
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

Cannot use an enum as a graphene.List named argument #1166

Open
spacether opened this issue Mar 27, 2020 · 6 comments
Open

Cannot use an enum as a graphene.List named argument #1166

spacether opened this issue Mar 27, 2020 · 6 comments

Comments

@spacether
Copy link

spacether commented Mar 27, 2020

When defining this query:

class Episode(graphene.Enum):
    NEWHOPE = 4
    EMPIRE = 5
    JEDI = 6

class ListAvailableSubscriptionPlans(graphene.ObjectType):

    available_subscription_plans = graphene.List(
        graphene.NonNull(graphql.SubscriptionPlanObject),
        subscriber_id=graphene.Int(required=True),
        subscriber_type=Episode,
        target_currency=graphene.String(required=True),
    )

    def resolve_available_subscription_plans(
        self, info, subscriber_id, subscriber_type, target_currency
    ):

And running the python module, we get the error:

  File "/app/subscription_management/subscriptions/api.py", line 16, in <module>
    class ListAvailableSubscriptionPlans(graphene.ObjectType):
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/utils/subclass_with_meta.py", line 52, in __init_subclass__
    super_class.__init_subclass_with_meta__(**options)
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/objecttype.py", line 112, in __init_subclass_with_meta__
    fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/utils.py", line 31, in yank_fields_from_attrs
    field = get_field_as(value, _as)
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/utils.py", line 21, in get_field_as
    return _as.mounted(value)
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/mountedtype.py", line 15, in mounted
    return cls(
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/field.py", line 103, in __init__
    self.args = to_arguments(args or OrderedDict(), extra_args)
  File "/app/virtualenv/lib/python3.8/site-packages/graphene/types/argument.py", line 80, in to_arguments
    extra_args = sorted(extra_args.items(), key=lambda f: f[1])
TypeError: '<' not supported between instances of 'EnumMeta' and 'Int'

Because this line does not work:
subscriber_type=Episode

@spacether spacether changed the title Cannot use an enum as a graphene.list named argument, Cannot use an enum as a graphene.List named argument Mar 27, 2020
@spacether
Copy link
Author

spacether commented Mar 27, 2020

A work around is to cast the enum as a graphene.Argument:
subscriber_type=graphene.Argument(Episode)

class ListAvailableSubscriptionPlans(graphene.ObjectType):

    available_subscription_plans = graphene.List(
        graphene.NonNull(graphql.SubscriptionPlanObject),
        subscriber_id=graphene.Int(required=True),
        subscriber_type=graphene.Argument(Episode),
        target_currency=graphene.String(required=True),
    )

@stale
Copy link

stale bot commented Jun 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 25, 2020
@iamareebjamal
Copy link

not stale

@stale stale bot removed the wontfix label Jul 7, 2020
@stale
Copy link

stale bot commented Oct 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 16, 2020
@iamareebjamal
Copy link

no

@stale stale bot removed the wontfix label Oct 16, 2020
@chrisberks
Copy link

You need to call Episode like with other GraphQL types.

subscriber_type=Episode()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants