Fetch fields from parent classes in mutations

The goal of this commit is to be able to subclass mutations like this:

```
    class BaseMutation(graphene.Mutation):
        class Arguments:
            name = graphene.String()

        def mutate(self, info, **kwargs):
            # do something

    class ChildMutation(BaseMutation):
        class Arguments(BaseMutation.Arguments):
            other_arg = graphene.String()

        def mutate(self, info, **kwargs):
            # do other things
```

Note:
    vars(x).get(key, gettattr(x, key)) is used instead of the
    simpler gettatrr(x, key) for python2.7 compat.
    Indeed python2 and python3 lead to different results for

    class Foo(object):
        def bar(self):
            pass
    getattr(Foo, 'bar')

    # python 2.7 : > unbound method bar
    # python 3.x : > function Foo.bar
This commit is contained in:
Sébastien Diemer 2018-06-29 16:49:33 +02:00
parent 9f366e93c6
commit 181e75c952

View File

@ -11,5 +11,5 @@ _all_vars = set(dir(_OldClass) + dir(_NewClass))
def props(x):
return {
key: value for key, value in vars(x).items() if key not in _all_vars
key: vars(x).get(key, getattr(x, key)) for key in dir(x) if key not in _all_vars
}