Package: aiohttp-graphql
aiohttp-graphqlAddsGraphQLsupport to youraiohttpapplication.Based onflask-graphqlbySyrus Akbaryandsanic-graphqlbySergey Porivaev.UsageJust use theGraphQLViewview fromaiohttp_graphqlfromaiohttp_graphqlimportGraphQLViewGraphQLView.attach(app,schema=Schema,graphiql=True)# Optional, for adding batch query support (used in Apollo-Client)GraphQLView.attach(app,schema=Schema,batch=True)This will add a/graphqlendpoint to your app (customizable by passingroute_path='/mypath'toGraphQLView.attach).Note:GraphQLView.attachis just a convenience function, and the same functionality can be achieved withgql_view=GraphQLView(schema=Schema,**kwargs)app.router.add_route('*',gql_view,name='graphql')It's worth noting that the the "view function" ofGraphQLViewis contained inGraphQLView.__call__. So, when you create an instance, that instance is callable with the request object as the sole positional argument. To illustrate:gql_view=GraphQLView(schema=Schema,**kwargs)gql_view(request)# <-- the instance is callable and expects a `aiohttp.web.Request` object.Supported optionsschema: TheGraphQLSchemaobject that you want the view to execute when it gets a valid request.executor: TheExecutorthat you want to use to execute queries. If anAsyncioExecutorinstance is provided, performs queries asynchronously within executorâ€™s loop.root_value: Theroot_valueyou want to provide toexecutor.execute.context: A value to pass as thecontextto thegraphql()function. By default is set todictwith request object at keyrequest.pretty: Whether or not you want the response to be pretty printed JSON.graphiql: IfTrue, may presentGraphiQLwhen loaded directly from a browser (a useful tool for debugging and exploration).graphiql_version: The version of the providedgraphiqlpackage.graphiql_template: Inject a Jinja template string to customize GraphiQL.middleware: Custom middleware forgraphql-python.batch: Set the GraphQL view as batch (for using inApollo-Clientor [ReactRelayNetworkLayer])jinja_env: Sets jinja environment to be used to process GraphiQL template. If Jinjaâ€™s async mode is enabled (byenable_async=True), usesTemplate.render_asyncinstead ofTemplate.render. If environment is not set, fallbacks to simple regex-based renderer.max_age: sets the response headerAccess-Control-Max-Agefor preflight requestsencoder: the encoder to use for responses (sensibly defaults tographql_server.json_encode)error_formatter: the error formatter to use for responses (sensibly defaults tographql_server.default_format_error)enable_async: whetherasyncmode will be enabled.subscriptions: TheGraphiQLsocket endpoint for using subscriptions ingraphql-ws.TestingTesting is done withpytest.gitclonehttps://github.com/graphql-python/aiohttp-graphqlcdaiohttp-graphql# Create a virtualenvpython3.6-mvenvenv&&sourceenv/bin/activate# for examplepipinstall-e.[test]pytestThe tests, while modeled after sanic-graphql's tests, have been entirely refactored to take advantage ofpytest-asyncio, conform with PEP-8, and increase readability with pytest fixtures. For usage tests, please check them out.LicenseCopyright for portions of projectaiohttp-graphqlare held bySyrus Akbaryas part of projectflask-graphqlandsanic-graphqlas part of projectSergey Porivaev. All other claims to this projectaiohttp-graphqlare held byDevin Fee.This project is licensed under the MIT License.