Skip to main content

An extension for django-graphene.

Project description

serious-django-graphene offers a couple of extensions for Graphene development in Django.

  1. get_user_from_info returns the request’s user from the passed info object.

    We use this function all the time, for example, to do permission checks on the current user.

  2. FormMutation is based on FailableMutation (see below).

    It defines a Graphene mutation based on a plain old Django form. What is this good for? Well, we want to employ the builtin capabilities of Django for input validation and conversion. Why reinvent the wheel to do checks like “string of max length 50” inside Graphene mutations when Forms can do that for you, and have extensible validators?

    This is essentially a cleaned up and changed version of the FormMutation delivered with graphene-django itself. The difference is mainly in how we model the returned data in an expectable pattern, see FailableMutation.

  1. FailableMutation defines a mutation that contains:

    • A success boolean flag

    • An error value, present only if an error occurred, which is (a union of) either

      • A list of ValidationError in the format like Django returns for validation errors, or

      • An ExecutionError, which just contains an error_message String.

If you need additional fields, add them by inheriting from FailableMutation.

  1. make_failable_objecttype turns an existing graphene.ObjectType into a Field that contains:

    • A result field which is an optional value of the original type

    • A error field which is an optional String value, present only if an error occurred

    • A success boolean flag field. Strictly seen, this is superfluous, as the null-ness of result or error can be checked. However, its existence improves semantics on the client, as they can now just check if(result.success) { ... }.

Quick start

  1. Install the package with pip:

    pip install serious-django-graphene
  2. Add “serious_django_graphene” to your INSTALLED_APPS setting like this:

  3. Import and use serious_django_graphene wherever you need the Graphene extensions

  4. Import and use serious_django_graphene.testing wherever you need the Graphene test extensions

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serious-django-graphene-0.5.1.tar.gz (7.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page