-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add queryset options to DjangoListObjectType Meta class for specify w…
…anted model queryset. Add AuthenticatedGraphQLView on graphene_django_extras.views for use 'permission', 'authorization' and 'throttle' classes based on the DRF settings. Special thanks to [@jacobh](https://github.com/jacobh) for this [comment](graphql-python/graphene#249 (comment))
- Loading branch information
Ernesto Perez Amigo
committed
Oct 24, 2017
1 parent
c6236f9
commit 12dc8c8
Showing
9 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from graphene_django.views import GraphQLView | ||
from rest_framework.decorators import (authentication_classes, permission_classes, api_view, throttle_classes) | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.request import Request | ||
from rest_framework.settings import api_settings | ||
from rest_framework.views import APIView | ||
|
||
|
||
class AuthenticatedGraphQLView(GraphQLView, APIView): | ||
""" | ||
Extra Graphql view that use 'permission', 'authorization' and 'throttle' classes based on the DRF settings. | ||
Thanks to @jacobh in (https://github.com/graphql-python/graphene/issues/249#issuecomment-300068390) | ||
""" | ||
def parse_body(self, request): | ||
if isinstance(request, Request): | ||
return request.data | ||
return super(AuthenticatedGraphQLView, self).parse_body(request) | ||
|
||
@classmethod | ||
def as_view(cls, *args, **kwargs): | ||
view = super(AuthenticatedGraphQLView, cls).as_view(*args, **kwargs) | ||
view = permission_classes((IsAuthenticated,))(view) | ||
view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view) | ||
view = throttle_classes(api_settings.DEFAULT_THROTTLE_CLASSES)(view) | ||
view = api_view(['GET', 'POST'])(view) | ||
|
||
return view |