Merge branch 'refs/heads/master' into features/plugins-autocamelcase

Conflicts:
	graphene/core/schema.py
This commit is contained in:
Syrus Akbary 2015-12-06 15:34:31 -08:00
commit 9e1dd8e314
5 changed files with 18 additions and 64 deletions

View File

@ -55,22 +55,20 @@ class Schema(object):
objecttype = plugin.transform_type(objecttype) objecttype = plugin.transform_type(objecttype)
return objecttype.internal_type(self) return objecttype.internal_type(self)
def T(self, object_type): def T(self, _type):
if not object_type: if not _type:
return return
if inspect.isclass(object_type) and issubclass( is_classtype = inspect.isclass(_type) and issubclass(_type, ClassType)
object_type, (BaseType, ClassType)) or isinstance( is_instancetype = isinstance(_type, BaseType)
object_type, BaseType): if is_classtype or is_instancetype:
if object_type not in self._types: if _type not in self._types:
internal_type = self.get_internal_type(object_type) internal_type = self.get_internal_type(_type)
self._types[object_type] = internal_type self._types[_type] = internal_type
is_objecttype = inspect.isclass( if is_classtype:
object_type) and issubclass(object_type, ClassType) self.register(_type)
if is_objecttype: return self._types[_type]
self.register(object_type)
return self._types[object_type]
else: else:
return object_type return _type
@property @property
def executor(self): def executor(self):

View File

@ -4,7 +4,7 @@ from .definitions import List, NonNull
# Compatibility import # Compatibility import
from .objecttype import Interface, ObjectType, Mutation, InputObjectType from .objecttype import Interface, ObjectType, Mutation, InputObjectType
from .scalars import String, ID, Boolean, Int, Float, Scalar from .scalars import String, ID, Boolean, Int, Float
from .field import Field, InputField from .field import Field, InputField
__all__ = [ __all__ = [
@ -26,5 +26,4 @@ __all__ = [
'ID', 'ID',
'Boolean', 'Boolean',
'Int', 'Int',
'Float', 'Float']
'Scalar']

View File

@ -1,5 +1,5 @@
from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID, from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID,
GraphQLInt, GraphQLScalarType, GraphQLString) GraphQLInt, GraphQLString)
from .base import MountedType from .base import MountedType
@ -22,20 +22,3 @@ class ID(MountedType):
class Float(MountedType): class Float(MountedType):
T = GraphQLFloat T = GraphQLFloat
class Scalar(MountedType):
@classmethod
def internal_type(cls, schema):
serialize = getattr(cls, 'serialize')
parse_literal = getattr(cls, 'parse_literal')
parse_value = getattr(cls, 'parse_value')
return GraphQLScalarType(
name=cls.__name__,
description=cls.__doc__,
serialize=serialize,
parse_value=parse_value,
parse_literal=parse_literal
)

View File

@ -13,7 +13,7 @@ from ..scalars import String
def test_field_internal_type(): def test_field_internal_type():
resolver = lambda *args: 'RESOLVED' resolver = lambda *args: 'RESOLVED'
field = Field(String, description='My argument', resolver=resolver) field = Field(String(), description='My argument', resolver=resolver)
class Query(ObjectType): class Query(ObjectType):
my_field = field my_field = field

View File

@ -1,9 +1,9 @@
from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID, from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID,
GraphQLInt, GraphQLScalarType, GraphQLString) GraphQLInt, GraphQLString)
from graphene.core.schema import Schema from graphene.core.schema import Schema
from ..scalars import ID, Boolean, Float, Int, Scalar, String from ..scalars import ID, Boolean, Float, Int, String
schema = Schema() schema = Schema()
@ -26,29 +26,3 @@ def test_id_scalar():
def test_float_scalar(): def test_float_scalar():
assert schema.T(Float()) == GraphQLFloat assert schema.T(Float()) == GraphQLFloat
def test_custom_scalar():
import datetime
from graphql.core.language import ast
class DateTimeScalar(Scalar):
'''DateTimeScalar Documentation'''
@staticmethod
def serialize(dt):
return dt.isoformat()
@staticmethod
def parse_literal(node):
if isinstance(node, ast.StringValue):
return datetime.datetime.strptime(
node.value, "%Y-%m-%dT%H:%M:%S.%f")
@staticmethod
def parse_value(value):
return datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")
scalar_type = schema.T(DateTimeScalar)
assert isinstance(scalar_type, GraphQLScalarType)
assert scalar_type.name == 'DateTimeScalar'
assert scalar_type.description == 'DateTimeScalar Documentation'