Skip to content

Commit 47d7adf

Browse files
committed
Improved documentation in UnmountedTypes
1 parent 0a80119 commit 47d7adf

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

graphene/types/enum.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):
5858
kind of type, often integers.
5959
'''
6060

61-
def get_type(self):
62-
return type(self)
61+
@classmethod
62+
def get_type(cls):
63+
'''
64+
This function is called when the unmounted type (Enum instance)
65+
is mounted (as a Field, InputField or Argument)
66+
'''
67+
return cls

graphene/types/inputobjecttype.py

+4
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ class InputObjectType(six.with_metaclass(InputObjectTypeMeta, UnmountedType)):
5050

5151
@classmethod
5252
def get_type(cls):
53+
'''
54+
This function is called when the unmounted type (InputObjectType instance)
55+
is mounted (as a Field, InputField or Argument)
56+
'''
5357
return cls

graphene/types/scalars.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class Scalar(six.with_metaclass(ScalarTypeMeta, UnmountedType)):
4343

4444
@classmethod
4545
def get_type(cls):
46+
'''
47+
This function is called when the unmounted type (Scalar instance)
48+
is mounted (as a Field, InputField or Argument)
49+
'''
4650
return cls
4751

4852
# As per the GraphQL Spec, Integers are only treated as valid when a valid

graphene/types/structures.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def __init__(self, of_type, *args, **kwargs):
1212
self.of_type = of_type
1313

1414
def get_type(self):
15+
'''
16+
This function is called when the unmounted type (List or NonNull instance)
17+
is mounted (as a Field, InputField or Argument)
18+
'''
1519
return self
1620

1721

graphene/types/unmountedtype.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UnmountedType(OrderedType):
88
99
Instead of writing
1010
>>> class MyObjectType(ObjectType):
11-
>>> my_field = Field(String(), description='Description here')
11+
>>> my_field = Field(String, description='Description here')
1212
1313
It let you write
1414
>>> class MyObjectType(ObjectType):
@@ -21,6 +21,10 @@ def __init__(self, *args, **kwargs):
2121
self.kwargs = kwargs
2222

2323
def get_type(self):
24+
'''
25+
This function is called when the UnmountedType instance
26+
is mounted (as a Field, InputField or Argument)
27+
'''
2428
raise NotImplementedError("get_type not implemented in {}".format(self))
2529

2630
def Field(self): # noqa: N802

0 commit comments

Comments
 (0)