graphql-python / graphql-python/graphene

Cannot use an enum as a graphene.List named argument

Abierto
#1,166 6 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
8.2k
Forks
818
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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
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**

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza reproduciendo el ejemplo e inspecciona la ruta graphene/types/argument.py del traceback, especialmente el manejo de extra_args. Se considera terminado cuando se acepta un argumento con nombre cuyo valor es un enum junto con Int y se puede crear la definición de esquema mostrada sin el TypeError.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.