Skip to content

Commit e904b15

Browse files
committed
Black the example code
1 parent 75cad35 commit e904b15

14 files changed

Lines changed: 128 additions & 124 deletions

File tree

examples/aiohttp/app.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,35 @@
1010

1111
async def graphql_view(request):
1212
payload = await request.json()
13-
response = await schema.execute(payload.get('query', ''), return_promise=True)
13+
response = await schema.execute(payload.get("query", ""), return_promise=True)
1414
data = {}
1515
if response.errors:
16-
data['errors'] = [format_error(e) for e in response.errors]
16+
data["errors"] = [format_error(e) for e in response.errors]
1717
if response.data:
18-
data['data'] = response.data
18+
data["data"] = response.data
1919
jsondata = json.dumps(data,)
20-
return web.Response(text=jsondata, headers={'Content-Type': 'application/json'})
20+
return web.Response(text=jsondata, headers={"Content-Type": "application/json"})
2121

2222

2323
async def graphiql_view(request):
24-
return web.Response(text=render_graphiql(), headers={'Content-Type': 'text/html'})
24+
return web.Response(text=render_graphiql(), headers={"Content-Type": "text/html"})
25+
2526

2627
subscription_server = AiohttpSubscriptionServer(schema)
2728

2829

2930
async def subscriptions(request):
30-
ws = web.WebSocketResponse(protocols=('graphql-ws',))
31+
ws = web.WebSocketResponse(protocols=("graphql-ws",))
3132
await ws.prepare(request)
3233

3334
await subscription_server.handle(ws)
3435
return ws
3536

3637

3738
app = web.Application()
38-
app.router.add_get('/subscriptions', subscriptions)
39-
app.router.add_get('/graphiql', graphiql_view)
40-
app.router.add_get('/graphql', graphql_view)
41-
app.router.add_post('/graphql', graphql_view)
39+
app.router.add_get("/subscriptions", subscriptions)
40+
app.router.add_get("/graphiql", graphiql_view)
41+
app.router.add_get("/graphql", graphql_view)
42+
app.router.add_post("/graphql", graphql_view)
4243

4344
web.run_app(app, port=8000)

examples/aiohttp/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ async def resolve_count_seconds(root, info, up_to=5):
2020
for i in range(up_to):
2121
print("YIELD SECOND", i)
2222
yield i
23-
await asyncio.sleep(1.)
23+
await asyncio.sleep(1.0)
2424
yield up_to
2525

2626
async def resolve_random_int(root, info):
2727
i = 0
2828
while True:
2929
yield RandomType(seconds=i, random_int=random.randint(0, 500))
30-
await asyncio.sleep(1.)
30+
await asyncio.sleep(1.0)
3131
i += 1
3232

3333

examples/aiohttp/template.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
from string import Template
32

43

