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

Deprecate Chalice's render_graphiql parameter by adding a warning #1587

Closed
wants to merge 11 commits into from
Closed
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
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release type: patch

With this release in Chalice's `GraphQLView` the parameter `render_graphiql` is now
deprecated and has been replaced with `graphiql`. It will be removed in releases of
Strawberry made after 2022-07-13.
2 changes: 1 addition & 1 deletion docs/integrations/chalice.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Mutation:


schema = strawberry.Schema(query=Query, mutation=Mutation)
view = GraphQLView(schema=schema, render_graphiql=True)
view = GraphQLView(schema=schema, graphiql=True)


@app.route("/graphql", methods=["GET", "POST"], content_types=["application/json"])
Expand Down
19 changes: 17 additions & 2 deletions strawberry/chalice/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import warnings
from http import HTTPStatus
from typing import Optional

from chalice.app import BadRequestError, CaseInsensitiveMapping, Request, Response
from strawberry.chalice.graphiql import render_graphiql_page
Expand All @@ -8,9 +10,22 @@


class GraphQLView:
def __init__(self, schema: BaseSchema, render_graphiql: bool = True):
def __init__(
self,
schema: BaseSchema,
graphiql: bool = True,
render_graphiql: Optional[bool] = None,
):
self._schema = schema
self.graphiql = render_graphiql
self.graphiql = graphiql

if render_graphiql is not None:
warnings.warn(
"`render_graphiql` is deprecated and it will stop working in releases "
"of strawberry made after 2022-07-13. Use `graphiql` instead",
DeprecationWarning,
)
self.graphiql = render_graphiql

@staticmethod
def render_graphiql() -> str:
Expand Down
14 changes: 13 additions & 1 deletion tests/chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def echo(self, string_to_echo: str) -> str:


schema = strawberry.Schema(query=Query, mutation=Mutation)
view = GraphQLView(schema=schema, render_graphiql=True)
view = GraphQLView(schema=schema, graphiql=True)


@app.route("/")
Expand All @@ -35,3 +35,15 @@ def handle_graphql():
request: Request = app.current_request
result = view.execute_request(request)
return result


deprecated_graphiql_view = GraphQLView(schema=schema, render_graphiql=True)


@app.route(
"/deprecated-graphql", methods=["GET", "POST"], content_types=["application/json"]
)
def handle_deprecated_graphql():
request: Request = app.current_request
result = deprecated_graphiql_view.execute_request(request)
return result
21 changes: 20 additions & 1 deletion tests/chalice/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import pytest

from chalice.test import Client, HTTPResponse
from strawberry.chalice.views import GraphQLView

from .app import app
from .app import app, schema


def test_chalice_server_index_route_returns():
Expand Down Expand Up @@ -94,3 +95,21 @@ def test_graphiql_query_with_no_request_body():
response = client.http.post("/graphql", headers=headers, body="")
assert response.status_code == HTTPStatus.OK
assert response_is_of_error_type(response)


def test_deprecated_render_graphiql():
with Client(app) as client:
headers = {"Accept": "application/json"}
response = client.http.get("/deprecated-graphql", headers=headers)
assert response.status_code == HTTPStatus.OK
assert response_is_of_error_type(response)
estyxx marked this conversation as resolved.
Show resolved Hide resolved


def test_using_deprecated_render_graphiql_raise_warning():
with pytest.deprecated_call() as record:
GraphQLView(schema=schema, render_graphiql=True)

assert record[0].message.args == [
"`render_graphiql` is deprecated and it will stop working in releases "
"of strawberry made after 2022-07-13. Use `graphiql` instead",
]