Skip to content

Commit afc5e27

Browse files
committed
Added NonNull, List definitions to ClassTypes
1 parent 3363f58 commit afc5e27

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

graphene/core/classtypes/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,19 @@ def construct(cls, bases, attrs):
4343
# Add all attributes to the class.
4444
for obj_name, obj in attrs.items():
4545
cls.add_to_class(obj_name, obj)
46+
47+
if not cls._meta.abstract:
48+
from ..types import List, NonNull
49+
setattr(cls, 'NonNull', NonNull(cls))
50+
setattr(cls, 'List', List(cls))
51+
4652
return cls
4753

4854

4955
class ClassType(six.with_metaclass(ClassTypeMeta)):
56+
class Meta:
57+
abstract = True
58+
5059
@classmethod
5160
def internal_type(cls, schema):
5261
raise NotImplementedError("Function internal_type not implemented in type {}".format(cls))
@@ -74,6 +83,9 @@ class FieldsClassTypeMeta(ClassTypeMeta):
7483

7584

7685
class FieldsClassType(six.with_metaclass(FieldsClassTypeMeta, ClassType)):
86+
class Meta:
87+
abstract = True
88+
7789
@classmethod
7890
def fields_internal_types(cls, schema):
7991
fields = []

graphene/core/classtypes/tests/test_base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..base import ClassType, FieldsClassType
2-
from ...types import Field, String
2+
from ...types import Field, String, List, NonNull
33
from ...schema import Schema
44

55

@@ -20,6 +20,20 @@ class Meta:
2020
assert Character._meta.description == 'OtherCharacter description'
2121

2222

23+
def test_classtype_definition_list():
24+
class Character(ClassType):
25+
'''Character description'''
26+
pass
27+
assert isinstance(Character.List, List)
28+
29+
30+
def test_classtype_definition_nonnull():
31+
class Character(ClassType):
32+
'''Character description'''
33+
pass
34+
assert isinstance(Character.NonNull, NonNull)
35+
36+
2337
def test_fieldsclasstype():
2438
f = Field(String())
2539

0 commit comments

Comments
 (0)