mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-10-30 23:47:30 +03:00 
			
		
		
		
	Use Promise.then instead of Promise.get on DjangoConnectionField
This commit is contained in:
		
							parent
							
								
									4350582c52
								
							
						
					
					
						commit
						bfcac1d48c
					
				|  | @ -62,31 +62,7 @@ class DjangoConnectionField(ConnectionField): | ||||||
|         return default_queryset & queryset |         return default_queryset & queryset | ||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     def connection_resolver(cls, resolver, connection, default_manager, max_limit, |     def resolve_connection(cls, connection, default_manager, args, iterable): | ||||||
|                             enforce_first_or_last, root, args, context, info): |  | ||||||
|         first = args.get('first') |  | ||||||
|         last = args.get('last') |  | ||||||
| 
 |  | ||||||
|         if enforce_first_or_last: |  | ||||||
|             assert first or last, ( |  | ||||||
|                 'You must provide a `first` or `last` value to properly paginate the `{}` connection.' |  | ||||||
|             ).format(info.field_name) |  | ||||||
| 
 |  | ||||||
|         if max_limit: |  | ||||||
|             if first: |  | ||||||
|                 assert first <= max_limit, ( |  | ||||||
|                     'Requesting {} records on the `{}` connection exceeds the `first` limit of {} records.' |  | ||||||
|                 ).format(first, info.field_name, max_limit) |  | ||||||
|                 args['first'] = min(first, max_limit) |  | ||||||
| 
 |  | ||||||
|             if last: |  | ||||||
|                 assert last <= max_limit, ( |  | ||||||
|                     'Requesting {} records on the `{}` connection exceeds the `last` limit of {} records.' |  | ||||||
|                 ).format(first, info.field_name, max_limit) |  | ||||||
|                 args['last'] = min(last, max_limit) |  | ||||||
| 
 |  | ||||||
|         iterable = resolver(root, args, context, info) |  | ||||||
|         iterable = Promise.resolve(iterable).get() |  | ||||||
|         if iterable is None: |         if iterable is None: | ||||||
|             iterable = default_manager |             iterable = default_manager | ||||||
|         iterable = maybe_queryset(iterable) |         iterable = maybe_queryset(iterable) | ||||||
|  | @ -111,6 +87,38 @@ class DjangoConnectionField(ConnectionField): | ||||||
|         connection.length = _len |         connection.length = _len | ||||||
|         return connection |         return connection | ||||||
| 
 | 
 | ||||||
|  |     @classmethod | ||||||
|  |     def connection_resolver(cls, resolver, connection, default_manager, max_limit, | ||||||
|  |                             enforce_first_or_last, root, args, context, info): | ||||||
|  |         first = args.get('first') | ||||||
|  |         last = args.get('last') | ||||||
|  | 
 | ||||||
|  |         if enforce_first_or_last: | ||||||
|  |             assert first or last, ( | ||||||
|  |                 'You must provide a `first` or `last` value to properly paginate the `{}` connection.' | ||||||
|  |             ).format(info.field_name) | ||||||
|  | 
 | ||||||
|  |         if max_limit: | ||||||
|  |             if first: | ||||||
|  |                 assert first <= max_limit, ( | ||||||
|  |                     'Requesting {} records on the `{}` connection exceeds the `first` limit of {} records.' | ||||||
|  |                 ).format(first, info.field_name, max_limit) | ||||||
|  |                 args['first'] = min(first, max_limit) | ||||||
|  | 
 | ||||||
|  |             if last: | ||||||
|  |                 assert last <= max_limit, ( | ||||||
|  |                     'Requesting {} records on the `{}` connection exceeds the `last` limit of {} records.' | ||||||
|  |                 ).format(first, info.field_name, max_limit) | ||||||
|  |                 args['last'] = min(last, max_limit) | ||||||
|  | 
 | ||||||
|  |         iterable = resolver(root, args, context, info) | ||||||
|  |         on_resolve = partial(cls.resolve_connection, connection, default_manager, args) | ||||||
|  | 
 | ||||||
|  |         if Promise.is_thenable(iterable): | ||||||
|  |             return Promise.resolve(iterable).then(on_resolve) | ||||||
|  | 
 | ||||||
|  |         return on_resolve(iterable) | ||||||
|  | 
 | ||||||
|     def get_resolver(self, parent_resolver): |     def get_resolver(self, parent_resolver): | ||||||
|         return partial( |         return partial( | ||||||
|             self.connection_resolver, |             self.connection_resolver, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user