Default QuerySet for DjangoObjectType has no effect with graphene.List
See original GitHub issueThe documentation describes the use of a default QuerySet on ObjectType level.
The unit test for this functionality makes use of DjangoConnectionField.
Using graphene.List
instead ignores the existence of the default QuerySet.
class CurrencyType(DjangoObjectType):
class Meta:
model = Currency
@classmethod
def get_queryset(cls, queryset, info):
print(cls)
print(queryset)
return queryset.filter(symbol__isnull=False)
all_currencies = graphene.List(CurrencyType)
def resolve_all_currencies(self, info):
return Currency.objects.all()
The get_queryset
method is never called, and the filter is not applied.
Please refer to #698 for some history on this.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (4 by maintainers)
Top Results From Across the Web
graphene-django custom get_queryset of DjangoObjectType ...
For anyone looking for the answer to this question, it is answered here. Try swapping out List for DjangoConnectionField.
Read more >Queries & ObjectTypes - Graphene-Python
By default, DjangoObjectType will present all fields on a Model through GraphQL. If you only want a subset of fields to be present,...
Read more >Django + Graphene: From REST to GraphQL - FullStack Labs
The truth is not only can you use GraphQL on top of your current Django app but ... The DjangoObjectType by default includes...
Read more >Build a Blog Using Django, Vue, and GraphQL - Real Python
This tutorial is structured as a step-by-step project so you can learn in a ... Import Graphene-Django's DjangoObjectType , your blog models, and...
Read more >Step-by-step guide to use GraphQL with Django - Bird Eats Bug
As previously said, every query must have a corresponding resolve function, else Graphene will have no idea what to return. To return the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue should actually be fixed as part of my PR. I’ll add a test to confirm.
Awesome @jkimbo! I have it working now for the example I provided (I don’t need a resolver on the query level here). I think it actually makes sense as it is called the “Default QuerySet”.
Something that still doesn’t work as I hoped is the following: When
Currency
from my example is a related field in another table, let’s sayFund
, a query for funds does not callget_queryset
in theCurrencyType
class.If that would be possible it provides an easy way to protect from returning too much data for specific tables (this is especially important for the User table being a related field).