mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 09:57:53 +03:00 
			
		
		
		
	
							parent
							
								
									afec960e4d
								
							
						
					
					
						commit
						b3c761b1c8
					
				| 
						 | 
					@ -57,7 +57,7 @@ class DjangoConnectionField(ConnectionField):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def merge_querysets(cls, default_queryset, queryset):
 | 
					    def merge_querysets(cls, default_queryset, queryset):
 | 
				
			||||||
        return default_queryset & queryset
 | 
					        return queryset & default_queryset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def connection_resolver(cls, resolver, connection, default_manager, max_limit,
 | 
					    def connection_resolver(cls, resolver, connection, default_manager, max_limit,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -284,6 +284,65 @@ def test_should_query_connectionfields():
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_should_keep_annotations():
 | 
				
			||||||
 | 
					    from django.db.models import (
 | 
				
			||||||
 | 
					        Count,
 | 
				
			||||||
 | 
					        Avg,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class ReporterType(DjangoObjectType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class Meta:
 | 
				
			||||||
 | 
					            model = Reporter
 | 
				
			||||||
 | 
					            interfaces = (Node, )
 | 
				
			||||||
 | 
					            only_fields = ('articles', )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class ArticleType(DjangoObjectType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class Meta:
 | 
				
			||||||
 | 
					            model = Article
 | 
				
			||||||
 | 
					            interfaces = (Node, )
 | 
				
			||||||
 | 
					            filter_fields = ('lang', )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Query(graphene.ObjectType):
 | 
				
			||||||
 | 
					        all_reporters = DjangoConnectionField(ReporterType)
 | 
				
			||||||
 | 
					        all_articles = DjangoConnectionField(ArticleType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def resolve_all_reporters(self, args, context, info):
 | 
				
			||||||
 | 
					            return Reporter.objects.annotate(articles_c=Count('articles')).order_by('articles_c')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def resolve_all_articles(self, args, context, info):
 | 
				
			||||||
 | 
					            return Article.objects.annotate(import_avg=Avg('importance')).order_by('import_avg')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    schema = graphene.Schema(query=Query)
 | 
				
			||||||
 | 
					    query = '''
 | 
				
			||||||
 | 
					        query ReporterConnectionQuery {
 | 
				
			||||||
 | 
					          allReporters {
 | 
				
			||||||
 | 
					            pageInfo {
 | 
				
			||||||
 | 
					              hasNextPage
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            edges {
 | 
				
			||||||
 | 
					              node {
 | 
				
			||||||
 | 
					                id
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          allArticles {
 | 
				
			||||||
 | 
					            pageInfo {
 | 
				
			||||||
 | 
					              hasNextPage
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            edges {
 | 
				
			||||||
 | 
					              node {
 | 
				
			||||||
 | 
					                id
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    '''
 | 
				
			||||||
 | 
					    result = schema.execute(query)
 | 
				
			||||||
 | 
					    assert not result.errors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
 | 
					@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
 | 
				
			||||||
                    reason="django-filter should be installed")
 | 
					                    reason="django-filter should be installed")
 | 
				
			||||||
def test_should_query_node_filtering():
 | 
					def test_should_query_node_filtering():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user