Integrations๐
In this section, we'll cover the integrations to other libraries that Undine includes.
channels๐
Undine provides support for the GraphQL over WebSocket protocol by integrating with the channels library. Using the channels integration requires turning on Undine's Async Support.
Additionally, you need to configure Django in your project's asgi.py file
so that websocket requests are sent to Undine's channels consumer.
This will add a new route to the Django application that will handle
the WebSocket requests. The path for this route is defined using the
WEBSOCKET_PATH setting.
django-debug-toolbar๐
Undine integrates with django-debug-toolbar by modifying the toolbar HTML so that it integrates with GraphiQL. After installing django-debug-toolbar, Undine should automatically patch it without any additional configuration.
django-modeltranslation๐
Undine integrates with django-modeltranslation
by allowing you to modify how autogenerated Fields, Inputs, Filters
and Orders are created. Specifically, this happens using two settings:
MODELTRANSLATION_INCLUDE_TRANSLATABLE
and MODELTRANSLATION_INCLUDE_TRANSLATIONS.
Let's say you the following Model (with MODELTRANSLATION_LANGUAGES = ("en", "fi"))
...and the following translation options
Based on the Model's translation options, django-modeltranslation adds additional fields
for each language defined by the MODELTRANSLATION_LANGUAGES setting. Let's call the added fields
the "translatable" fields, and the fields they are based on the "translation" fields.
Using the MODELTRANSLATION_INCLUDE_TRANSLATABLE and MODELTRANSLATION_INCLUDE_TRANSLATIONS
settings, you can control which of these fields undine will add to your schema
when using autogeneration. By default, only the translation fields are added.
You can of course always add the translatable fields manually.
Note that due to the way that
django-modeltranslationworks, the translation fields are always nullable, even for the default language.
pytest๐
Undine comes with a pytest plugin that includes a testing client and few fixtures to help you write tests for your GraphQL APIs.
The GraphQLClient class is wrapper around Django's test client that
makes testing your GraphQL API easier. It can be added to a test using
the graphql fixture. Here is a simple example:
GraphQL requests can be made by calling the client as shown above.
This makes a request to the GraphQL endpoint set by the
GRAPHQL_PATH setting.
GraphQL variables can be passed using the variables argument. If these variables
include any files, the client will automatically create a GraphQL multipart request
instead of a normal GraphQL request.
The client returns a custom response object GraphQLClientResponse,
which has a number of useful properties for introspecting the response.
The response object also has details on the database queries that were executed
during the request, which can be useful for debugging the performance of your
GraphQL API.
An async version of the client is also available, which can be accessed from
the graphql_async fixture.
The plugin also includes a undine_settings fixture that allows modifying
Undine's settings during testing more easily.
If the channels integration is installed, the test client can
also send GraphQL over WebSocket requests using the over_websocket method.