mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 19:43:56 +03:00
Merge branch 'refs/heads/master' into features/plugins-autocamelcase
Conflicts: graphene/core/schema.py
This commit is contained in:
commit
9e1dd8e314
|
@ -55,22 +55,20 @@ class Schema(object):
|
|||
objecttype = plugin.transform_type(objecttype)
|
||||
return objecttype.internal_type(self)
|
||||
|
||||
def T(self, object_type):
|
||||
if not object_type:
|
||||
def T(self, _type):
|
||||
if not _type:
|
||||
return
|
||||
if inspect.isclass(object_type) and issubclass(
|
||||
object_type, (BaseType, ClassType)) or isinstance(
|
||||
object_type, BaseType):
|
||||
if object_type not in self._types:
|
||||
internal_type = self.get_internal_type(object_type)
|
||||
self._types[object_type] = internal_type
|
||||
is_objecttype = inspect.isclass(
|
||||
object_type) and issubclass(object_type, ClassType)
|
||||
if is_objecttype:
|
||||
self.register(object_type)
|
||||
return self._types[object_type]
|
||||
is_classtype = inspect.isclass(_type) and issubclass(_type, ClassType)
|
||||
is_instancetype = isinstance(_type, BaseType)
|
||||
if is_classtype or is_instancetype:
|
||||
if _type not in self._types:
|
||||
internal_type = self.get_internal_type(_type)
|
||||
self._types[_type] = internal_type
|
||||
if is_classtype:
|
||||
self.register(_type)
|
||||
return self._types[_type]
|
||||
else:
|
||||
return object_type
|
||||
return _type
|
||||
|
||||
@property
|
||||
def executor(self):
|
||||
|
|
|
@ -4,7 +4,7 @@ from .definitions import List, NonNull
|
|||
# Compatibility import
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
|
@ -26,5 +26,4 @@ __all__ = [
|
|||
'ID',
|
||||
'Boolean',
|
||||
'Int',
|
||||
'Float',
|
||||
'Scalar']
|
||||
'Float']
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID,
|
||||
GraphQLInt, GraphQLScalarType, GraphQLString)
|
||||
GraphQLInt, GraphQLString)
|
||||
|
||||
from .base import MountedType
|
||||
|
||||
|
@ -22,20 +22,3 @@ class ID(MountedType):
|
|||
|
||||
class Float(MountedType):
|
||||
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
|
||||
)
|
||||
|
|
|
@ -13,7 +13,7 @@ from ..scalars import String
|
|||
def test_field_internal_type():
|
||||
resolver = lambda *args: 'RESOLVED'
|
||||
|
||||
field = Field(String, description='My argument', resolver=resolver)
|
||||
field = Field(String(), description='My argument', resolver=resolver)
|
||||
|
||||
class Query(ObjectType):
|
||||
my_field = field
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from graphql.core.type import (GraphQLBoolean, GraphQLFloat, GraphQLID,
|
||||
GraphQLInt, GraphQLScalarType, GraphQLString)
|
||||
GraphQLInt, GraphQLString)
|
||||
|
||||
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()
|
||||
|
||||
|
@ -26,29 +26,3 @@ def test_id_scalar():
|
|||
|
||||
def test_float_scalar():
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user