Comments (10)
@eamigo86 Exploring for alternatives I found that I can use a FilterSet class to filter the queryset with its filter_queryset(self, queryset)
method, having the request available at self.request.
Here the alternative way of intervening the queryset:
class Product(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
name = models.CharField(max_length=255)
discontinued = models.BooleanField(default=False)
class ProductListType(DjangoListObjectType):
class Meta:
model = Product
pagination = LimitOffsetGraphqlPagination()
class ProductFilter(django_filters.FilterSet):
class Meta:
model = Product
def filter_queryset(self, queryset):
# here I am able to filter the queryset with the request
queryset = queryset.filter(discontinued=False, owner=self.request.user)
return queryset
class Query(graphene.ObjectType):
all_products = DjangoListObjectField(ProductListType, filterset_class=ProductFilter)
Gracias!
from graphene-django-extras.
I’m also very interested in this.
I want to use it with https://github.com/flavors/django-graphql-jwt
from graphene-django-extras.
@gsiegman http://django-filter.readthedocs.io/en/latest/guide/usage.html#filtering-the-primary-qs
from graphene-django-extras.
Hi @tadeo, sorry about that, but it's a pending work that I have to do, which one will be available very soon.
from graphene-django-extras.
Hi, I also have the need for resolve_[field]
in order to add queryset annotations to my type, which isn't quite solved by #15 , i.e:
class SystemType(DjangoObjectType):
version = graphene.Int()
warning_count = graphene.Int()
class Meta:
model = System
filterset_class = SystemFilter
class SystemListType(DjangoListObjectType):
version = graphene.Int()
warning_count = graphene.Int()
class Meta:
model = System
pagination = PageGraphqlPagination(page_size=20)
filterset_class = SystemFilter
class Query(object):
systems = DjangoListObjectField(SystemListType)
system = DjangoObjectField(SystemType)
def resolve_systems(self, info, **kwargs):
return System.objects\
.add_version_number()\
.add_warning_count()
Thanks!
from graphene-django-extras.
@gregbrowndev just curious, did you try the filterset_class
workaround I suggest?
from graphene-django-extras.
@tadeo I attempted your solution, however when making a GraphQL query, my filterset's filter_queryset method never gets called. Is there anything additional you had to do beyond what is showing in your code above?
from graphene-django-extras.
@aldarund that did it, thank you!
from graphene-django-extras.
@cfarvidson, if you still interested in using django-graphql-jwt
with this library, you can check the request #176.
from graphene-django-extras.
@cfarvidson, if you still interested in using
django-graphql-jwt
with this library, you can check the request #176.
Thanks. Sadly I’ve abandoned the Django project that I used JWT in. 🙂
from graphene-django-extras.
Related Issues (20)
- pagination info HOT 2
- Updating to GitHub Actions' environment variables HOT 1
- Dynamic Schema generation
- Travis rewrite to GitHub Actions HOT 2
- TODO
- Tried installing graphene-django-extras, but get errors about incompatibility HOT 3
- ImportError: cannot import name 'force_text' from 'django.utils.encoding' HOT 1
- Regarding UnionTypes
- Pagination Total Count HOT 7
- When using a model with a UUID Field as ID the update method does not provide a UUID Field HOT 1
- No type registered for model: <model>
- Getting duplicate results on a filter across multiple fields. Cannot add distinct.
- still maintained? HOT 5
- python error: can only concatenate list (not "tuple") to list in __init__.py
- Updates removing other fields if not supplied: Might not be specific to graphene-django-extras
- ImportError: cannot import name 'JSONField' from 'graphene_django.compat'
- AssertionError: Page value for PageGraphqlPagination must be a non-zero value
- Filtering on enum fields returns all results HOT 1
- Logs received not informative
- DjangoListObjectType BigInt Error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene-django-extras.