@@ -28,14 +28,14 @@ pip install graphene-django-extras
28
28
1. DjangoSerializerMutation
29
29
30
30
** Types:**
31
- 1 . DjangoObjectTypeExtra
32
- 2. DjangoInputObjectType
33
- 3. DjangoPaginatedObjectListType
31
+ 1 . DjangoObjectType
32
+ 2. DjangoListObjectType
33
+ 3. DjangoInputObjectType
34
34
35
35
** Pagination:**
36
36
1. LimitOffsetGraphqlPagination
37
37
2. PageGraphqlPagination
38
- 3. CursosGraphqlPagination * (cooming soon)*
38
+ 3. CursorGraphqlPagination * (cooming soon)*
39
39
40
40
41
41
### Examples
@@ -46,16 +46,16 @@ Here is a use of graphene-django-extras:
46
46
47
47
``` python
48
48
from django.contrib.auth.models import User
49
- from graphene_django_extras import DjangoObjectType, DjangoPaginatedObjectListType
49
+ from graphene_django_extras import DjangoObjectType, DjangoListObjectType
50
50
from graphene_django_extras.pagination import LimitOffsetGraphqlPagination
51
51
52
52
class UserType (DjangoObjectType ):
53
53
"""
54
- This DjangoObjectType have a ID field to filter to avoid resolve method definition on Queries
54
+ This DjangoObjectType have a ID field, that allow filter by id and resolve method definition on Queries is not necesary
55
55
"""
56
56
class Meta :
57
57
model = User
58
- description = " Type for User Model "
58
+ description = " Type definition for single User model object "
59
59
filter_fields = {
60
60
' id' : [' exact' , ],
61
61
' first_name' : [' icontains' , ' iexact' ],
@@ -65,9 +65,9 @@ class UserType(DjangoObjectType):
65
65
}
66
66
67
67
68
- class UserListType (DjangoPaginatedObjectListType ):
68
+ class UserListType (DjangoListObjectType ):
69
69
class Meta :
70
- description = " User list query definition"
70
+ description = " Type definition for List of users "
71
71
model = User
72
72
pagination = LimitOffsetGraphqlPagination(page_size = 20 )
73
73
```
@@ -79,15 +79,15 @@ from graphene_django_extras import DjangoInputObjectType
79
79
80
80
class UserInput (DjangoInputObjectType ):
81
81
class Meta :
82
- description = " Input Type for User Model "
82
+ description = " User Input Type for used as input on Argumments classes on traditional Mutations "
83
83
model = User
84
84
```
85
85
86
86
#### 3- You can define traditional mutations that use Input Types or Mutations based on DRF SerializerClass:
87
87
88
88
``` python
89
89
import graphene
90
- from graphene_django_extras import DjangoSerializerMutation
90
+ from graphene_django_extras import DjangoSerializerMutation
91
91
92
92
from .serializers import UserSerializer
93
93
from .types import UserType
@@ -104,7 +104,7 @@ class UserSerializerMutation(DjangoSerializerMutation):
104
104
105
105
class UserMutation (graphene .mutation ):
106
106
"""
107
- You must implement the mutate function
107
+ On traditional graphene mutation classes definition you must implement the mutate function
108
108
"""
109
109
110
110
user = graphene.Field(UserType, required = False )
@@ -113,7 +113,7 @@ class UserMutation(graphene.mutation):
113
113
new_user = graphene.Argument(UserInput)
114
114
115
115
class Meta :
116
- description = " Normal mutation for Users"
116
+ description = " Traditional graphene mutation for Users "
117
117
118
118
@ classmethod
119
119
def mutate (cls , info , ** kwargs ):
@@ -130,14 +130,16 @@ from .mutations import UserMutation, UserSerializerMutation
130
130
131
131
class Queries (graphene .ObjectType ):
132
132
# Posible User list queries definitions
133
- all_users = DjangoListObjectField(UserListType, description = _(' All Usersquery ' ))
133
+ all_users = DjangoListObjectField(UserListType, description = _(' All Users query ' ))
134
134
all_users1 = DjangoFilterPaginateListField(UserType, pagination = LimitOffsetGraphqlPagination())
135
135
all_users2 = DjangoFilterListField(UserType)
136
136
all_users3 = DjangoListObjectField(UserListType, filterset_class = UserFilter, description = _(' All Users query' ))
137
137
138
- # Single user queries definitions
139
- user = DjangoObjectField(UserType, description = _(' Single User query' ))
140
- other_way_user = DjangoObjectField(UserListType.getOne(), description = _(' Other way to query a single User query' ))
138
+ # Defining the petition to a user
139
+ user = DjangoObjectField(UserType, description = _(' Single User query' ))
140
+
141
+ # Another way to define a single user query
142
+ other_way_user = DjangoObjectField(UserListType.getOne(), description = _(' User List with pagination and filtering' ))
141
143
142
144
class Mutations (graphene .ObjectType ):
143
145
user_create = UserSerializerMutation.CreateField(deprecation_reason = ' Deprecation message' )
@@ -159,21 +161,21 @@ class Mutations(graphene.ObjectType):
159
161
}
160
162
totalCount
161
163
}
162
-
164
+
163
165
allUsers1 (lastName_Iexact : " Doe" , limit : 5 , offset : 0 ){
164
166
id
165
167
username
166
168
firstName
167
- lastName
169
+ lastName
168
170
}
169
-
171
+
170
172
allUsers2 (firstName_Icontains : " J" ){
171
173
id
172
174
username
173
175
firstName
174
176
lastName
175
177
}
176
-
178
+
177
179
user (id : 2 ){
178
180
id
179
181
username
@@ -186,7 +188,7 @@ class Mutations(graphene.ObjectType):
186
188
187
189
``` js
188
190
mutation{
189
- userCreate (newUser : {password : " test*123 " , email : " test@test.com " , username : " test " }){
191
+ userCreate (newUser : {username : " test" , password : " test*123 " }){
190
192
user{
191
193
id
192
194
username
@@ -199,15 +201,15 @@ mutation{
199
201
messages
200
202
}
201
203
}
202
-
204
+
203
205
userDelete (id : 1 ){
204
206
ok
205
207
errors{
206
208
field
207
209
messages
208
210
}
209
211
}
210
-
212
+
211
213
userUpdate (newUser : {id: 1 , username: " John" }){
212
214
user{
213
215
id
0 commit comments