Skip to content

Commit 184ba72

Browse files
kiendanggcampaxChoongkyu
authored
chore: update dependencies (#99)
* Update dependencies * Relax flask dependency to allow flask 2 * Fixes for quart >=0.15 Fix quart.request.get_data signature QuartClient -> TestClientProtocol * Lint * Fix aiohttp tests * Update sanic to v22.6 * Make sanic v22.9 work * Fix deprecation warnings DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content. * Update graphiql to 1.4.7 for security reason "All versions of graphiql < 1.4.7 are vulnerable to an XSS attack." https://github.com/graphql/graphiql/blob/ab2b52f06213bd9bf90c905c1b460b6939f3d856/docs/security/2021-introspection-schema-xss.md * Fix webob graphiql check Was working by accident before * Fix quart PytestCollectionWarning cannot collect test class 'TestClientProtocol' because it has a __init__ constructor * Make Jinja2 optional * Add python 3.11 and remove 3.6 * Tweak quart for python 3.7 to 3.11 * Fix test for python 3.11 Co-authored-by: Giovanni Campagna <[email protected]> Co-authored-by: Choongkyu Kim <[email protected]>
1 parent 8dec731 commit 184ba72

20 files changed

+271
-258
lines changed

.github/workflows/deploy.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Set up Python 3.9
15-
uses: actions/setup-python@v2
13+
- uses: actions/checkout@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
1616
with:
17-
python-version: 3.9
17+
python-version: "3.10"
1818
- name: Build wheel and source tarball
1919
run: |
2020
pip install wheel

.github/workflows/lint.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
11-
- name: Set up Python 3.9
12-
uses: actions/setup-python@v2
10+
- uses: actions/checkout@v3
11+
- name: Set up Python
12+
uses: actions/setup-python@v4
1313
with:
14-
python-version: 3.9
14+
python-version: "3.10"
1515
- name: Install dependencies
1616
run: |
1717
python -m pip install --upgrade pip

.github/workflows/tests.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ jobs:
88
strategy:
99
max-parallel: 4
1010
matrix:
11-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
11+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1212
os: [ubuntu-latest, windows-latest]
1313
exclude:
14-
- os: windows-latest
15-
python-version: "3.6"
1614
- os: windows-latest
1715
python-version: "3.7"
1816
- os: windows-latest
1917
python-version: "3.8"
2018
- os: windows-latest
21-
python-version: "3.10"
19+
python-version: "3.9"
20+
- os: windows-latest
21+
python-version: "3.11"
2222

2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
26+
uses: actions/setup-python@v4
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929
- name: Install dependencies
@@ -39,11 +39,11 @@ jobs:
3939
runs-on: ubuntu-latest
4040

4141
steps:
42-
- uses: actions/checkout@v2
43-
- name: Set up Python 3.9
44-
uses: actions/setup-python@v2
42+
- uses: actions/checkout@v3
43+
- name: Set up Python
44+
uses: actions/setup-python@v4
4545
with:
46-
python-version: 3.9
46+
python-version: "3.10"
4747
- name: Install test dependencies
4848
run: |
4949
python -m pip install --upgrade pip

graphql_server/__init__.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@
99
import json
1010
from collections import namedtuple
1111
from collections.abc import MutableMapping
12-
from typing import (
13-
Any,
14-
Callable,
15-
Collection,
16-
Dict,
17-
List,
18-
Optional,
19-
Type,
20-
Union,
21-
cast,
22-
)
12+
from typing import Any, Callable, Collection, Dict, List, Optional, Type, Union, cast
2313

2414
from graphql.error import GraphQLError
2515
from graphql.execution import ExecutionResult, execute

graphql_server/quart/graphqlview.py

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import copy
2-
import sys
32
from collections.abc import MutableMapping
43
from functools import partial
54
from typing import List
@@ -165,11 +164,11 @@ async def parse_body():
165164
# information provided by content_type
166165
content_type = request.mimetype
167166
if content_type == "application/graphql":
168-
refined_data = await request.get_data(raw=False)
167+
refined_data = await request.get_data(as_text=True)
169168
return {"query": refined_data}
170169

171170
elif content_type == "application/json":
172-
refined_data = await request.get_data(raw=False)
171+
refined_data = await request.get_data(as_text=True)
173172
return load_json_body(refined_data)
174173

175174
elif content_type == "application/x-www-form-urlencoded":
@@ -191,20 +190,8 @@ def should_display_graphiql(self):
191190
def request_wants_html():
192191
best = request.accept_mimetypes.best_match(["application/json", "text/html"])
193192

194-
# Needed as this was introduced at Quart 0.8.0: https://gitlab.com/pgjones/quart/-/issues/189
195-
def _quality(accept, key: str) -> float:
196-
for option in accept.options:
197-
if accept._values_match(key, option.value):
198-
return option.quality
199-
return 0.0
200-
201-
if sys.version_info >= (3, 7):
202-
return (
203-
best == "text/html"
204-
and request.accept_mimetypes[best]
205-
> request.accept_mimetypes["application/json"]
206-
)
207-
else:
208-
return best == "text/html" and _quality(
209-
request.accept_mimetypes, best
210-
) > _quality(request.accept_mimetypes, "application/json")
193+
return (
194+
best == "text/html"
195+
and request.accept_mimetypes[best]
196+
> request.accept_mimetypes["application/json"]
197+
)

graphql_server/render_graphiql.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Based on (express-graphql)[https://github.com/graphql/express-graphql/blob/master/src/renderGraphiQL.js] and
1+
"""Based on (express-graphql)[https://github.com/graphql/express-graphql/blob/main/src/renderGraphiQL.ts] and
22
(subscriptions-transport-ws)[https://github.com/apollographql/subscriptions-transport-ws]"""
33
import json
44
import re
@@ -7,7 +7,7 @@
77
from jinja2 import Environment
88
from typing_extensions import TypedDict
99

10-
GRAPHIQL_VERSION = "1.0.3"
10+
GRAPHIQL_VERSION = "1.4.7"
1111

1212
GRAPHIQL_TEMPLATE = """<!--
1313
The request to this GraphQL server provided the header "Accept: text/html"
@@ -34,12 +34,12 @@
3434
}
3535
</style>
3636
<link href="//cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.css" rel="stylesheet" />
37-
<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8.1.3/dist/polyfill.min.js"></script>
38-
<script src="//cdn.jsdelivr.net/npm/unfetch@4.1.0/dist/unfetch.umd.js"></script>
39-
<script src="//cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js"></script>
40-
<script src="//cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js"></script>
37+
<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8.2.0/dist/polyfill.min.js"></script>
38+
<script src="//cdn.jsdelivr.net/npm/unfetch@4.2.0/dist/unfetch.umd.js"></script>
39+
<script src="//cdn.jsdelivr.net/npm/react@16.14.0/umd/react.production.min.js"></script>
40+
<script src="//cdn.jsdelivr.net/npm/react-dom@16.14.0/umd/react-dom.production.min.js"></script>
4141
<script src="//cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.min.js"></script>
42-
<script src="//cdn.jsdelivr.net/npm/[email protected].16/browser/client.js"></script>
42+
<script src="//cdn.jsdelivr.net/npm/[email protected].18/browser/client.js"></script>
4343
<script src="//cdn.jsdelivr.net/npm/[email protected]/browser/client.js"></script>
4444
</head>
4545
<body>
@@ -308,9 +308,8 @@ async def render_graphiql_async(
308308
jinja_env: Optional[Environment] = config.get("jinja_env")
309309

310310
if jinja_env:
311-
# This method returns a Template. See https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.Template
312311
template = jinja_env.from_string(graphiql_template)
313-
if jinja_env.is_async: # type: ignore
312+
if jinja_env.is_async:
314313
source = await template.render_async(**template_vars)
315314
else:
316315
source = template.render(**template_vars)

graphql_server/sanic/graphqlview.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_validation_rules(self):
8585
return specified_rules
8686
return self.validation_rules
8787

88-
async def dispatch_request(self, request, *args, **kwargs):
88+
async def __handle_request(self, request, *args, **kwargs):
8989
try:
9090
request_method = request.method.lower()
9191
data = self.parse_body(request)
@@ -173,6 +173,8 @@ async def dispatch_request(self, request, *args, **kwargs):
173173
content_type="application/json",
174174
)
175175

176+
get = post = put = head = options = patch = delete = __handle_request
177+
176178
# noinspection PyBroadException
177179
def parse_body(self, request):
178180
content_type = self.get_mime_type(request)

graphql_server/webob/graphqlview.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
class GraphQLView:
2929
schema = None
30-
request = None
3130
root_value = None
3231
context = None
3332
pretty = False
@@ -187,8 +186,9 @@ def should_display_graphiql(self, request):
187186
if not self.graphiql or "raw" in request.params:
188187
return False
189188

190-
return self.request_wants_html()
189+
return self.request_wants_html(request)
191190

192-
def request_wants_html(self):
193-
best = self.request.accept.best_match(["application/json", "text/html"])
191+
@staticmethod
192+
def request_wants_html(request):
193+
best = request.accept.best_match(["application/json", "text/html"])
194194
return best == "text/html"

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ignore = E203, E501, W503
55

66
[isort]
77
known_first_party=graphql_server
8+
profile=black
89
multi_line_output=3
910
include_trailing_comma=True
1011
force_grid_wrap=0

setup.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
from re import search
22
from setuptools import setup, find_packages
33

4-
install_requires = ["graphql-core>=3.2,<3.3", "typing-extensions>=4,<5"]
4+
install_requires = [
5+
"graphql-core>=3.2,<3.3",
6+
"typing-extensions>=4,<5",
7+
]
58

69
tests_requires = [
7-
"pytest>=6.2,<6.3",
8-
"pytest-asyncio>=0.16,<1",
9-
"pytest-cov>=3,<4",
10-
"aiohttp>=3.8,<4",
11-
"Jinja2>=2.11,<3",
10+
"pytest>=7.2,<8",
11+
"pytest-asyncio>=0.20,<1",
12+
"pytest-cov>=4,<5",
13+
"Jinja2>=3.1,<4",
14+
"sanic-testing>=22.3,<23",
1215
]
1316

1417
dev_requires = [
15-
"flake8>=4,<5",
18+
"flake8>=5,<6",
1619
"isort>=5,<6",
17-
"black>=19.10b0",
18-
"mypy>=0.931,<1",
20+
"black>=22.12,<22.13",
21+
"mypy>=0.991,<1",
1922
"check-manifest>=0.47,<1",
2023
] + tests_requires
2124

2225
install_flask_requires = [
23-
"flask>=1,<2",
26+
"flask>=1,<3",
2427
]
2528

2629
install_sanic_requires = [
27-
"sanic>=20.3,<21",
30+
"sanic>=21.12,<23",
2831
]
2932

3033
install_webob_requires = [
@@ -35,7 +38,7 @@
3538
"aiohttp>=3.8,<4",
3639
]
3740

38-
install_quart_requires = ["quart>=0.6.15,<0.15"]
41+
install_quart_requires = ["quart>=0.15,<1"]
3942

4043
install_all_requires = (
4144
install_requires

tests/aiohttp/test_graphiqlview.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import pytest_asyncio
23
from aiohttp.test_utils import TestClient, TestServer
34
from jinja2 import Environment
45

@@ -12,7 +13,7 @@ def app():
1213
return app
1314

1415

15-
@pytest.fixture
16+
@pytest_asyncio.fixture
1617
async def client(app):
1718
client = TestClient(TestServer(app))
1819
await client.start_server()

tests/aiohttp/test_graphqlview.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from urllib.parse import urlencode
33

44
import pytest
5+
import pytest_asyncio
56
from aiohttp import FormData
67
from aiohttp.test_utils import TestClient, TestServer
78

@@ -15,7 +16,7 @@ def app():
1516
return app
1617

1718

18-
@pytest.fixture
19+
@pytest_asyncio.fixture
1920
async def client(app):
2021
client = TestClient(TestServer(app))
2122
await client.start_server()

tests/quart/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from quart.typing import TestClientProtocol
2+
3+
TestClientProtocol.__test__ = False # type: ignore

0 commit comments

Comments
 (0)