mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 01:47:45 +03:00 
			
		
		
		
	Improved default field getter and improved relay connection resolver
This commit is contained in:
		
							parent
							
								
									39a4fe20b3
								
							
						
					
					
						commit
						33c58f6cfa
					
				| 
						 | 
				
			
			@ -51,6 +51,16 @@ class Field(NamedType, OrderedType):
 | 
			
		|||
    def resolver(self):
 | 
			
		||||
        return self.resolver_fn or self.get_resolver_fn()
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def default(self):
 | 
			
		||||
        if callable(self._default):
 | 
			
		||||
            return self._default()
 | 
			
		||||
        return self._default
 | 
			
		||||
 | 
			
		||||
    @default.setter
 | 
			
		||||
    def default(self, value):
 | 
			
		||||
        self._default = value
 | 
			
		||||
 | 
			
		||||
    def get_resolver_fn(self):
 | 
			
		||||
        resolve_fn_name = 'resolve_%s' % self.attname
 | 
			
		||||
        if hasattr(self.object_type, resolve_fn_name):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,15 +23,15 @@ class ConnectionField(Field):
 | 
			
		|||
        self.connection_type = connection_type
 | 
			
		||||
        self.edge_type = edge_type
 | 
			
		||||
 | 
			
		||||
    def wrap_resolved(self, value, instance, args, info):
 | 
			
		||||
        return value
 | 
			
		||||
 | 
			
		||||
    def resolver(self, instance, args, info):
 | 
			
		||||
        schema = info.schema.graphene_schema
 | 
			
		||||
        connection_type = self.get_type(schema)
 | 
			
		||||
        resolved = super(ConnectionField, self).resolver(instance, args, info)
 | 
			
		||||
        if isinstance(resolved, connection_type):
 | 
			
		||||
            return resolved
 | 
			
		||||
        return self.from_list(connection_type, resolved, args, info)
 | 
			
		||||
 | 
			
		||||
    def from_list(self, connection_type, resolved, args, info):
 | 
			
		||||
        return connection_type.from_list(resolved, args, info)
 | 
			
		||||
 | 
			
		||||
    def get_connection_type(self, node):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user