graphql-python / graphql-python/graphene
Interfaces are ignored when define Mutation.
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Hello.
First of all, thanks for all graphene developers and contributors.
* **What is the current behavior?**
Interface is ignored when define mutation. This is my code.
```python
class CreatePlan(Mutation):
class Meta:
interfaces = (PlanInterface, )
class Arguments:
name = String(required=True)
comment = String(default_value='')
goal = String(required=True)
start_date = DateTime(required=True)
end_date = DateTime(required=True)
def mutate(parent, info, **kwargs):
~~~
# this raises AssertionError:
# CreatePlan fields must be a mapping (dict / OrderedDict)
# with field names as keys or a function which returns such a mapping.
```
* **What is the expected behavior?**
I think Mutation should includes all interfaces and fields together.
* **Please tell us about your environment:**
Here is my environment.
- Version: 2.1.9
- Platform: Mac OS
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
I think removing just a line can resolve this problem.
**branch v2**, graphene/types/mutation.py line 69
```python
@classmethod
def __init_subclass_with_meta__(
cls,
interfaces=(),
resolver=None,
output=None,
arguments=None,
_meta=None,
**options
):
if not _meta:
_meta = MutationOptions(cls)
output = output or getattr(cls, "Output", None)
fields = {}
for interface in interfaces:
assert issubclass(interface, Interface), (
'All interfaces of {} must be a subclass of Interface. Received "{}".'
).format(cls.__name__, interface)
fields.update(interface._meta.fields)
if not output:
# If output is defined, we don't need to get the fields
fields = OrderedDict(). # This ignores interfaces. Remove this.
for base in reversed(cls.__mro__):
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
output = cls
```
Also, I found same problem on master branch.
```python
@classmethod
def __init_subclass_with_meta__(
cls,
interfaces=(),
resolver=None,
output=None,
arguments=None,
_meta=None,
**options,
):
if not _meta:
_meta = MutationOptions(cls)
output = output or getattr(cls, "Output", None)
fields = {}
for interface in interfaces:
assert issubclass(
interface, Interface
), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
fields.update(interface._meta.fields)
if not output:
# If output is defined, we don't need to get the fields
fields = {}. # This ignores interfaces. Remove this.
for base in reversed(cls.__mro__):
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
output = cls
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en graphene/types/mutation.py, en __init_subclass_with_meta__, y reproduce el ejemplo de CreatePlan informado. La corrección estará terminada cuando definir una mutación con interfaces conserve los campos de las interfaces en su salida, en lugar de descartarlos cuando no se proporciona una salida explícita.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100