-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ways to limit access
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Limiting Access to Graphql Endpoint | ||
----------------------------------- | ||
|
||
To limit access to login users to the ``/graphql`` endpoint import the | ||
``login_required`` decorator and wrap the path for the url pattern. | ||
|
||
.. code:: python | ||
#url.py | ||
from django.contrib.auth.decorators import login_required | ||
urlpatterns = [ | ||
path("graphql/", login_required(GraphQLView.as_view(schema=schema))), | ||
] | ||
Limit access to user fields | ||
--------------------------- | ||
|
||
To limit access to user objects, ``info`` in the resolver function can | ||
be called to get the user context data. | ||
|
||
.. code:: python | ||
#resolvers.py | ||
query = QueryType() | ||
@query.field("Books") | ||
def resolve_books(_, info): | ||
return Book.objects.filter(user=info.context.user) |