Skip to content

Commit c121529

Browse files
committed
Various improvements on the django path
1 parent e717afe commit c121529

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/graphql_server/channels/handlers/http_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,17 @@ class GraphQLHTTPConsumer(
244244
To use this, place it in your ProtocolTypeRouter for your channels project:
245245
246246
```
247-
from graphql_server.channels import GraphQLHttpRouter
247+
from graphql_server.channels import GraphQLHTTPConsumer, GraphQLWSConsumer
248248
from channels.routing import ProtocolTypeRouter
249249
from django.core.asgi import get_asgi_application
250250
251251
application = ProtocolTypeRouter({
252252
"http": URLRouter([
253-
re_path("^graphql", GraphQLHTTPRouter(schema=schema)),
253+
re_path("^graphql", GraphQLHTTPConsumer.as_asgi(schema=schema)),
254254
re_path("^", get_asgi_application()),
255255
]),
256256
"websocket": URLRouter([
257-
re_path("^ws/graphql", GraphQLWebSocketRouter(schema=schema)),
257+
re_path("^ws/graphql", GraphQLWSConsumer.as_asgi(schema=schema)),
258258
]),
259259
})
260260
```

src/graphql_server/channels/router.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ def __init__(
4949
schema: GraphQLSchema,
5050
django_application: Optional[str] = None,
5151
url_pattern: str = "^graphql",
52+
http_consumer_class: type[GraphQLHTTPConsumer] = GraphQLHTTPConsumer,
53+
ws_consumer_class: type[GraphQLWSConsumer] = GraphQLWSConsumer,
54+
*args,
55+
**kwargs,
5256
) -> None:
53-
http_urls = [re_path(url_pattern, GraphQLHTTPConsumer.as_asgi(schema=schema))]
57+
http_urls = [
58+
re_path(
59+
url_pattern,
60+
http_consumer_class.as_asgi(*args, **kwargs),
61+
)
62+
]
5463
if django_application is not None:
5564
http_urls.append(re_path("^", django_application))
5665

@@ -59,7 +68,10 @@ def __init__(
5968
"http": URLRouter(http_urls),
6069
"websocket": URLRouter(
6170
[
62-
re_path(url_pattern, GraphQLWSConsumer.as_asgi(schema=schema)),
71+
re_path(
72+
url_pattern,
73+
ws_consumer_class.as_asgi(*args, **kwargs),
74+
),
6375
]
6476
),
6577
}

src/graphql_server/django/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .views import GraphQLView, AsyncGraphQLView
2+
3+
__all__ = ["GraphQLView", "AsyncGraphQLView"]

0 commit comments

Comments
 (0)