Merge pull request #788 from sebdiem/sdr/subclass_mutations

Enable mutations subclassing
This commit is contained in:
Syrus Akbary 2018-07-09 19:06:15 -07:00 committed by GitHub
commit 4346832f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -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',
}
}

View File

@ -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
}