Skip to content

Commit 6e68e52

Browse files
author
Ernesto Perez Amigo
committed
Added support to Django's field: GenericRel.
Improve model's fields calculation for to add all possible related and reverse fields. Improved documentation translation.
1 parent 58e1f99 commit 6e68e52

File tree

8 files changed

+154
-139
lines changed

8 files changed

+154
-139
lines changed

README.md

+52-43
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66

77
This package add some extra functionalities to graphene-django to facilitate the graphql use without Relay:
8-
1. Allow pagination and filtering on Queries.
9-
2. Allow to define DjangoRestFramework serializers based Mutations.
10-
3. Add support to Subscription's requests and its integration with websockets using Channels package. :muscle:
8+
1. Allows pagination and filtering on Queries.
9+
2. Allows to define DjangoRestFramework serializers based Mutations.
10+
3. Adds support to Subscription's requests and its integration with websockets using Channels package. :muscle:
1111

1212
## Installation
1313

@@ -45,8 +45,8 @@ pip install graphene-django-extras
4545

4646
### Queries and Mutations examples:
4747

48-
This is a basic example of graphene-django-extras package use. You can configure some pagination
49-
default values on settings.py like this:
48+
This is a basic example of graphene-django-extras package use. You can configure global params
49+
for DjangoListObjectType classes pagination definitions on settings.py like this:
5050

5151
```python
5252
GRAPHENE_DJANGO_EXTRAS = {
@@ -85,19 +85,19 @@ class UserListType(DjangoListObjectType):
8585
pagination = LimitOffsetGraphqlPagination(page_size=20)
8686
```
8787

88-
#### 2- Input Types can be defined for use on mutations:
88+
#### 2- You can to define InputTypes for use on mutations:
8989

9090
```python
9191
from graphene_django_extras import DjangoInputObjectType
9292

9393

9494
class UserInput(DjangoInputObjectType):
9595
class Meta:
96-
description = " User InputType to use as input on Arguments classes on traditional Mutations "
96+
description = " User InputType definition to use as input on an Arguments class on traditional Mutations "
9797
model = User
9898
```
9999

100-
#### 3- You can define traditional mutations that use InputTypes or Mutations based on DRF SerializerClass:
100+
#### 3- You can define traditional mutations that use InputTypes or Mutations based on DRF serializers:
101101

102102
```python
103103
import graphene
@@ -113,7 +113,7 @@ class UserSerializerMutation(DjangoSerializerMutation):
113113
DjangoSerializerMutation auto implement Create, Delete and Update functions
114114
"""
115115
class Meta:
116-
description = " Serializer based Mutation for Users "
116+
description = " DRF serializer based Mutation for Users "
117117
serializer_class = UserSerializer
118118

119119

@@ -128,7 +128,7 @@ class UserMutation(graphene.Mutation):
128128
new_user = graphene.Argument(UserInput)
129129

130130
class Meta:
131-
description = " Traditional graphene mutation for Users "
131+
description = " Graphene traditional mutation for Users "
132132

133133
@classmethod
134134
def mutate(cls, root, info, *args, **kwargs):
@@ -153,22 +153,22 @@ class Queries(graphene.ObjectType):
153153
all_users3 = DjangoListObjectField(UserListType, filterset_class=UserFilter, description=_('All Users query'))
154154

155155
# Defining a query for a single user
156-
# The DjangoObjectField have a ID input field, that allow filter by id and is't necessary resolve method
156+
# The DjangoObjectField have a ID type input field, that allow filter by id and is't necessary to define resolve function
157157
user = DjangoObjectField(UserType, description=_('Single User query'))
158158

159-
# Another way to define a single user query
160-
user1 = DjangoObjectField(UserListType.getOne(), description=_('User List with pagination and filtering'))
159+
# Another way to define a query to single user
160+
user1 = DjangoObjectField(UserListType.getOne(), description=_('User list with pagination and filtering'))
161161

162162

163163
class Mutations(graphene.ObjectType):
164-
user_create = UserSerializerMutation.CreateField(deprecation_reason='Some deprecation message')
164+
user_create = UserSerializerMutation.CreateField(deprecation_reason='Some one deprecation message')
165165
user_delete = UserSerializerMutation.DeleteField()
166166
user_update = UserSerializerMutation.UpdateField()
167167

168168
traditional_user_mutation = UserMutation.Field()
169169
```
170170

