[Django][Auth] About GraphQLView and (not) AnonymousUser #625
-
I followed tutorial on page https://ariadnegraphql.org/docs/django-integration and integrated ariadne with Django. Typical scenario for most of APIs - get some user related data. I logged in to Django based project as admin (using default Django admin panel /admin/) and I also replaced example resolver code line to I opened http://127.0.0.1:8000/graphql/ and executed this request:
And got this result:
How to fix it?.. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Just to mention, I tried to make request from browser console, this works as expected:
So problem related with GraphQLView and related things... |
Beta Was this translation helpful? Give feedback.
-
You are not authenticated with the API because your JS code is not sending any authentication credentials. Assuming you are using default Django auth, it requires session cookies to work, and fetch needs to be told to include those. |
Beta Was this translation helpful? Give feedback.
-
@rafalp Thank you for answer! But how to fix it, it's not clear for me?.. My custom request (from second message) works without any problems at all, I used browser console to execute it and got my user name as excepted. But this web GUI, https://127.0.0.1:8000/graphql/ (Playground) not works as expected. I opened browser dev tools, Network page and discovered that It uses http://cdn.jsdelivr.net/npm/graphql-playground-react/node_modules/apollo-link-http/lib/bundle.esm.js to create fetch requests. So looks like it's integration bug between Playground and ariadne. Ariadne need change some Playground config (include fetch options) to make Playground works correctly... |
Beta Was this translation helpful? Give feedback.
-
There are two things here: There's indeed a bug with DEFAULT_PLAYGROUND_OPTIONS = {"settings": {"request.credentials": "same-origin"}} This bug can be worked around by defining this setting in your path(
'graphql/',
GraphQLView.as_view(
schema=schema,
playground_options={
"settings": {
"request.credentials": "include"
}
}
),
name='graphql',
), We've deprecated Could you please raise this issue with ariadne-django maintainers? Thanks! |
Beta Was this translation helpful? Give feedback.
There are two things here:
There's indeed a bug with
DEFAULT_PLAYGROUND_OPTIONS
. Correct value would be:This bug can be worked around by defining this setting in your
GraphQLView
:We've deprecated
ariadne.contrib.django
with plan to remove this code from Ariadne's codebase soonish, which makes fixing this in Ariadne counter-productive …