Skip to content

Fix graphene 1.3 annotation bug #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphene_django/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_manager(self):

@classmethod
def merge_querysets(cls, default_queryset, queryset):
return default_queryset & queryset
return queryset & default_queryset

@classmethod
def connection_resolver(cls, resolver, connection, default_manager, max_limit,
Expand Down
59 changes: 59 additions & 0 deletions graphene_django/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,65 @@ def resolve_all_reporters(self, args, context, info):
}


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,
reason="django-filter should be installed")
def test_should_query_node_filtering():
Expand Down