171-
#### 5- Examples of queries:
171+
#### 5- Queries's examples:
172172
```js
173173
{
174174
allUsers(username_Icontains:"john"){
@@ -209,7 +209,7 @@ class Mutations(graphene.ObjectType):
209209
}
210210
```
211211

212-
#### 6- Examples of Mutations:
212+
#### 6- Mutations's examples:
213213

214214
```js
215215
mutation{
@@ -251,7 +251,7 @@ mutation{
251251

252252
### **Subscriptions:**
253253

254-
This first approach to support Graphql subscriptions with Channels in **graphene-django-extras**, use **channels-api** package.
254+
This first approach to add Graphql subscriptions support with Channels in **graphene-django-extras**, use **channels-api** package.
255255

256256
#### 1- Defining custom Subscriptions classes:
257257

@@ -268,18 +268,18 @@ class UserSubscription(Subscription):
268268
class Meta:
269269
mutation_class = UserMutation
270270
stream = 'users'
271-
description = 'Subscription for users'
271+
description = 'User Subscription'
272272

273273

274274
class GroupSubscription(Subscription):
275275
class Meta:
276276
mutation_class = GroupMutation
277277
stream = 'groups'
278-
description = 'Subscriptions for groups'
278+
description = 'Group Subscription'
279279

280280
```
281281

282-
Add ours subscriptions definitions into our app schema:
282+
Add the subscriptions definitions into your app's schema:
283283

284284
```python
285285
# app/graphql/schema.py
@@ -292,7 +292,7 @@ class Subscriptions(graphene.ObjectType):
292292
GroupSubscription = PersonSubscription.Field()
293293
```
294294

295-
Add your app schema into your project root schema:
295+
Add the app's schema into your project root schema:
296296

