Graphene-django: How to disable GraphiQL IDE on production?

Created on 10 Jul 2019  路  3Comments  路  Source: graphql-python/graphene-django

How can I disable the GraphiQL IDE on production?

Most helpful comment

Might as well use

path('graphql/', GraphQLView.as_view(graphiql=settings.DEBUG), name='graphql')

All 3 comments

Hi @amiyatulu - this is how I do it:

In urls.py I import the settings.DEBUG value and then add graphiql ONLY if debug is true:

from django.conf import settings

url_patterns = [...normal_patterns]

if settings.DEBUG:
    url_patterns.extend([...graphiql_url])

Thanks,
This is my code in urls.py:

if settings.DEBUG:
    urlpatterns += path('graphql', csrf_exempt(jwt_cookie(GraphQLView.as_view(graphiql=True)))),
else:
    urlpatterns += path('graphql', csrf_exempt(jwt_cookie(GraphQLView.as_view()))),

Might as well use

path('graphql/', GraphQLView.as_view(graphiql=settings.DEBUG), name='graphql')
Was this page helpful?
0 / 5 - 0 ratings