@@ -284,6 +284,65 @@ def resolve_all_reporters(self, args, context, info):
284284 }
285285
286286
287+ def test_should_keep_annotations ():
288+ from django .db .models import (
289+ Count ,
290+ Avg ,
291+ )
292+
293+ class ReporterType (DjangoObjectType ):
294+
295+ class Meta :
296+ model = Reporter
297+ interfaces = (Node , )
298+ only_fields = ('articles' , )
299+
300+ class ArticleType (DjangoObjectType ):
301+
302+ class Meta :
303+ model = Article
304+ interfaces = (Node , )
305+ filter_fields = ('lang' , )
306+
307+ class Query (graphene .ObjectType ):
308+ all_reporters = DjangoConnectionField (ReporterType )
309+ all_articles = DjangoConnectionField (ArticleType )
310+
311+ def resolve_all_reporters (self , args , context , info ):
312+ return Reporter .objects .annotate (articles_c = Count ('articles' )).order_by ('articles_c' )
313+
314+ def resolve_all_articles (self , args , context , info ):
315+ return Article .objects .annotate (import_avg = Avg ('importance' )).order_by ('import_avg' )
316+
317+ schema = graphene .Schema (query = Query )
318+ query = '''
319+ query ReporterConnectionQuery {
320+ allReporters {
321+ pageInfo {
322+ hasNextPage
323+ }
324+ edges {
325+ node {
326+ id
327+ }
328+ }
329+ }
330+ allArticles {
331+ pageInfo {
332+ hasNextPage
333+ }
334+ edges {
335+ node {
336+ id
337+ }
338+ }
339+ }
340+ }
341+ '''
342+ result = schema .execute (query )
343+ assert not result .errors
344+
345+
287346@pytest .mark .skipif (not DJANGO_FILTER_INSTALLED ,
288347 reason = "django-filter should be installed" )
289348def test_should_query_node_filtering ():
0 commit comments