mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Improved DjangoDebug integration.
This commit is contained in:
		
							parent
							
								
									3feae35f69
								
							
						
					
					
						commit
						f74c23f02e
					
				|  | @ -49,7 +49,8 @@ class DjangoDebugMiddleware(object): | |||
|                 raise Exception('DjangoDebug need the context to be writable, context received: {}.'.format( | ||||
|                     context.__class__.__name__ | ||||
|                 )) | ||||
|         if info.schema.graphene_schema.T(DjangoDebug) == info.return_type: | ||||
|         print info.schema.get_type('DjangoDebug'), info.return_type | ||||
|         if info.schema.get_type('DjangoDebug') == info.return_type: | ||||
|             return context.django_debug.get_debug_promise() | ||||
|         promise = next(root, args, context, info) | ||||
|         context.django_debug.add_promise(promise) | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ from time import time | |||
| from django.utils import six | ||||
| from django.utils.encoding import force_text | ||||
| 
 | ||||
| from .types import DjangoDebugSQL, DjangoDebugPostgreSQL | ||||
| from .types import DjangoDebugSQL | ||||
| 
 | ||||
| 
 | ||||
| class SQLQueryTriggered(Exception): | ||||
|  | @ -142,9 +142,8 @@ class NormalCursorWrapper(object): | |||
|                     'iso_level': iso_level, | ||||
|                     'encoding': conn.encoding, | ||||
|                 }) | ||||
|                 _sql = DjangoDebugPostgreSQL(**params) | ||||
|             else: | ||||
|                 _sql = DjangoDebugSQL(**params) | ||||
| 
 | ||||
|             _sql = DjangoDebugSQL(**params) | ||||
|             # We keep `sql` to maintain backwards compatibility | ||||
|             self.logger.object.sql.append(_sql) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| from graphene import Boolean, Float, ObjectType, String | ||||
| 
 | ||||
| 
 | ||||
| class DjangoDebugBaseSQL(ObjectType): | ||||
| class DjangoDebugSQL(ObjectType): | ||||
|     vendor = String() | ||||
|     alias = String() | ||||
|     sql = String() | ||||
|  | @ -13,12 +13,7 @@ class DjangoDebugBaseSQL(ObjectType): | |||
|     is_slow = Boolean() | ||||
|     is_select = Boolean() | ||||
| 
 | ||||
| 
 | ||||
| class DjangoDebugSQL(DjangoDebugBaseSQL): | ||||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| class DjangoDebugPostgreSQL(DjangoDebugBaseSQL): | ||||
|     # Postgres | ||||
|     trans_id = String() | ||||
|     trans_status = String() | ||||
|     iso_level = String() | ||||
|  |  | |||
|  | @ -23,10 +23,11 @@ def test_should_query_field(): | |||
|     r2 = Reporter(last_name='Griffin') | ||||
|     r2.save() | ||||
| 
 | ||||
|     class ReporterType(DjangoNode, DjangoObjectType): | ||||
|     class ReporterType(DjangoObjectType): | ||||
| 
 | ||||
|         class Meta: | ||||
|             model = Reporter | ||||
|             interfaces = (DjangoNode, ) | ||||
| 
 | ||||
|     class Query(graphene.ObjectType): | ||||
|         reporter = graphene.Field(ReporterType) | ||||
|  | @ -69,13 +70,14 @@ def test_should_query_list(): | |||
|     r2 = Reporter(last_name='Griffin') | ||||
|     r2.save() | ||||
| 
 | ||||
|     class ReporterType(DjangoNode, DjangoObjectType): | ||||
|     class ReporterType(DjangoObjectType): | ||||
| 
 | ||||
|         class Meta: | ||||
|             model = Reporter | ||||
|             interfaces = (DjangoNode, ) | ||||
| 
 | ||||
|     class Query(graphene.ObjectType): | ||||
|         all_reporters = ReporterType.List() | ||||
|         all_reporters = graphene.List(ReporterType) | ||||
|         debug = graphene.Field(DjangoDebug, name='__debug') | ||||
| 
 | ||||
|         def resolve_all_reporters(self, *args, **kwargs): | ||||
|  | @ -117,10 +119,11 @@ def test_should_query_connection(): | |||
|     r2 = Reporter(last_name='Griffin') | ||||
|     r2.save() | ||||
| 
 | ||||
|     class ReporterType(DjangoNode, DjangoObjectType): | ||||
|     class ReporterType(DjangoObjectType): | ||||
| 
 | ||||
|         class Meta: | ||||
|             model = Reporter | ||||
|             interfaces = (DjangoNode, ) | ||||
| 
 | ||||
|     class Query(graphene.ObjectType): | ||||
|         all_reporters = DjangoConnectionField(ReporterType) | ||||
|  | @ -173,13 +176,15 @@ def test_should_query_connectionfilter(): | |||
|     r2 = Reporter(last_name='Griffin') | ||||
|     r2.save() | ||||
| 
 | ||||
|     class ReporterType(DjangoNode, DjangoObjectType): | ||||
|     class ReporterType(DjangoObjectType): | ||||
| 
 | ||||
|         class Meta: | ||||
|             model = Reporter | ||||
|             interfaces = (DjangoNode, ) | ||||
| 
 | ||||
|     class Query(graphene.ObjectType): | ||||
|         all_reporters = DjangoFilterConnectionField(ReporterType) | ||||
|         s = graphene.String(resolver=lambda *_: "S") | ||||
|         debug = graphene.Field(DjangoDebug, name='__debug') | ||||
| 
 | ||||
|         def resolve_all_reporters(self, *args, **kwargs): | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| from graphene import ObjectType, List | ||||
| from .sql.types import DjangoDebugBaseSQL | ||||
| from .sql.types import DjangoDebugSQL | ||||
| 
 | ||||
| 
 | ||||
| class DjangoDebug(ObjectType): | ||||
|     sql = List(DjangoDebugBaseSQL) | ||||
|     sql = List(DjangoDebugSQL) | ||||
|  |  | |||
|  | @ -22,9 +22,6 @@ class DjangoConnectionField(ConnectionField): | |||
|         else: | ||||
|             return self.model._default_manager | ||||
| 
 | ||||
|     def default_resolver(self, root, args, context, info): | ||||
|         return getattr(root, self.source, self.get_manager()) | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def connection_resolver(resolver, connection, default_manager, root, args, context, info): | ||||
|         iterable = resolver(root, args, context, info) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user