Skip to content

Commit 181e75c

Browse files
author
Sébastien Diemer
committed
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
1 parent 9f366e9 commit 181e75c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

graphene/utils/props.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ class _NewClass(object):
1111

1212
def props(x):
1313
return {
14-
key: value for key, value in vars(x).items() if key not in _all_vars
14+
key: vars(x).get(key, getattr(x, key)) for key in dir(x) if key not in _all_vars
1515
}

0 commit comments

Comments
 (0)