mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-01 00:17:26 +03:00 
			
		
		
		
	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:
		
							parent
							
								
									9f366e93c6
								
							
						
					
					
						commit
						181e75c952
					
				|  | @ -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 | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user