Skip to content

Commit

Permalink
Optimizing imports, fix some minors bugs and working on performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Perez Amigo committed Sep 25, 2017
1 parent dbbfa33 commit c17b88a
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 200 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
include README.md
include README.rst
recursive-exclude .vscode *
include README.rst
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ pip install graphene-django-extras
1. DjangoSerializerMutation

**Types:**
1. DjangoObjectTypeExtra
2. DjangoInputObjectType
3. DjangoPaginatedObjectListType
1. DjangoObjectType
2. DjangoListObjectType
3. DjangoInputObjectType

**Pagination:**
1. LimitOffsetGraphqlPagination
2. PageGraphqlPagination
3. CursosGraphqlPagination *(cooming soon)*
3. CursorGraphqlPagination *(cooming soon)*


### Examples
Expand All @@ -46,16 +46,16 @@ Here is a use of graphene-django-extras:

```python
from django.contrib.auth.models import User
from graphene_django_extras import DjangoObjectType, DjangoPaginatedObjectListType
from graphene_django_extras import DjangoObjectType, DjangoListObjectType
from graphene_django_extras.pagination import LimitOffsetGraphqlPagination

class UserType(DjangoObjectType):
"""
This DjangoObjectType have a ID field to filter to avoid resolve method definition on Queries
This DjangoObjectType have a ID field, that allow filter by id and resolve method definition on Queries is not necesary
"""
class Meta:
model = User
description = "Type for User Model"
description = " Type definition for single User model object "
filter_fields = {
'id': ['exact', ],
'first_name': ['icontains', 'iexact'],
Expand All @@ -65,9 +65,9 @@ class UserType(DjangoObjectType):
}


class UserListType(DjangoPaginatedObjectListType):
class UserListType(DjangoListObjectType):
class Meta:
description = "User list query definition"
description = " Type definition for List of users "
model = User
pagination = LimitOffsetGraphqlPagination(page_size=20)
```
Expand All @@ -79,15 +79,15 @@ from graphene_django_extras import DjangoInputObjectType

class UserInput(DjangoInputObjectType):
class Meta:
description = " Input Type for User Model "
description = " User Input Type for used as input on Argumments classes on traditional Mutations "
model = User
```

#### 3- You can define traditional mutations that use Input Types or Mutations based on DRF SerializerClass:

```python
import graphene
from graphene_django_extras import DjangoSerializerMutation
from graphene_django_extras import DjangoSerializerMutation

from .serializers import UserSerializer
from .types import UserType
Expand All @@ -104,7 +104,7 @@ class UserSerializerMutation(DjangoSerializerMutation):

class UserMutation(graphene.mutation):
"""
You must implement the mutate function
On traditional graphene mutation classes definition you must implement the mutate function
"""

user = graphene.Field(UserType, required=False)
Expand All @@ -113,7 +113,7 @@ class UserMutation(graphene.mutation):
new_user = graphene.Argument(UserInput)

class Meta:
description = "Normal mutation for Users"
description = " Traditional graphene mutation for Users "

@classmethod
def mutate(cls, info, **kwargs):
Expand All @@ -130,14 +130,16 @@ from .mutations import UserMutation, UserSerializerMutation

class Queries(graphene.ObjectType):
# Posible User list queries definitions
all_users = DjangoListObjectField(UserListType, description=_('All Usersquery'))
all_users = DjangoListObjectField(UserListType, description=_('All Users query'))
all_users1 = DjangoFilterPaginateListField(UserType, pagination=LimitOffsetGraphqlPagination())
all_users2 = DjangoFilterListField(UserType)
all_users3 = DjangoListObjectField(UserListType, filterset_class=UserFilter, description=_('All Users query'))

# Single user queries definitions
user = DjangoObjectField(UserType, description=_('Single User query'))
other_way_user = DjangoObjectField(UserListType.getOne(), description=_('Other way to query a single User query'))
# Defining the petition to a user
user = DjangoObjectField(UserType, description=_('Single User query'))

# Another way to define a single user query
other_way_user = DjangoObjectField(UserListType.getOne(), description=_('User List with pagination and filtering'))

class Mutations(graphene.ObjectType):
user_create = UserSerializerMutation.CreateField(deprecation_reason='Deprecation message')
Expand All @@ -159,21 +161,21 @@ class Mutations(graphene.ObjectType):
}
totalCount
}

allUsers1(lastName_Iexact:"Doe", limit:5, offset:0){
id
username
firstName
lastName
lastName
}

allUsers2(firstName_Icontains: "J"){
id
username
firstName
lastName
}

