mirror of
https://github.com/graphql-python/graphene.git
synced 2024-12-01 22:14:02 +03:00
Merge pull request #788 from sebdiem/sdr/subclass_mutations
Enable mutations subclassing
This commit is contained in:
commit
4346832f71
|
@ -148,3 +148,47 @@ def test_mutation_allow_to_have_custom_args():
|
||||||
assert field.description == "Create a user"
|
assert field.description == "Create a user"
|
||||||
assert field.deprecation_reason == "Is deprecated"
|
assert field.deprecation_reason == "Is deprecated"
|
||||||
assert field.type == NonNull(CreateUser)
|
assert field.type == NonNull(CreateUser)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mutation_as_subclass():
|
||||||
|
class BaseCreateUser(Mutation):
|
||||||
|
|
||||||
|
class Arguments:
|
||||||
|
name = String()
|
||||||
|
|
||||||
|
name = String()
|
||||||
|
|
||||||
|
def mutate(self, info, **args):
|
||||||
|
return args
|
||||||
|
|
||||||
|
class CreateUserWithPlanet(BaseCreateUser):
|
||||||
|
|
||||||
|
class Arguments(BaseCreateUser.Arguments):
|
||||||
|
planet = String()
|
||||||
|
|
||||||
|
planet = String()
|
||||||
|
|
||||||
|
def mutate(self, info, **args):
|
||||||
|
return CreateUserWithPlanet(**args)
|
||||||
|
|
||||||
|
class MyMutation(ObjectType):
|
||||||
|
create_user_with_planet = CreateUserWithPlanet.Field()
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
a = String()
|
||||||
|
|
||||||
|
schema = Schema(query=Query, mutation=MyMutation)
|
||||||
|
result = schema.execute(''' mutation mymutation {
|
||||||
|
createUserWithPlanet(name:"Peter", planet: "earth") {
|
||||||
|
name
|
||||||
|
planet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
''')
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {
|
||||||
|
'createUserWithPlanet': {
|
||||||
|
'name': 'Peter',
|
||||||
|
'planet': 'earth',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,4 +10,6 @@ _all_vars = set(dir(_OldClass) + dir(_NewClass))
|
||||||
|
|
||||||
|
|
||||||
def props(x):
|
def props(x):
|
||||||
return {key: value for key, value in vars(x).items() if key not in _all_vars}
|
return {
|
||||||
|
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