297297
```python
298298
# schema.py
@@ -302,17 +302,17 @@ import custom.app.route.graphql.schema
302302

303303
class RootQuery(custom.app.route.graphql.schema.Query, graphene.ObjectType):
304304
class Meta:
305-
description = 'Root Queries for my Project'
305+
description = 'The project root query definition'
306306

307307

308308
class RootSubscription(custom.app.route.graphql.schema.Mutation, graphene.ObjectType):
309309
class Meta:
310-
description = 'Root Mutations for my Project'
310+
description = 'The project root mutation definition'
311311

312312

313313
class RootSubscription(custom.app.route.graphql.schema.Subscriptions, graphene.ObjectType):
314314
class Meta:
315-
description = 'Root Subscriptions for my Project'
315+
description = 'The project root subscription definition'
316316

317317

318318
schema = graphene.Schema(
@@ -324,7 +324,7 @@ schema = graphene.Schema(
324324

325325
#### 2- Defining Channels settings and custom routing config ( *For more information see Channels documentation* ):
326326

327-
Defining our app routing, like custom apps urls:
327+
We define app routing, as if they were app urls:
328328

329329
```python
330330
# app/routing.py
@@ -345,7 +345,7 @@ app_routing = [
345345
]
346346
```
347347

348-
Defining our project routing, like custom root project urls:
348+
We define project routing, as if they were project urls:
349349

350350
```python
351351
# project/routing.py
@@ -358,7 +358,7 @@ project_routing = [
358358

359359
```
360360

361-
You should add **channels** and **channels_api** modules into your INSTALLED_APPS setting and you must defining your routing project definition into the CHANNEL_LAYERS setting:
361+
You should put into your INSTALLED_APPS the **channels** and **channels_api** modules and you must to add your project's routing definition into the CHANNEL_LAYERS setting:
362362

363363
```python
364364
# settings.py
@@ -384,17 +384,18 @@ CHANNEL_LAYERS = {
384384
...
385385
```
386386

387-
#### 3- Examples of Subscriptions:
387+
#### 3- Subscription's examples:
388388

389-
In your client you must define websocket connection to: *'ws://host:port/custom_websocket_path'*.
390-
When the connection is established, the server return a websocket message like this:
389+
In your WEB client you must define websocket connection to: *'ws://host:port/custom_websocket_path'*.
390+
When the connection is established, the server return a websocket's message like this:
391391
*{"channel_id": "GthKdsYVrK!WxRCdJQMPi", "connect": "success"}*, where you must store the **channel_id** value to later use in your graphql subscriptions request for subscribe or unsubscribe operations.
392-
The Subscription accept five possible parameters:
392+
393+
The graphql's subscription request accept five possible parameters:
393394
1. **operation**: Operation to perform: subscribe or unsubscribe. (*required*)
394-
2. **action**: Action you wish to subscribe: create, update, delete or all_actions. (*required*)
395-
3. **channelId**: Websocket connection identification. (*required*)
396-
4. **id**: ID field value of model object that you wish to subscribe to. (*optional*)
397-
5. **data**: List of desired model fields that you want in subscription's notification. (*optional*)
395+
2. **action**: Action to which you wish to subscribe: create, update, delete or all_actions. (*required*)
396+
3. **channelId**: Identification of the connection by websocket. (*required*)
397+
4. **id**: Object's ID field value that you wish to subscribe to. (*optional*)
398+
5. **data**: Model's fields that you want to appear in the subscription notifications. (*optional*)
398399

399400
```js
400401
subscription{
@@ -412,7 +413,9 @@ subscription{
412413
}
413414
```
414415

415-
In this case, the subscription request sanded return a websocket message to client like this: *{"action": "update", "operation": "subscribe", "ok": true, "stream": "users", "error": null}* and each time than the user with id=5 get modified, you will receive a message through websocket's connection with the following format:
416+
In this case, the subscription request sent return a websocket message to client like this:
417+
*{"action": "update", "operation": "subscribe", "ok": true, "stream": "users", "error": null}*
418+
and from that moment each time than the user with id=5 get modified, you will receive a message through websocket's connection with the following format:
416419

417420
```js
418421
{
@@ -432,7 +435,7 @@ In this case, the subscription request sanded return a websocket message to clie
432435
}
433436
```
434437

435-
For unsubscribe you must send a graphql subscription request like this:
438+
For unsubscribe you must send a graphql request like this:
436439

437440
```js
438441
subscription{
@@ -449,14 +452,17 @@ subscription{
449452
}
450453
```
451454

452-
**NOTE:** Each time than the Graphql server restart, you must to reestablish the websocket's connection and resend the subscription graphql request with a new websocket connection id.
455+
**NOTE:** Each time than the graphql's server restart, you must to reestablish the websocket connection and resend the graphql's subscription request with the new websocket connection id.
453456

454457

455458
## Change Log:
456459

457460
#### v0.1.0-alpha12:
458-
1. Added MAX_PAGE_SIZE configuration field to global dict GRAPHENE_DJANGO_EXTRAS
459-
configuration for better customize paginations.
461+
1. Added new settings param: MAX_PAGE_SIZE, to use on GRAPHENE_DJANGO_EXTRAS
462+
configuration dict for better customize DjangoListObjectType's pagination.
463+
2. Added support to Django's field: GenericRel.
464+
3. Improve model's fields calculation for to add all possible related and reverse fields.
465+
4. Improved documentation translation.
460466

461467
#### v0.1.0-alpha11:
462468
1. Improved ordering for showed fields on graphqli's IDE.
@@ -482,7 +488,8 @@ subscription{
482488
1. Add queryset options to DjangoListObjectType Meta class for specify wanted model queryset.
483489
2. Add AuthenticatedGraphQLView on graphene_django_extras.views for use
484490
'permission', 'authorization' and 'throttle' classes based on the DRF settings. Special thanks to
485-
[@jacobh](https://github.com/jacobh) for this [comment](https://github.com/graphql-python/graphene/issues/249#issuecomment-300068390)
491+
[@jacobh](https://github.com/jacobh) for this
492+
[comment](https://github.com/graphql-python/graphene/issues/249#issuecomment-300068390)
486493

487494
#### v0.1.0-alpha3:
488495
1. Fixed bug on subscriptions when not specified any field in "data" parameter to bean return on notification
@@ -512,8 +519,10 @@ subscription{
512519

513520
#### v0.0.1:
514521
1. Fixed bug on DjangoInputObjectType class that refer to unused interface attribute.
515-
2. Added support to create nested objects like in [DRF](http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations),
516-
it's valid to SerializerMutation and DjangoInputObjectType, only is necessary to specify nested_fields=True on its Meta class definition.
522+
2. Added support to create nested objects like in
523+
[DRF](http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations),
524+
it's valid to SerializerMutation and DjangoInputObjectType, only is necessary to specify nested_fields=True
525+
on its Meta class definition.
517526
3. Added support to show, only in mutations types to create objects and with debug=True on settings,
518527
inputs autocomplete ordered by required fields first.
519528
4. Fixed others minors bugs.

0 commit comments

Comments
 (0)