user(id:2){
id
username
Expand All @@ -186,7 +188,7 @@ class Mutations(graphene.ObjectType):

```js
mutation{
userCreate(newUser:{password:"test*123", email: "test@test.com", username:"test"}){
userCreate(newUser:{username:"test", password:"test*123"}){
user{
id
username
Expand All @@ -199,15 +201,15 @@ mutation{
messages
}
}

userDelete(id:1){
ok
errors{
field
messages
}
}

userUpdate(newUser:{id:1, username:"John"}){
user{
id
Expand Down
34 changes: 18 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Extra functionalities:

Types:
1. DjangoObjectTypeExtra
2. DjangoInputObjectType
3. DjangoPaginatedObjectListType
2. DjangoListObjectType
3. DjangoInputObjectType

Pagination:
1. LimitOffsetGraphqlPagination
2. PageGraphqlPagination
3. CursosGraphqlPagination (cooming soon)
3. CursorGraphqlPagination (cooming soon)

Examples:
---------
Expand All @@ -47,17 +47,17 @@ Here is a simple use of graphene-django-extras:
.. code:: python
from django.contrib.auth.models import User
from graphene_django_extras import DjangoObjectType, DjangoPaginatedObjectListType
from graphene_django_extras import DjangoObjectType, DjangoListObjectType
from graphene_django_extras.pagination import LimitOffsetGraphqlPagination
class UserType(DjangoObjectType):
"""
The DjangoObjectType have a ID field to filter to avoid resolve method definition on Queries
This DjangoObjectType have a ID field, that allow filter by id and resolve method definition on Queries is not necesary
"""
class Meta:
model = User
description = "Type for User Model"
description = " Type definition for single User model object "
filter_fields = {
'id': ['exact', ],
'first_name': ['icontains', 'iexact'],
Expand All @@ -66,9 +66,9 @@ Here is a simple use of graphene-django-extras:
'email': ['icontains', 'iexact']
}
class UserListType(DjangoPaginatedObjectListType):
class UserListType(DjangoListObjectType):
class Meta:
description = "User list query definition"
description = " Type definition for List of users "
model = User
pagination = LimitOffsetGraphqlPagination()
Expand All @@ -81,7 +81,7 @@ Here is a simple use of graphene-django-extras:
class UserInput(DjangoInputObjectType):
class Meta:
description = " Input Type for User Model "
description = " User Input Type for used as input on Argumments classes on traditional Mutations "
model = User
Expand All @@ -91,7 +91,7 @@ Here is a simple use of graphene-django-extras:
import graphene
from .serializers import UserSerializer
from graphene_django_extras import DjangoSerializerMutation
from graphene_django_extras import DjangoSerializerMutation
from .types import UserType
from .input_types import UserInputType
Expand All @@ -103,7 +103,7 @@ Here is a simple use of graphene-django-extras:
class UserMutation(graphene.mutation):
"""
You must implement the mutate function
On traditional graphene mutation classes definition you must implement the mutate function
"""
user = graphene.Field(UserType, required=False)
Expand All @@ -112,7 +112,7 @@ Here is a simple use of graphene-django-extras:
new_user = graphene.Argument(UserInput)
class Meta:
description = "Normal mutation for Users"
description = " Traditional graphene mutation for Users "
@classmethod
def mutate(cls, info, **kwargs):
Expand All @@ -130,14 +130,16 @@ Here is a simple use of graphene-django-extras:
class Queries(graphene.ObjectType):
# Posible User list queries definitions
all_users = DjangoListObjectField(UserListType, description=_('All Usersquery'))
all_users = DjangoListObjectField(UserListType, description=_('All Users query'))
all_users1 = DjangoFilterPaginateListField(UserType, pagination=LimitOffsetGraphqlPagination())
all_users2 = DjangoFilterListField(UserType)
all_users3 = DjangoListObjectField(UserListType, filterset_class=UserFilter, description=_('All Users query'))
# Single user queries definitions
user = DjangoObjectField(UserType, description=_('Single User query'))
other_way_user = DjangoObjectField(UserListType.getOne(), description=_('Other way to query a single User query'))
# Defining the petition to a user
user = DjangoObjectField(UserType, description=_('Only one user'))
# Another way to define a single user query
other_way_user = DjangoObjectField(UserListType.getOne(), description=_('User List with pagination and filtering'))
class Mutations(graphene.ObjectType):
user_create = UserSerializerMutation.CreateField(deprecation_reason='Deprecation message')
Expand Down
11 changes: 5 additions & 6 deletions graphene_django_extras/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from graphene import get_version

from .fields import DjangoObjectField, DjangoListField, DjangoFilterListField, DjangoFilterPaginateListField, \
from .fields import DjangoObjectField, DjangoFilterListField, DjangoFilterPaginateListField, \
DjangoListObjectField
from .mutation import DjangoSerializerMutation
from .pagination import LimitOffsetGraphqlPagination, PageGraphqlPagination, CursorGraphqlPagination
from .types import DjangoObjectType, DjangoInputObjectType, DjangoPaginatedObjectListType
from .types import DjangoObjectType, DjangoInputObjectType, DjangoListObjectType

VERSION = (0, 0, 1, 'beta', 5)
VERSION = (0, 0, 1, 'beta', 6)

__version__ = get_version(VERSION)

Expand All @@ -16,7 +16,6 @@

# FIELDS
'DjangoObjectField',
'DjangoListField',
'DjangoFilterListField',
'DjangoFilterPaginateListField',
'DjangoListObjectField',
Expand All @@ -31,6 +30,6 @@

# TYPES
'DjangoObjectType',
'DjangoInputObjectType',
'DjangoPaginatedObjectListType',
'DjangoListObjectType',
'DjangoInputObjectType',
)
Loading

0 comments on commit c17b88a

Please sign in to comment.