Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,24 @@ A plug-and-play GraphQL subscription implementation for Graphene + Django built
]),
})
```

5. Add `GraphQLSubscriptionView` to your `urls.py` file.

5. Connect signals for any models you want to create subscriptions for
```python
# your_project/urls.py
from django.urls import path
from graphene_subscriptions.views import GraphQLSubscriptionView

urlpatterns = [
# your urls...
path('graphql/', GraphQLSubscriptionView.as_view()),
]

```
GraphQL Playgrounds IDE is enabled by default.<br />
If you want to disable it you can use `GraphQLSubscriptionView.as_view(playground=False)` (`playground=True` by default)

6. Connect signals for any models you want to create subscriptions for

```python
# your_app/signals.py
Expand Down
22 changes: 12 additions & 10 deletions graphene_subscriptions/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ def signal_fired(self, message):

def _send_result(self, id, result):
errors = result.errors
response = {
"id": id,
"type": "data",
"payload": {
"data": result.data
}
}

if errors is not None:
response["payload"]["errors"] = list(map(str, errors))

self.send(
{
"type": "websocket.send",
"text": json.dumps(
{
"id": id,
"type": "data",
"payload": {
"data": result.data,
"errors": list(map(str, errors)) if errors else None,
},
}
),
"text": json.dumps(response),
}
)

Loading