mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Allow mutations to be required. Improved testing. Fixed #694
This commit is contained in:
parent
562cafc14f
commit
d46d8e8c33
|
@ -73,10 +73,11 @@ class Mutation(ObjectType):
|
|||
_meta.resolver = resolver
|
||||
_meta.arguments = arguments
|
||||
|
||||
super(Mutation, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
super(Mutation, cls).__init_subclass_with_meta__(
|
||||
_meta=_meta, **options)
|
||||
|
||||
@classmethod
|
||||
def Field(cls, name=None, description=None, deprecation_reason=None):
|
||||
def Field(cls, name=None, description=None, deprecation_reason=None, required=False):
|
||||
return Field(
|
||||
cls._meta.output,
|
||||
args=cls._meta.arguments,
|
||||
|
@ -84,4 +85,5 @@ class Mutation(ObjectType):
|
|||
name=name,
|
||||
description=description,
|
||||
deprecation_reason=deprecation_reason,
|
||||
required=required,
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@ from ..mutation import Mutation
|
|||
from ..objecttype import ObjectType
|
||||
from ..scalars import String
|
||||
from ..schema import Schema
|
||||
from ..structures import NonNull
|
||||
|
||||
|
||||
def test_generate_mutation_no_args():
|
||||
|
@ -133,3 +134,27 @@ def test_mutation_no_fields_output():
|
|||
'name': None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_mutation_allow_to_have_custom_args():
|
||||
class CreateUser(Mutation):
|
||||
|
||||
class Arguments:
|
||||
name = String()
|
||||
|
||||
name = String()
|
||||
|
||||
def mutate(self, info, name):
|
||||
return CreateUser(name=name)
|
||||
|
||||
class MyMutation(ObjectType):
|
||||
create_user = CreateUser.Field(
|
||||
description='Create a user',
|
||||
deprecation_reason='Is deprecated',
|
||||
required=True
|
||||
)
|
||||
|
||||
field = MyMutation._meta.fields['create_user']
|
||||
assert field.description == 'Create a user'
|
||||
assert field.deprecation_reason == 'Is deprecated'
|
||||
assert field.type == NonNull(CreateUser)
|
||||
|
|
Loading…
Reference in New Issue
Block a user