Skip to content

Commit 4346832

Browse files
authored
Merge pull request #788 from sebdiem/sdr/subclass_mutations
Enable mutations subclassing
2 parents 43aec72 + 319605b commit 4346832

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

graphene/types/tests/test_mutation.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,47 @@ class MyMutation(ObjectType):
148148
assert field.description == "Create a user"
149149
assert field.deprecation_reason == "Is deprecated"
150150
assert field.type == NonNull(CreateUser)
151+
152+
153+
def test_mutation_as_subclass():
154+
class BaseCreateUser(Mutation):
155+
156+
class Arguments:
157+
name = String()
158+
159+
name = String()
160+
161+
def mutate(self, info, **args):
162+
return args
163+
164+
class CreateUserWithPlanet(BaseCreateUser):
165+
166+
class Arguments(BaseCreateUser.Arguments):
167+
planet = String()
168+
169+
planet = String()
170+
171+
def mutate(self, info, **args):
172+
return CreateUserWithPlanet(**args)
173+
174+
class MyMutation(ObjectType):
175+
create_user_with_planet = CreateUserWithPlanet.Field()
176+
177+
class Query(ObjectType):
178+
a = String()
179+
180+
schema = Schema(query=Query, mutation=MyMutation)
181+
result = schema.execute(''' mutation mymutation {
182+
createUserWithPlanet(name:"Peter", planet: "earth") {
183+
name
184+
planet
185+
}
186+
}
187+
''')
188+
assert not result.errors
189+
assert result.data == {
190+
'createUserWithPlanet': {
191+
'name': 'Peter',
192+
'planet': 'earth',
193+
}
194+
}

graphene/utils/props.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ class _NewClass(object):
1010

1111

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

0 commit comments

Comments
 (0)