Improved documentation in UnmountedTypes

This commit is contained in:
Syrus Akbary 2016-10-21 08:44:44 -07:00
parent 0a80119f5e
commit 47d7adf7b0
5 changed files with 24 additions and 3 deletions

View File

@ -58,5 +58,10 @@ class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):
kind of type, often integers.
'''
def get_type(self):
return type(self)
@classmethod
def get_type(cls):
'''
This function is called when the unmounted type (Enum instance)
is mounted (as a Field, InputField or Argument)
'''
return cls

View File

@ -50,4 +50,8 @@ class InputObjectType(six.with_metaclass(InputObjectTypeMeta, UnmountedType)):
@classmethod
def get_type(cls):
'''
This function is called when the unmounted type (InputObjectType instance)
is mounted (as a Field, InputField or Argument)
'''
return cls

View File

@ -43,6 +43,10 @@ class Scalar(six.with_metaclass(ScalarTypeMeta, UnmountedType)):
@classmethod
def get_type(cls):
'''
This function is called when the unmounted type (Scalar instance)
is mounted (as a Field, InputField or Argument)
'''
return cls
# As per the GraphQL Spec, Integers are only treated as valid when a valid

View File

@ -12,6 +12,10 @@ class Structure(UnmountedType):
self.of_type = of_type
def get_type(self):
'''
This function is called when the unmounted type (List or NonNull instance)
is mounted (as a Field, InputField or Argument)
'''
return self

View File

@ -8,7 +8,7 @@ class UnmountedType(OrderedType):
Instead of writing
>>> class MyObjectType(ObjectType):
>>> my_field = Field(String(), description='Description here')
>>> my_field = Field(String, description='Description here')
It let you write
>>> class MyObjectType(ObjectType):
@ -21,6 +21,10 @@ class UnmountedType(OrderedType):
self.kwargs = kwargs
def get_type(self):
'''
This function is called when the UnmountedType instance
is mounted (as a Field, InputField or Argument)
'''
raise NotImplementedError("get_type not implemented in {}".format(self))
def Field(self): # noqa: N802