Improved ScalarTypes code

This commit is contained in:
Syrus Akbary 2015-12-06 15:53:56 -08:00
parent 37a454b831
commit 2724025a5b
2 changed files with 17 additions and 13 deletions

View File

@ -5,9 +5,8 @@ import six
class InstanceType(object): class InstanceType(object):
@classmethod def internal_type(self, schema):
def internal_type(cls, schema): raise NotImplementedError("internal_type for type {} is not implemented".format(self.__class__.__name__))
return getattr(cls, 'T', None)
class MountType(InstanceType): class MountType(InstanceType):

View File

@ -4,21 +4,26 @@ from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID,
from .base import MountedType from .base import MountedType
class String(MountedType): class ScalarType(MountedType):
T = GraphQLString def internal_type(self, schema):
return self._internal_type
class Int(MountedType): class String(ScalarType):
T = GraphQLInt _internal_type = GraphQLString
class Boolean(MountedType): class Int(ScalarType):
T = GraphQLBoolean _internal_type = GraphQLInt
class ID(MountedType): class Boolean(ScalarType):
T = GraphQLID _internal_type = GraphQLBoolean
class Float(MountedType): class ID(ScalarType):
T = GraphQLFloat _internal_type = GraphQLID
class Float(ScalarType):
_internal_type = GraphQLFloat