Giter Site home page Giter Site logo

Comments (10)

tadeo avatar tadeo commented on August 13, 2024 2

@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.

cfarvidson avatar cfarvidson commented on August 13, 2024 1

I’m also very interested in this.

I want to use it with https://github.com/flavors/django-graphql-jwt

from graphene-django-extras.

aldarund avatar aldarund commented on August 13, 2024 1

@gsiegman http://django-filter.readthedocs.io/en/latest/guide/usage.html#filtering-the-primary-qs

from graphene-django-extras.

eamigo86 avatar eamigo86 commented on August 13, 2024

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.

gregbrowndev avatar gregbrowndev commented on August 13, 2024

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.

tadeo avatar tadeo commented on August 13, 2024

@gregbrowndev just curious, did you try the filterset_class workaround I suggest?

from graphene-django-extras.

gsiegman avatar gsiegman commented on August 13, 2024

@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.

gsiegman avatar gsiegman commented on August 13, 2024

@aldarund that did it, thank you!

from graphene-django-extras.

s3rius avatar s3rius commented on August 13, 2024

@cfarvidson, if you still interested in using django-graphql-jwt with this library, you can check the request #176.

from graphene-django-extras.

cfarvidson avatar cfarvidson commented on August 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.