54
def render_graphiql():
6-
return Template('''
5+
return Template(
6+
"""
77
<!DOCTYPE html>
88
<html>
99
<head>
@@ -116,10 +116,11 @@ def render_graphiql():
116116
);
117117
</script>
118118
</body>
119-
</html>''').substitute(
120-
GRAPHIQL_VERSION='0.10.2',
121-
SUBSCRIPTIONS_TRANSPORT_VERSION='0.7.0',
122-
subscriptionsEndpoint='ws://localhost:8000/subscriptions',
119+
</html>"""
120+
).substitute(
121+
GRAPHIQL_VERSION="0.10.2",
122+
SUBSCRIPTIONS_TRANSPORT_VERSION="0.7.0",
123+
subscriptionsEndpoint="ws://localhost:8000/subscriptions",
123124
# subscriptionsEndpoint='ws://localhost:5000/',
124-
endpointURL='/graphql',
125+
endpointURL="/graphql",
125126
)

examples/django_subscriptions/django_subscriptions/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_subscriptions.settings")
55

6-
channel_layer = get_channel_layer()
6+
channel_layer = get_channel_layer()

examples/django_subscriptions/django_subscriptions/schema.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ class Query(graphene.ObjectType):
66
hello = graphene.String()
77

88
def resolve_hello(self, info, **kwargs):
9-
return 'world'
9+
return "world"
10+
1011

1112
class Subscription(graphene.ObjectType):
1213

1314
count_seconds = graphene.Int(up_to=graphene.Int())
1415

15-
1616
def resolve_count_seconds(root, info, up_to=5):
17-
return Observable.interval(1000)\
18-
.map(lambda i: "{0}".format(i))\
19-
.take_while(lambda i: int(i) <= up_to)
20-
17+
return (
18+
Observable.interval(1000)
19+
.map(lambda i: "{0}".format(i))
20+
.take_while(lambda i: int(i) <= up_to)
21+
)
2122

2223

23-
schema = graphene.Schema(query=Query, subscription=Subscription)
24+
schema = graphene.Schema(query=Query, subscription=Subscription)

examples/django_subscriptions/django_subscriptions/settings.py

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'fa#kz8m$l6)4(np9+-j_-z!voa090mah!s9^4jp=kj!^nwdq^c'
23+
SECRET_KEY = "fa#kz8m$l6)4(np9+-j_-z!voa090mah!s9^4jp=kj!^nwdq^c"
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
@@ -31,53 +31,53 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34-
'django.contrib.admin',
35-
'django.contrib.auth',
36-
'django.contrib.contenttypes',
37-
'django.contrib.sessions',
38-
'django.contrib.messages',
39-
'django.contrib.staticfiles',
40-
'channels',
34+
"django.contrib.admin",
35+
"django.contrib.auth",
36+
"django.contrib.contenttypes",
37+
"django.contrib.sessions",
38+
"django.contrib.messages",
39+
"django.contrib.staticfiles",
40+
"channels",
4141
]
4242

4343
MIDDLEWARE = [
44-
'django.middleware.security.SecurityMiddleware',
45-
'django.contrib.sessions.middleware.SessionMiddleware',
46-
'django.middleware.common.CommonMiddleware',
47-
'django.middleware.csrf.CsrfViewMiddleware',
48-
'django.contrib.auth.middleware.AuthenticationMiddleware',
49-
'django.contrib.messages.middleware.MessageMiddleware',
50-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
44+
"django.middleware.security.SecurityMiddleware",
45+
"django.contrib.sessions.middleware.SessionMiddleware",
46+
"django.middleware.common.CommonMiddleware",
47+
"django.middleware.csrf.CsrfViewMiddleware",
48+
"django.contrib.auth.middleware.AuthenticationMiddleware",
49+
"django.contrib.messages.middleware.MessageMiddleware",
50+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5151
]
5252

53-
ROOT_URLCONF = 'django_subscriptions.urls'
53+
ROOT_URLCONF = "django_subscriptions.urls"
5454

5555
TEMPLATES = [
5656
{
57-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58-
'DIRS': [],
59-
'APP_DIRS': True,
60-
'OPTIONS': {
61-
'context_processors': [
62-
'django.template.context_processors.debug',
63-
'django.template.context_processors.request',
64-
'django.contrib.auth.context_processors.auth',
65-
'django.contrib.messages.context_processors.messages',
57+
"BACKEND": "django.template.backends.django.DjangoTemplates",
58+
"DIRS": [],
59+
"APP_DIRS": True,
60+
"OPTIONS": {
61+
"context_processors": [
62+
"django.template.context_processors.debug",
63+
"django.template.context_processors.request",
64+
"django.contrib.auth.context_processors.auth",
65+
"django.contrib.messages.context_processors.messages",
6666
],
6767
},
6868
},
6969
]
7070

71-
WSGI_APPLICATION = 'django_subscriptions.wsgi.application'
71+
WSGI_APPLICATION = "django_subscriptions.wsgi.application"
7272

7373

7474
# Database
7575
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
7676

7777
DATABASES = {
78-
'default': {
79-
'ENGINE': 'django.db.backends.sqlite3',
80-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
78+
"default": {
79+
"ENGINE": "django.db.backends.sqlite3",
80+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
8181
}
8282
}
8383

@@ -87,26 +87,20 @@
8787

8888
AUTH_PASSWORD_VALIDATORS = [
8989
{
90-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91-
},
92-
{
93-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94-
},
95-
{
96-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97-
},
98-
{
99-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
90+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
10091
},
92+
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
93+
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
94+
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
10195
]
10296

10397

10498
# Internationalization
10599
# https://docs.djangoproject.com/en/1.11/topics/i18n/
106100

107-
LANGUAGE_CODE = 'en-us'
101+
LANGUAGE_CODE = "en-us"
108102

109-
TIME_ZONE = 'UTC'
103+
TIME_ZONE = "UTC"
110104

111105
USE_I18N = True
112106

@@ -118,20 +112,17 @@
118112
# Static files (CSS, JavaScript, Images)
119113
# https://docs.djangoproject.com/en/1.11/howto/static-files/
120114

121-
STATIC_URL = '/static/'
122-
CHANNELS_WS_PROTOCOLS = ["graphql-ws", ]
115+
STATIC_URL = "/static/"
116+
CHANNELS_WS_PROTOCOLS = [
117+
"graphql-ws",
118+
]
123119
CHANNEL_LAYERS = {
124120
"default": {
125121
"BACKEND": "asgi_redis.RedisChannelLayer",
126-
"CONFIG": {
127-
"hosts": [("localhost", 6379)],
128-
},
122+
"CONFIG": {"hosts": [("localhost", 6379)]},
129123
"ROUTING": "django_subscriptions.urls.channel_routing",
130124
},
131-
132125
}
133126

134127

135-
GRAPHENE = {
136-
'SCHEMA': 'django_subscriptions.schema.schema'
137-
}
128+
GRAPHENE = {"SCHEMA": "django_subscriptions.schema.schema"}

examples/django_subscriptions/django_subscriptions/template.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
from string import Template
32

43

54
def render_graphiql():
6-
return Template('''
5+
return Template(
6+
"""
77
<!DOCTYPE html>
88
<html>
99
<head>
@@ -116,10 +116,11 @@ def render_graphiql():
116116
);
117117
</script>
118118
</body>
119-
</html>''').substitute(
120-
GRAPHIQL_VERSION='0.11.10',
121-
SUBSCRIPTIONS_TRANSPORT_VERSION='0.7.0',
122-
subscriptionsEndpoint='ws://localhost:8000/subscriptions',
119+
</html>"""
120+
).substitute(
121+
GRAPHIQL_VERSION="0.11.10",
122+
SUBSCRIPTIONS_TRANSPORT_VERSION="0.7.0",
123+
subscriptionsEndpoint="ws://localhost:8000/subscriptions",
123124
# subscriptionsEndpoint='ws://localhost:5000/',
124-
endpointURL='/graphql',
125+
endpointURL="/graphql",
125126
)

examples/django_subscriptions/django_subscriptions/urls.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@
2121
from graphene_django.views import GraphQLView
2222
from django.views.decorators.csrf import csrf_exempt
2323

24+
from channels.routing import route_class
25+
from graphql_ws.django_channels import GraphQLSubscriptionConsumer
26+
2427

2528
def graphiql(request):
2629
response = HttpResponse(content=render_graphiql())
2730
return response
2831

32+
2933
urlpatterns = [
30-
url(r'^admin/', admin.site.urls),
31-
url(r'^graphiql/', graphiql),
32-
url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=True)))
34+
url(r"^admin/", admin.site.urls),
35+
url(r"^graphiql/", graphiql),
36+
url(r"^graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
3337
]
3438

35-
from channels.routing import route_class
36-
from graphql_ws.django_channels import GraphQLSubscriptionConsumer
37-
3839
channel_routing = [
3940
route_class(GraphQLSubscriptionConsumer, path=r"^/subscriptions"),
40-
]
41+
]

examples/flask_gevent/app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
from flask import Flask, make_response
42
from flask_graphql import GraphQLView
53
from flask_sockets import Sockets
@@ -14,19 +12,20 @@
1412
sockets = Sockets(app)
1513

1614

17-
@app.route('/graphiql')
15+
@app.route("/graphiql")
1816
def graphql_view():
1917
return make_response(render_graphiql())
2018

2119

2220
app.add_url_rule(
23-
'/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=False))
21+
"/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=False)
22+
)
2423

2524
subscription_server = GeventSubscriptionServer(schema)
26-
app.app_protocol = lambda environ_path_info: 'graphql-ws'
25+
app.app_protocol = lambda environ_path_info: "graphql-ws"
2726

2827

29-
@sockets.route('/subscriptions')
28+
@sockets.route("/subscriptions")
3029
def echo_socket(ws):
3130
subscription_server.handle(ws)
3231
return []
@@ -35,5 +34,6 @@ def echo_socket(ws):
3534
if __name__ == "__main__":
3635
from gevent import pywsgi
3736
from geventwebsocket.handler import WebSocketHandler
38-
server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
37+
38+
server = pywsgi.WSGIServer(("", 5000), app, handler_class=WebSocketHandler)
3939
server.serve_forever()

examples/flask_gevent/schema.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ class Subscription(graphene.ObjectType):
1919
random_int = graphene.Field(RandomType)
2020

2121
def resolve_count_seconds(root, info, up_to=5):
22-
return Observable.interval(1000)\
23-
.map(lambda i: "{0}".format(i))\
24-
.take_while(lambda i: int(i) <= up_to)
22+
return (
23+
Observable.interval(1000)
24+
.map(lambda i: "{0}".format(i))
25+
.take_while(lambda i: int(i) <= up_to)
26+
)
2527

2628
def resolve_random_int(root, info):
27-
return Observable.interval(1000).map(lambda i: RandomType(seconds=i, random_int=random.randint(0, 500)))
29+
return Observable.interval(1000).map(
30+
lambda i: RandomType(seconds=i, random_int=random.randint(0, 500))
31+
)
2832

2933

3034
schema = graphene.Schema(query=Query, subscription=Subscription)

0 commit comments

Comments
 (0)