I got some REST API endpoints in Django and I'd like to use the same authentication for Graphene. The documentation does not provide any guidance.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
Adding some additional steps that I had to take when following this integration:
Graphene was expecting the
.body
attr but DRF reads it and attaches it to.data
before being passed to GraphQLView.For example, if you are using
authentication_classes = (TokenAuthentication,)
in your API views, you could add an endpoint to a GraphQLView decorated in this way:urls.py:
Note that we added a new
^graphql_token
endpoint and kept the original^graphql
which is used by the GraphiQL tool.Then, you should set the
Authorization
header in your GraphQL client and point to thegraphql_token
endpoint.UPDATE: See this GitHub issue where people have suggested alternative solutions and full working examples.