mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 09:57:53 +03:00 
			
		
		
		
	Merge pull request #609 from acu/fix-connection-field-required
Fix passing required=True to DjangoConnectionField
This commit is contained in:
		
						commit
						0d178b38fb
					
				| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
from functools import partial
 | 
					from functools import partial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.db.models.query import QuerySet
 | 
					from django.db.models.query import QuerySet
 | 
				
			||||||
 | 
					from graphene import NonNull
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from promise import Promise
 | 
					from promise import Promise
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,17 +46,31 @@ class DjangoConnectionField(ConnectionField):
 | 
				
			||||||
        from .types import DjangoObjectType
 | 
					        from .types import DjangoObjectType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _type = super(ConnectionField, self).type
 | 
					        _type = super(ConnectionField, self).type
 | 
				
			||||||
 | 
					        non_null = False
 | 
				
			||||||
 | 
					        if isinstance(_type, NonNull):
 | 
				
			||||||
 | 
					            _type = _type.of_type
 | 
				
			||||||
 | 
					            non_null = True
 | 
				
			||||||
        assert issubclass(
 | 
					        assert issubclass(
 | 
				
			||||||
            _type, DjangoObjectType
 | 
					            _type, DjangoObjectType
 | 
				
			||||||
        ), "DjangoConnectionField only accepts DjangoObjectType types"
 | 
					        ), "DjangoConnectionField only accepts DjangoObjectType types"
 | 
				
			||||||
        assert _type._meta.connection, "The type {} doesn't have a connection".format(
 | 
					        assert _type._meta.connection, "The type {} doesn't have a connection".format(
 | 
				
			||||||
            _type.__name__
 | 
					            _type.__name__
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return _type._meta.connection
 | 
					        connection_type = _type._meta.connection
 | 
				
			||||||
 | 
					        if non_null:
 | 
				
			||||||
 | 
					            return NonNull(connection_type)
 | 
				
			||||||
 | 
					        return connection_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def connection_type(self):
 | 
				
			||||||
 | 
					        type = self.type
 | 
				
			||||||
 | 
					        if isinstance(type, NonNull):
 | 
				
			||||||
 | 
					            return type.of_type
 | 
				
			||||||
 | 
					        return type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def node_type(self):
 | 
					    def node_type(self):
 | 
				
			||||||
        return self.type._meta.node
 | 
					        return self.connection_type._meta.node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def model(self):
 | 
					    def model(self):
 | 
				
			||||||
| 
						 | 
					@ -151,7 +166,7 @@ class DjangoConnectionField(ConnectionField):
 | 
				
			||||||
        return partial(
 | 
					        return partial(
 | 
				
			||||||
            self.connection_resolver,
 | 
					            self.connection_resolver,
 | 
				
			||||||
            parent_resolver,
 | 
					            parent_resolver,
 | 
				
			||||||
            self.type,
 | 
					            self.connection_type,
 | 
				
			||||||
            self.get_manager(),
 | 
					            self.get_manager(),
 | 
				
			||||||
            self.max_limit,
 | 
					            self.max_limit,
 | 
				
			||||||
            self.enforce_first_or_last,
 | 
					            self.enforce_first_or_last,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user