Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Interfaces are ignored when define Mutation.

Aperta
#1,361 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

Inizia in graphene/types/mutation.py, in init_subclass_with_meta, e riproduci l'esempio CreatePlan segnalato. La correzione è completata quando la definizione di una mutation con interfacce conserva i campi delle interfacce nel suo output invece di scartarli quando non viene fornito alcun output esplicito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 bug

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

    @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.

    @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
Lingua principale
Python
Stelle
8.2k
Fork
818
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di graphql-python/graphene

Tutte le issue di graphql-python/graphene

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.