Skip to content

Commit

Permalink
Create PermissionsDoc.rst (#58)
Browse files Browse the repository at this point in the history
added ways to limit access
  • Loading branch information
ccsv authored Aug 23, 2022
1 parent edfada5 commit 2babb8f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Docs/PermissionsDoc.rst
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)

0 comments on commit 2babb8f

Please sign in to comment.