From d69116a4930cd8d1fbc3dffbbeb76425abaa9cee Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 8 Mar 2022 18:40:01 +0000 Subject: [PATCH 1/2] Restyled by black --- .../minos/plugins/graphql_aiohttp/handlers.py | 11 ++--- .../graphql_aiohttp/handlers/__init__.py | 2 +- .../plugins/graphql_aiohttp/handlers/abc.py | 48 +++++++++---------- .../graphql_aiohttp/handlers/graphiql.py | 4 +- .../graphql_aiohttp/handlers/graphql.py | 1 - .../minos/plugins/graphql_aiohttp/schema.py | 2 +- .../graphql_aiohttp/schemas/schema_hello.py | 4 +- .../minos/plugins/graphql_aiohttp/services.py | 14 +++--- 8 files changed, 40 insertions(+), 46 deletions(-) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py index b56c32f65..83c55d723 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py @@ -33,10 +33,7 @@ ResponseException, ) -from .handlers import ( - GraphiqlHandler, - GraphqlHandler -) +from .handlers import GraphiqlHandler, GraphqlHandler from .requests import ( RestRequest, ) @@ -129,15 +126,15 @@ def _mount_graphql(self, app: web.Application): """ def register_handlers(self, app: web.Application): - routes = [(r'/graphql', GraphqlHandler)] + routes = [(r"/graphql", GraphqlHandler)] # if self.dev: - routes += [(r'/graphiql', GraphiqlHandler)] + routes += [(r"/graphiql", GraphiqlHandler)] app.router.add_routes([web.view(route[0], route[1]) for route in routes]) async def initialize_jinja2(self, app: web.Application): - aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('./templates')) + aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("./templates")) @staticmethod def get_callback( diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py index 1e49dde44..cbcec5ba1 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py @@ -1,6 +1,6 @@ from .graphql import ( GraphqlHandler, ) -from .graphiql import ( +from .graphiql import ( GraphiqlHandler, ) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py index 628fbe4a7..3b8a82c4d 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py @@ -4,11 +4,11 @@ import json import aiohttp from aiohttp import web -#from graphql.execution.executors.asyncio import AsyncioExecutor +# from graphql.execution.executors.asyncio import AsyncioExecutor -class BaseHandler(web.View): +class BaseHandler(web.View): @property def fetch(self): return self.app.fetch @@ -21,9 +21,9 @@ async def options(self): return web.Response( status=204, headers={ - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH', - 'Access-Control-Allow-Headers': 'x-requested-with,access-control-allow-origin,authorization,content-type', + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH", + "Access-Control-Allow-Headers": "x-requested-with,access-control-allow-origin,authorization,content-type", }, ) @@ -39,17 +39,17 @@ async def handle_graqhql(self): status = 200 result = await self.execute_graphql() logging.debug( - 'GraphQL result data: %s errors: %s', + "GraphQL result data: %s errors: %s", result.data, result.errors, - #result.invalid, + # result.invalid, ) if result and result.errors: status = 500 - #ex = ExecutionError(errors=result.errors) - #logging.debug('GraphQL Error: %s', ex) + # ex = ExecutionError(errors=result.errors) + # logging.debug('GraphQL Error: %s', ex) errors = result.errors @@ -57,44 +57,44 @@ async def handle_graqhql(self): errors = [] return web.json_response( - {'data': result.data, 'errors': [str(err) for err in errors]}, + {"data": result.data, "errors": [str(err) for err in errors]}, status=status, - headers={'Access-Control-Allow-Origin': '*'}, + headers={"Access-Control-Allow-Origin": "*"}, ) async def execute_graphql(self): graphql_req = await self.graphql_request - logging.debug('graphql request: %s', graphql_req) - context_value = graphql_req.get('context', {}) - variables = graphql_req.get('variables', {}) + logging.debug("graphql request: %s", graphql_req) + context_value = graphql_req.get("context", {}) + variables = graphql_req.get("variables", {}) - context_value['application'] = self.app + context_value["application"] = self.app - #executor = AsyncioExecutor(loop=asyncio.get_event_loop()) + # executor = AsyncioExecutor(loop=asyncio.get_event_loop()) result = self.schema.execute( - graphql_req['query'], - #executor=executor, - #return_promise=True, + graphql_req["query"], + # executor=executor, + # return_promise=True, context_value=context_value, variable_values=variables, ) - ref = self.request.headers.get('referer') - url_path = '' + ref = self.request.headers.get("referer") + url_path = "" if ref: url = urllib.parse.urlparse(ref) url_path = url.path if result.errors: - if '/graphiql' not in url_path: + if "/graphiql" not in url_path: aiohttp.log.server_logger.error(f'Graphql query error: for query "{graphql_req}"') return result @property async def graphql_request(self): - if self.request.method == 'GET': - return json.loads(self.request.query['q']) + if self.request.method == "GET": + return json.loads(self.request.query["q"]) return await self.request.json() diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py index 4e82cd7c3..edd1000f6 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py @@ -3,6 +3,6 @@ class GraphiqlHandler(BaseHandler): - @aiohttp_jinja2.template('graphiql.html') + @aiohttp_jinja2.template("graphiql.html") async def get(self): - return {'base_url': f'/graphql'} + return {"base_url": f"/graphql"} diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py index 9746e4f15..3d767a9e6 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py @@ -5,7 +5,6 @@ class GraphqlHandler(GQLBaseHandler): - @property def schema(self): return graphene.Schema(query=AllQuery) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py index 9d1ee5a0e..1e45cee0b 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py @@ -7,4 +7,4 @@ class AllQuery( # Schema2, # Schema3 ): - '''AllQuery''' + """AllQuery""" diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py index b29703d77..8f31af3ee 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py @@ -7,10 +7,10 @@ class Query(ObjectType): goodbye = String() def resolve_hello(root, info, name): - return f'Hello {name}!' + return f"Hello {name}!" def resolve_goodbye(root, info): - return 'See ya!' + return "See ya!" schema = Schema(query=Query) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py index ce26b9858..9cf566f44 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py @@ -6,10 +6,7 @@ from aiomisc.service.aiohttp import ( AIOHTTPService, ) -from .handlers import ( - GraphiqlHandler, - GraphqlHandler -) +from .handlers import GraphiqlHandler, GraphqlHandler class RestService(AIOHTTPService): @@ -24,21 +21,22 @@ def __init__(self, **kwargs): # self.handler = RestHandler.from_config(**kwargs) # super().__init__(**(kwargs | {"address": self.handler.host, "port": self.handler.port})) super().__init__(**(kwargs | {"address": "localhost", "port": 7030})) + """ def _mount_graphql(self, app: web.Application): GraphQLView.attach(app, schema=schema, graphiql=True) """ def register_handlers(self, app: web.Application): - routes = [(r'/graphql', GraphqlHandler)] + routes = [(r"/graphql", GraphqlHandler)] # if self.dev: - routes += [(r'/graphiql', GraphiqlHandler)] + routes += [(r"/graphiql", GraphiqlHandler)] app.router.add_routes([web.view(route[0], route[1]) for route in routes]) async def initialize_jinja2(self, app: web.Application): - aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('./templates')) + aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("./templates")) async def create_application(self) -> web.Application: """Create the web application. @@ -49,6 +47,6 @@ async def create_application(self) -> web.Application: self.register_handlers(app) await self.initialize_jinja2(app) # self._mount_routes(app) - #self._mount_graphql(app) + # self._mount_graphql(app) return app # return self.handler.get_app() # pragma: no cover From a61ea60481e2d3d58a9d7622b94dd158405b3e66 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 8 Mar 2022 18:40:12 +0000 Subject: [PATCH 2/2] Restyled by isort --- .../minos/plugins/graphql_aiohttp/handlers.py | 5 ++++- .../minos/plugins/graphql_aiohttp/handlers/__init__.py | 6 +++--- .../minos/plugins/graphql_aiohttp/handlers/abc.py | 7 +++++-- .../minos/plugins/graphql_aiohttp/handlers/graphiql.py | 5 ++++- .../minos/plugins/graphql_aiohttp/handlers/graphql.py | 9 +++++++-- .../minos/plugins/graphql_aiohttp/schema.py | 4 +++- .../plugins/graphql_aiohttp/schemas/schema_hello.py | 6 +++++- .../minos/plugins/graphql_aiohttp/services.py | 6 +++++- 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py index 83c55d723..d195bc210 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers.py @@ -33,7 +33,10 @@ ResponseException, ) -from .handlers import GraphiqlHandler, GraphqlHandler +from .handlers import ( + GraphiqlHandler, + GraphqlHandler, +) from .requests import ( RestRequest, ) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py index cbcec5ba1..6a3937e81 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/__init__.py @@ -1,6 +1,6 @@ -from .graphql import ( - GraphqlHandler, -) from .graphiql import ( GraphiqlHandler, ) +from .graphql import ( + GraphqlHandler, +) diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py index 3b8a82c4d..8a402d652 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/abc.py @@ -1,9 +1,12 @@ import asyncio +import json import logging import urllib -import json + import aiohttp -from aiohttp import web +from aiohttp import ( + web, +) # from graphql.execution.executors.asyncio import AsyncioExecutor diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py index edd1000f6..3cf938e43 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphiql.py @@ -1,5 +1,8 @@ import aiohttp_jinja2 -from .abc import BaseHandler + +from .abc import ( + BaseHandler, +) class GraphiqlHandler(BaseHandler): diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py index 3d767a9e6..43fcc556a 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/handlers/graphql.py @@ -1,7 +1,12 @@ import graphene -from .abc import GQLBaseHandler -from minos.plugins.graphql_aiohttp.schema import AllQuery +from minos.plugins.graphql_aiohttp.schema import ( + AllQuery, +) + +from .abc import ( + GQLBaseHandler, +) class GraphqlHandler(GQLBaseHandler): diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py index 1e45cee0b..d823cdfe3 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schema.py @@ -1,4 +1,6 @@ -from schemas.schema_hello import Query +from schemas.schema_hello import ( + Query, +) class AllQuery( diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py index 8f31af3ee..951c3210f 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/schemas/schema_hello.py @@ -1,4 +1,8 @@ -from graphene import ObjectType, String, Schema +from graphene import ( + ObjectType, + Schema, + String, +) class Query(ObjectType): diff --git a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py index 9cf566f44..e8bca0f69 100644 --- a/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py +++ b/packages/plugins/minos-graphql-aiohttp/minos/plugins/graphql_aiohttp/services.py @@ -6,7 +6,11 @@ from aiomisc.service.aiohttp import ( AIOHTTPService, ) -from .handlers import GraphiqlHandler, GraphqlHandler + +from .handlers import ( + GraphiqlHandler, + GraphqlHandler, +) class RestService(AIOHTTPService):