Skip to main content

An extension for django-graphene.

Project description

https://github.com/serioeseGmbH/serious-django-graphene

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:

    INSTALLED_APPS = [
        ...
        'serious_django_graphene',
    ]
  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 details)

Uploaded Source

File details

Details for the file serious-django-graphene-0.5.1.tar.gz.

File metadata

  • Download URL: serious-django-graphene-0.5.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.6.7

File hashes

Hashes for serious-django-graphene-0.5.1.tar.gz
Algorithm Hash digest
SHA256 e5c32cb32524f46d16500c16d2870bd4ba551995f65a25e0e7e0eb508e8c2b3e
MD5 8d4bc5e1953d8b44726133320d3c6425
BLAKE2b-256 cf447eed64897cffe1ff0a01ae0d43979ef6d4411935d6aee7bab52fd544bd23

See more details on using hashes here.

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