Skip to main content

Graphene-Generator

A Graphene-Django (GraphQL) queries and mutations generator

You can:

  • Generate queries and mutations based on the specified model(s)

  • Require authentication for some and/or all generated queries/mutations

Tech

Graphene-Generator uses a number of open source projects to work properly:

If you are not familiar with the above technologies, please refer to their respective documentation.

And of course Graphene-generator itself is open source with a public repository on GitHub.

Quickstart

For installing graphene, just run this command in your shell:

pip install "graphene-generator"

Settings

We need to specify the model(s) name to be used and their respective path(s)

GRAPHENE_GENERATOR_MODELS = [
    {
        'name': 'ingredient',
        'path': 'path.to.the.model',
    }
]

Note that GRAPHENE_GENERATOR_MODELS is an array to support many models at once.

Authentication

If we want to require the authentication, we need to specify that in our settings under the require_auth dictionary for each model

GRAPHENE_GENERATOR_MODELS = [
    {
        # ...
        'require_auth': {
            'queries': ["all", "single"],
            'mutations': ["create", 'update', 'delete']
        }
    }
]

To make the difference between Mutations and Queries the require_auth contains queries and mutations as different keys.

Below are the different values and their meaning:

Queries

Key word

Meaning

all

The get all query (usually the model['name'] + s)

single

The get one query (usually the model['name'])

Mutations

Key word

Meaning

create

The create mutation

update

The update mutation

delete

The delete mutation

Schema

We need to import the QueriesHolder and/or MutationsHolder classes into our schema used by graphene and you should be able to see the generated CRUD operations into you schema.

Examples

Here is a simple Django model:

from django.db import models

class Ingredient(models.Model):
    name = models.CharField(max_length=100)
    notes = models.TextField()

Based on the above model ou settings would look like:

GRAPHENE_GENERATOR_MODELS = [
    {
        'name': 'ingredient',
        'path': 'ingredients.models.Ingredient',
        'require_auth': {
            'queries': ["all", "single"],
            'mutations': ["create", 'update', 'delete']
        }
    }
]

Here is a graphene schema sample which use the generated requests:

import graphene

from graphene_generator.holder import QueriesHolder, MutationsHolder


class Query(QueriesHolder, graphene.ObjectType):
    pass


class Mutation(MutationsHolder, graphene.ObjectType):
    pass


schema = graphene.Schema(query=Query, mutation=MutationsHolder)

Then you can query the schema:

query = '''
    query {
      ingredients {
        name,
        notes
      }
    }
'''
result = schema.execute(query)

Todos

  • Write Tests

  • Handle model’s relations properly

  • Use corresponding graphene scalar type for each field(currently using string for all fields)

  • Handle pagination

License

MIT

Metadata

Release files for graphene-generator 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphene-generator 0.1.2
File Size Uploaded Provenance Actions
graphene_generator-0.1.2.tar.gz 7.0 kB Without provenance Details for graphene_generator-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graphene-generator 0.1.2
File Interpreter ABI Platform Actions
graphene_generator-0.1.2-py3-none-any.whl Python 3 none any Details for graphene_generator-0.1.2-py3-none-any.whl

Total release size: 15.9 kB

Release files / graphene_generator-0.1.2.tar.gz

Download URL graphene_generator-0.1.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
428a47bdecf796dd9cfafcf3e9f432b9e3e70c36746a6154406cf7dcf46c7f88
BLAKE2b-256 checksum
How to use checksums
e9b92a86c545d30a4f88364fde6fdb029fb862049092914aba7c3aee1dd09ccc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.5

Release files / graphene_generator-0.1.2-py3-none-any.whl

Download URL graphene_generator-0.1.2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e78243b05cf94cf616cf11e5478cfddf4623d1a84012994b45a46bea119a0019
BLAKE2b-256 checksum
How to use checksums
478cfe274dd53831be88f4952a4706b063d291df507601a73b736d8bba91bac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.5

Security for graphene-generator 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page