Django GraphiQL Debug Toolbar

0.2.0 · active · verified Thu Apr 16

django-graphiql-debug-toolbar integrates the powerful Django Debug Toolbar into the GraphiQL IDE, allowing developers to inspect SQL queries, cache hits, CPU time, and other performance metrics directly within their GraphQL development environment. It currently stands at version 0.2.0, with a release cadence that has been infrequent since its last major update in 2021.

Common errors

Warnings

Install

Imports

Quickstart

To quickly set up `django-graphiql-debug-toolbar`, first install it and `django-debug-toolbar`. Then, modify your Django project's `settings.py` by adding `debug_toolbar` and `graphiql_debug_toolbar` to `INSTALLED_APPS`. Crucially, replace the default `DebugToolbarMiddleware` with `graphiql_debug_toolbar.middleware.DebugToolbarMiddleware` in your `MIDDLEWARE` list. Ensure `DEBUG` is `True` and `INTERNAL_IPS` is configured. Finally, include the `debug_toolbar.urls` in your project's `urls.py`, typically conditional on `settings.DEBUG`.

# settings.py

import os

DEBUG = True # Must be True for the toolbar to show

INSTALLED_APPS = [
    # ... other Django apps
    'django.contrib.staticfiles',
    'debug_toolbar',
    'graphiql_debug_toolbar',
    # 'graphene_django' if using Graphene,
    # ...
]

MIDDLEWARE = [
    # ... other middleware
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # Ensure this comes after other middleware that might encode content
    # and before any middleware that modifies the response too much.
    # Replace the standard DebugToolbarMiddleware with the GraphiQL version
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
    'graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
]

INTERNAL_IPS = [
    '127.0.0.1',
    # Add other internal IPs if you're developing in a container/VM
    # '10.0.2.2', # For Android emulator if running Django in Docker
]

STATIC_URL = 'static/'

# urls.py (in your project's main urls.py)

from django.conf import settings
from django.urls import include, path

urlpatterns = [
    # ... your other url patterns
]

if settings.DEBUG:
    urlpatterns += [
        path('__debug__/', include('debug_toolbar.urls')),
    ]

view raw JSON →