diff --git a/docs/config.toml b/docs/config.toml index 18ceb76a..1ac80d0c 100644 --- a/docs/config.toml +++ b/docs/config.toml @@ -22,8 +22,9 @@ ga = "UA-12613282-7" name = "Django" pages = [ "/docs/django/tutorial/", - "/docs/django/authorization/", "/docs/django/filtering/", + "/docs/django/authorization/", + "/docs/django/debug/", ] [docs.sqlalchemy] diff --git a/docs/pages/docs/django/debug.md b/docs/pages/docs/django/debug.md new file mode 100644 index 00000000..939667c8 --- /dev/null +++ b/docs/pages/docs/django/debug.md @@ -0,0 +1,51 @@ +--- +title: Django Debug Plugin +description: How to debug Django queries and requests using Graphene +--- + +# Django Debug Plugin + +You can debug your GraphQL queries in a similar way to [django-debug-toolbar](https://django-debug-toolbar.readthedocs.org/), +but outputing in the results in GraphQL response as fields, instead of the graphical HTML interface. + + +For that, you will need to add the plugin in your graphene schema. + +## Installation + +For use the Django Debug plugin in Graphene, just import `DjangoDebugPlugin` and add it to the `plugins` argument when you initiate the `Schema`. + + +```python +from graphene.contrib.django.debug import DjangoDebugPlugin + +# ... +schema = graphene.Schema(query=Query, plugins=[DjangoDebugPlugin()]) +``` + +This plugin, will add another field in the `Query` named `__debug`. + + +## Querying + +You can query it for outputing all the sql transactions that happened in the GraphQL request, like: + +```graphql +{ + # A example that will use the ORM for interact with the DB + allIngredients { + edges { + node { + id, + name + } + } + } + # Here is the debug field that will output the SQL queries + __debug { + sql { + rawSql + } + } +} +```