mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Moved scalar definitions
This commit is contained in:
		
							parent
							
								
									1737089c6d
								
							
						
					
					
						commit
						3529fcb29b
					
				|  | @ -1,4 +1,4 @@ | ||||||
| from .definitions import GrapheneInterfaceType, GrapheneObjectType | from .definitions import GrapheneInterfaceType, GrapheneObjectType, GrapheneScalarType | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def generate_interface(interface): | def generate_interface(interface): | ||||||
|  | @ -20,3 +20,15 @@ def generate_objecttype(objecttype): | ||||||
|         is_type_of=objecttype.is_type_of, |         is_type_of=objecttype.is_type_of, | ||||||
|         interfaces=objecttype._meta.get_interfaces |         interfaces=objecttype._meta.get_interfaces | ||||||
|     ) |     ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def generate_scalar(scalar): | ||||||
|  |     return GrapheneScalarType( | ||||||
|  |         graphene_type=scalar, | ||||||
|  |         name=scalar._meta.name or scalar.__name__, | ||||||
|  |         description=scalar._meta.description or scalar.__doc__, | ||||||
|  | 
 | ||||||
|  |         serialize=getattr(scalar, 'serialize', None), | ||||||
|  |         parse_value=getattr(scalar, 'parse_value', None), | ||||||
|  |         parse_literal=getattr(scalar, 'parse_literal', None), | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| from graphql import GraphQLObjectType, GraphQLInterfaceType | from graphql import GraphQLObjectType, GraphQLInterfaceType, GraphQLScalarType | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class GrapheneGraphQLType(object): | class GrapheneGraphQLType(object): | ||||||
|  | @ -27,3 +27,7 @@ class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType): | ||||||
|         for interface in self._provided_interfaces: |         for interface in self._provided_interfaces: | ||||||
|             if isinstance(interface, GrapheneInterfaceType): |             if isinstance(interface, GrapheneInterfaceType): | ||||||
|                 interface.graphene_type.implements(self.graphene_type) |                 interface.graphene_type.implements(self.graphene_type) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType): | ||||||
|  |     pass | ||||||
|  |  | ||||||
|  | @ -1,16 +1,13 @@ | ||||||
| import six | import six | ||||||
| 
 | 
 | ||||||
| from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, | from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, | ||||||
|                      GraphQLScalarType, GraphQLString) |                      GraphQLString) | ||||||
| 
 | 
 | ||||||
| from ..utils.is_base_type import is_base_type | from ..utils.is_base_type import is_base_type | ||||||
| from .definitions import GrapheneGraphQLType |  | ||||||
| from .options import Options | from .options import Options | ||||||
| from .unmountedtype import UnmountedType | from .unmountedtype import UnmountedType | ||||||
| 
 | 
 | ||||||
| 
 | from ..generators import generate_scalar | ||||||
| class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType): |  | ||||||
|     pass |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ScalarTypeMeta(type): | class ScalarTypeMeta(type): | ||||||
|  | @ -33,15 +30,7 @@ class ScalarTypeMeta(type): | ||||||
|         cls = super_new(cls, name, bases, dict(attrs, _meta=options)) |         cls = super_new(cls, name, bases, dict(attrs, _meta=options)) | ||||||
| 
 | 
 | ||||||
|         if not options.graphql_type: |         if not options.graphql_type: | ||||||
|             options.graphql_type = GrapheneScalarType( |             options.graphql_type = generate_scalar(cls) | ||||||
|                 graphene_type=cls, |  | ||||||
|                 name=cls._meta.name or cls.__name__, |  | ||||||
|                 description=cls._meta.description or cls.__doc__, |  | ||||||
| 
 |  | ||||||
|                 serialize=getattr(cls, 'serialize', None), |  | ||||||
|                 parse_value=getattr(cls, 'parse_value', None), |  | ||||||
|                 parse_literal=getattr(cls, 'parse_literal', None), |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|         return cls |         return cls | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user