From cba56bb5a544aeb6a2e06df47efff72a1b3444af Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 11 Sep 2020 18:13:10 +0100 Subject: [PATCH 1/2] make context|variables deprecation warning ignore as specific as possible --- setup.cfg | 2 -- tests/test_graphql.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index e90f5e9c2..80eb78ed7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,5 +31,3 @@ filterwarnings= ignore: "@coroutine" decorator is deprecated.*:DeprecationWarning # https://github.com/graphql-python/graphene/issues/1055 ignore: Using or importing the ABCs from 'collections' instead of from 'collections\.abc' is deprecated.*:DeprecationWarning - ignore: The 'context' alias has been deprecated. Please use 'context_value' instead\.:DeprecationWarning - ignore: The 'variables' alias has been deprecated. Please use 'variable_values' instead\.:DeprecationWarning diff --git a/tests/test_graphql.py b/tests/test_graphql.py index 67f307231..7596c0b75 100644 --- a/tests/test_graphql.py +++ b/tests/test_graphql.py @@ -38,24 +38,35 @@ def resolve_whoami(self, info): client = TestClient(app) +filterwarnings = pytest.mark.filterwarnings( + r"ignore:" + r"The '(context|variables)' alias has been deprecated. Please use " + r"'(context_value|variable_values)' instead\.:DeprecationWarning" +) + + +@filterwarnings def test_graphql_get(): response = client.get("/?query={ hello }") assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} +@filterwarnings def test_graphql_post(): response = client.post("/?query={ hello }") assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} +@filterwarnings def test_graphql_post_json(): response = client.post("/", json={"query": "{ hello }"}) assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} +@filterwarnings def test_graphql_post_graphql(): response = client.post( "/", data="{ hello }", headers={"content-type": "application/graphql"} @@ -110,6 +121,7 @@ def test_graphiql_not_found(): assert response.text == "Not Found" +@filterwarnings def test_add_graphql_route(): app = Starlette() app.add_route("/", GraphQLApp(schema=schema)) @@ -119,6 +131,7 @@ def test_add_graphql_route(): assert response.json() == {"data": {"hello": "Hello stranger"}} +@filterwarnings def test_graphql_context(): app = Starlette() app.add_middleware(FakeAuthMiddleware) @@ -142,6 +155,7 @@ async def resolve_hello(self, info, name): async_app = GraphQLApp(schema=async_schema, executor_class=AsyncioExecutor) +@filterwarnings def test_graphql_async(): client = TestClient(async_app) response = client.get("/?query={ hello }") @@ -160,6 +174,7 @@ def old_style_async_app(event_loop) -> GraphQLApp: return old_style_async_app +@filterwarnings def test_graphql_async_old_style_executor(old_style_async_app: GraphQLApp): # See https://github.com/encode/starlette/issues/242 client = TestClient(old_style_async_app) From 40631fafa216e7e0ff68a848118cc18d539a5de1 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 11 Sep 2020 18:14:33 +0100 Subject: [PATCH 2/2] fix context|variables deprecation warning --- starlette/graphql.py | 8 ++++---- tests/test_graphql.py | 15 --------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/starlette/graphql.py b/starlette/graphql.py index e67be3f1b..90aa993d2 100644 --- a/starlette/graphql.py +++ b/starlette/graphql.py @@ -123,19 +123,19 @@ async def execute( # type: ignore if self.is_async: return await self.schema.execute( query, - variables=variables, + variable_values=variables, operation_name=operation_name, executor=self.executor, return_promise=True, - context=context, + context_value=context, ) else: return await run_in_threadpool( self.schema.execute, query, - variables=variables, + variable_values=variables, operation_name=operation_name, - context=context, + context_value=context, ) async def handle_graphiql(self, request: Request) -> Response: diff --git a/tests/test_graphql.py b/tests/test_graphql.py index 7596c0b75..67f307231 100644 --- a/tests/test_graphql.py +++ b/tests/test_graphql.py @@ -38,35 +38,24 @@ def resolve_whoami(self, info): client = TestClient(app) -filterwarnings = pytest.mark.filterwarnings( - r"ignore:" - r"The '(context|variables)' alias has been deprecated. Please use " - r"'(context_value|variable_values)' instead\.:DeprecationWarning" -) - - -@filterwarnings def test_graphql_get(): response = client.get("/?query={ hello }") assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} -@filterwarnings def test_graphql_post(): response = client.post("/?query={ hello }") assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} -@filterwarnings def test_graphql_post_json(): response = client.post("/", json={"query": "{ hello }"}) assert response.status_code == 200 assert response.json() == {"data": {"hello": "Hello stranger"}} -@filterwarnings def test_graphql_post_graphql(): response = client.post( "/", data="{ hello }", headers={"content-type": "application/graphql"} @@ -121,7 +110,6 @@ def test_graphiql_not_found(): assert response.text == "Not Found" -@filterwarnings def test_add_graphql_route(): app = Starlette() app.add_route("/", GraphQLApp(schema=schema)) @@ -131,7 +119,6 @@ def test_add_graphql_route(): assert response.json() == {"data": {"hello": "Hello stranger"}} -@filterwarnings def test_graphql_context(): app = Starlette() app.add_middleware(FakeAuthMiddleware) @@ -155,7 +142,6 @@ async def resolve_hello(self, info, name): async_app = GraphQLApp(schema=async_schema, executor_class=AsyncioExecutor) -@filterwarnings def test_graphql_async(): client = TestClient(async_app) response = client.get("/?query={ hello }") @@ -174,7 +160,6 @@ def old_style_async_app(event_loop) -> GraphQLApp: return old_style_async_app -@filterwarnings def test_graphql_async_old_style_executor(old_style_async_app: GraphQLApp): # See https://github.com/encode/starlette/issues/242 client = TestClient(old_style_async_app)