From dd46f5ff20265f9b2fd5a0e9372beb1596c97648 Mon Sep 17 00:00:00 2001 From: Jason Kraus Date: Fri, 5 Oct 2018 10:35:34 -0700 Subject: [PATCH] document get_queryset usage --- docs/authorization.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/authorization.rst b/docs/authorization.rst index 7a08481..08e7bf2 100644 --- a/docs/authorization.rst +++ b/docs/authorization.rst @@ -96,6 +96,29 @@ schema is simple. result = schema.execute(query, context_value=request) + +Global Filtering +---------------- + +If you are using ``DjangoObjectType`` you can define a custom `get_queryset`. + +.. code:: python + + from graphene import relay + from graphene_django.types import DjangoObjectType + from .models import Post + + class PostNode(DjangoObjectType): + class Meta: + model = Post + + @classmethod + def get_queryset(cls, queryset, info): + if info.context.user.is_anonymous: + return queryset.filter(published=True) + return queryset + + Filtering ID-based Node Access ------------------------------