Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop micromanaging WS support in IDEs #3660

Merged
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
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: minor

This release removes the dated `subscriptions_enabled` setting from the Django and Channels integrations.
Instead, WebSocket support is now enabled by default in all GraphQL IDEs.
2 changes: 0 additions & 2 deletions docs/integrations/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,6 @@ GraphQLWebsocketCommunicator(
to disable it by passing `None`.
- `allow_queries_via_get`: optional, defaults to `True`, whether to enable
queries via `GET` requests
- `subscriptions_enabled`: optional boolean paramenter enabling subscriptions in
the GraphiQL interface, defaults to `True`
- `multipart_uploads_enabled`: optional, defaults to `False`, controls whether
to enable multipart uploads. Please make sure to consider the
[security implications mentioned in the GraphQL Multipart Request Specification](https://github.com/jaydenseric/graphql-multipart-request-spec/blob/master/readme.md#security)
Expand Down
4 changes: 0 additions & 4 deletions docs/integrations/django.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ The `GraphQLView` accepts the following arguments:
to disable it by passing `None`.
- `allow_queries_via_get`: optional, defaults to `True`, whether to enable
queries via `GET` requests
- `subscriptions_enabled`: optional boolean paramenter enabling subscriptions in
the GraphiQL interface, defaults to `False`.
- `multipart_uploads_enabled`: optional, defaults to `False`, controls whether
to enable multipart uploads. Please make sure to consider the
[security implications mentioned in the GraphQL Multipart Request Specification](https://github.com/jaydenseric/graphql-multipart-request-spec/blob/master/readme.md#security)
Expand Down Expand Up @@ -182,8 +180,6 @@ The `AsyncGraphQLView` accepts the following arguments:
to disable it by passing `None`.
- `allow_queries_via_get`: optional, defaults to `True`, whether to enable
queries via `GET` requests
- `subscriptions_enabled`: optional boolean paramenter enabling subscriptions in
the GraphiQL interface, defaults to `False`.

## Extending the view

Expand Down
1 change: 0 additions & 1 deletion strawberry/chalice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class GraphQLView(
):
allow_queries_via_get: bool = True
request_adapter_class = ChaliceHTTPRequestAdapter
_ide_subscription_enabled = False

def __init__(
self,
Expand Down
3 changes: 0 additions & 3 deletions strawberry/channels/handlers/http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,11 @@ def __init__(
graphiql: Optional[bool] = None,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
allow_queries_via_get: bool = True,
subscriptions_enabled: bool = True,
multipart_uploads_enabled: bool = False,
**kwargs: Any,
) -> None:
self.schema = schema
self.allow_queries_via_get = allow_queries_via_get
self.subscriptions_enabled = subscriptions_enabled
self._ide_subscriptions_enabled = subscriptions_enabled
self.multipart_uploads_enabled = multipart_uploads_enabled

if graphiql is not None:
Expand Down
31 changes: 8 additions & 23 deletions strawberry/django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
StreamingHttpResponse,
)
from django.http.response import HttpResponseBase
from django.template import RequestContext, Template
from django.template.exceptions import TemplateDoesNotExist
from django.template.loader import render_to_string
from django.template.response import TemplateResponse
from django.utils.decorators import classonlymethod
from django.views.generic import View

Expand All @@ -44,6 +42,8 @@
from .context import StrawberryDjangoContext

if TYPE_CHECKING:
from django.template.response import TemplateResponse

from strawberry.http import GraphQLHTTPResponse
from strawberry.http.ides import GraphQL_IDE

Expand Down Expand Up @@ -137,7 +137,6 @@ async def get_form_data(self) -> FormData:


class BaseView:
_ide_replace_variables = False
graphql_ide_html: str

def __init__(
Expand All @@ -146,13 +145,11 @@ def __init__(
graphiql: Optional[str] = None,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
allow_queries_via_get: bool = True,
subscriptions_enabled: bool = False,
multipart_uploads_enabled: bool = False,
**kwargs: Any,
) -> None:
self.schema = schema
self.allow_queries_via_get = allow_queries_via_get
self.subscriptions_enabled = subscriptions_enabled
self.multipart_uploads_enabled = multipart_uploads_enabled

if graphiql is not None:
Expand Down Expand Up @@ -215,7 +212,6 @@ class GraphQLView(
],
View,
):
subscriptions_enabled = False
graphiql: Optional[bool] = None
graphql_ide: Optional[GraphQL_IDE] = "graphiql"
allow_queries_via_get = True
Expand Down Expand Up @@ -244,16 +240,11 @@ def dispatch(

def render_graphql_ide(self, request: HttpRequest) -> HttpResponse:
try:
template = Template(render_to_string("graphql/graphiql.html"))
content = render_to_string("graphql/graphiql.html")
except TemplateDoesNotExist:
template = Template(self.graphql_ide_html)

context = {"SUBSCRIPTION_ENABLED": json.dumps(self.subscriptions_enabled)}
content = self.graphql_ide_html

response = TemplateResponse(request=request, template=None, context=context)
response.content = template.render(RequestContext(request, context))

return response
return HttpResponse(content)


class AsyncGraphQLView(
Expand All @@ -269,7 +260,6 @@ class AsyncGraphQLView(
],
View,
):
subscriptions_enabled = False
graphiql: Optional[bool] = None
graphql_ide: Optional[GraphQL_IDE] = "graphiql"
allow_queries_via_get = True
Expand Down Expand Up @@ -308,16 +298,11 @@ async def dispatch( # pyright: ignore

async def render_graphql_ide(self, request: HttpRequest) -> HttpResponse:
try:
template = Template(render_to_string("graphql/graphiql.html"))
content = render_to_string("graphql/graphiql.html")
except TemplateDoesNotExist:
template = Template(self.graphql_ide_html)
content = self.graphql_ide_html

context = {"SUBSCRIPTION_ENABLED": json.dumps(self.subscriptions_enabled)}

response = TemplateResponse(request=request, template=None, context=context)
response.content = template.render(RequestContext(request, context))

return response
return HttpResponse(content=content)

def is_websocket_request(self, request: HttpRequest) -> TypeGuard[HttpRequest]:
return False
Expand Down
1 change: 0 additions & 1 deletion strawberry/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def content_type(self) -> Optional[str]:


class BaseGraphQLView:
_ide_subscription_enabled = False
graphql_ide: Optional[GraphQL_IDE]

def __init__(
Expand Down
10 changes: 1 addition & 9 deletions strawberry/http/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class BaseView(Generic[Request]):
graphql_ide: Optional[GraphQL_IDE]
multipart_uploads_enabled: bool = False

# TODO: we might remove this in future :)
_ide_replace_variables: bool = True
_ide_subscription_enabled: bool = True

def should_render_graphql_ide(self, request: BaseRequestProtocol) -> bool:
return (
request.method == "GET"
Expand Down Expand Up @@ -64,11 +60,7 @@ def parse_query_params(self, params: QueryParams) -> Dict[str, Any]:

@property
def graphql_ide_html(self) -> str:
return get_graphql_ide_html(
subscription_enabled=self._ide_subscription_enabled,
replace_variables=self._ide_replace_variables,
graphql_ide=self.graphql_ide,
)
return get_graphql_ide_html(graphql_ide=self.graphql_ide)

def _is_multipart_subscriptions(
self, content_type: str, params: Dict[str, str]
Expand Down
8 changes: 0 additions & 8 deletions strawberry/http/ides.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import pathlib
from typing import Optional
from typing_extensions import Literal
Expand All @@ -7,8 +6,6 @@


def get_graphql_ide_html(
subscription_enabled: bool = True,
replace_variables: bool = True,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
) -> str:
here = pathlib.Path(__file__).parents[1]
Expand All @@ -22,11 +19,6 @@ def get_graphql_ide_html(

template = path.read_text(encoding="utf-8")

if replace_variables:
template = template.replace(
"{{ SUBSCRIPTION_ENABLED }}", json.dumps(subscription_enabled)
)

return template


Expand Down
2 changes: 0 additions & 2 deletions strawberry/quart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class GraphQLView(
],
View,
):
_ide_subscription_enabled = False

methods = ["GET", "POST"]
allow_queries_via_get: bool = True
request_adapter_class = QuartHTTPRequestAdapter
Expand Down
5 changes: 1 addition & 4 deletions strawberry/static/graphiql.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@
headers["x-csrftoken"] = csrfToken;
}

const subscriptionsEnabled = JSON.parse("{{ SUBSCRIPTION_ENABLED }}");
const subscriptionUrl = subscriptionsEnabled
? httpUrlToWebSockeUrl(fetchURL)
: null;
const subscriptionUrl = httpUrlToWebSockeUrl(fetchURL);

const fetcher = GraphiQL.createFetcher({
url: fetchURL,
Expand Down
Loading