A graphene-django wrapper to do stuffs in the Django way 💃🕺
Project description
Dj Graphene
This package adds extra functionalities to graphene-django to make stuffs more in the "django way", writing less code and get more things done.
WARNING: This is still in development and some things may not work properly. I will try to solve all the bugs ASAP but it may take time.
Features
Note: By installing this package graphene and graphene-django will be available so all the features of those packages are also available.
- New base type: ModelObjectType
- ModelObjectType allow to create new types with default permissions. The fields in this package only works with subtypes of ModelObjectType
- A straightforward but powerful permissions system (like DRF permissions)
- New fields: RelayConnectionField, RelayFilterConnectionField
- DjangoModelMutation
- Allow to create easily create/update/delete mutations
Types
For the following examples we will use these models:
class Author(models.Model):
name = models.CharField(max_length=100, blank=False)
birthday = models.DateField()
class Book(models.Model):
isbn = models.CharField(max_length=30, unique=True)
title = models.CharField(max_length=100, blank=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
The types would look like this:
class AuthorNode(ModelObjectType):
class Meta:
model = Author
filter_fields = {
'name': ['exact', 'icontains', 'istartswith'],
}
# we use RelayNode instead of graphene.relay.Node
interfaces = (RelayNode, )
permission_classes = (IsAuthenticated, )
class BookNode(ModelObjectType):
class Meta:
model = Book
interfaces = (RelayNode, )
permission_classes = (IsAuthenticated, )
Queries
class Query(graphene.ObjectType):
author = RelayNode.Field(AuthorNode)
authors = RelayFilterConnectionField(AuthorNode)
book = RelayNode.Field(BookNode)
books = RelayFilterConnectionField(BookNode)
Mutations
class NewAuthorMutation(DjangoModelMutation):
class Meta:
model = Author
fields = ('name', 'birthday')
permission_classes = (IsAuthenticated, )
class UpdateAuthorMutation(DjangoModelMutation):
class Meta:
model = Author
permission_classes = (IsAuthenticated, )
class DeleteAuthorMutation(DjangoModelMutation):
class Meta:
model = Author
fields = ['id']
# required param to indicate that this is a delete mutation
deleting = True
# is_relay is used to translate GlobalId into Django IDs
is_relay = True
permission_classes = (IsAuthenticated, )
class Mutations(graphene.ObjectType):
create_author = NewAuthorMutation.Field()
update_author = UpdateAuthorMutation.Field()
delete_author = DeleteAuthorMutation.Field()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj-graphene-0.0.2b2.tar.gz.
File metadata
- Download URL: dj-graphene-0.0.2b2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dacc2ed5f0747a3d675b4c7c5472b8b4243a2f63f9d2b663cb354600ee9a086f
|
|
| MD5 |
bbf84ece9fcc595dfd88e455e345f156
|
|
| BLAKE2b-256 |
c9fc6a20d4d3bd5370445b71484d01ed51ef50ba37c8f18594d81a5ae7f0f01d
|
File details
Details for the file dj_graphene-0.0.2b2-py3-none-any.whl.
File metadata
- Download URL: dj_graphene-0.0.2b2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a41d87dd55d7fffc383114dcc1c3c1ae1bf8fbd574ba668a9b76cb1b886ba2
|
|
| MD5 |
5b829435c8024090108ebd7e0b834c31
|
|
| BLAKE2b-256 |
4edc5cee00357c2b57de4c7d23b730e8c965cdc178723eff4b0ed1a0928d2d8f
|