asyncio - explicit concurrency to reduce race conditions
graphql - all you need and nothing more in one request +auto docs of your api
minimal http - unlike REST frameworks that are waste of time for /graphql endpoint
pluggable context - for auth, logging, etc
exception handling - at all levels, with default or custom handler
Usage:
pip install aiographql
cat <<'END' >serve.py
import asyncio, aiographql, graphene
class User(graphene.ObjectType):
id = graphene.ID(required=True)
name = graphene.String()
class Query(graphene.ObjectType):
me = graphene.Field(User)
async def resolve_me(self, info):
await asyncio.sleep(1) # DB
return User(id=42, name='John')
schema = graphene.Schema(query=Query, mutation=None)
aiographql.serve(schema, listen=[
dict(protocol='tcp', port=25100),
dict(protocol='unix', path='/tmp/worker0'),
])
END
python3 serve.py
curl http://localhost:25100/ --data-binary \
'{"query": "{
me {
id
name
}
}", "variables": null}'
# OR:
curl --unix-socket /tmp/worker0 http:/ --data-binary ...
# Result:
# 1 second async await for DB and then:
{"data":{"me":{"id":"42","name":"John"}}}
See more examples and tests about JWT auth, concurrent slow DB queries, etc.
Config:
import aiographql; help(aiographql.serve)
serve(schema, listen, get_context=None, exception_handler=None, enable_uvloop=True, run=True)
Configure the stack and start serving requests
schema: graphene.Schema - GraphQL schema to serve
listen: list - one or more endpoints to listen for connections:
dict(protocol='tcp', port=25100, ...) - create_server() docs
dict(protocol='unix', path='/tmp/worker0', ...) - create_unix_server() docs
get_context: None or [async] callable(loop, context: dict): mixed - to produce GraphQL context like auth from input unified with exception_handler()
exception_handler: None or callable(loop, context: dict) - default or custom exception handler as defined in the docs +
headers: bytes or None - HTTP headers, if known
request: dict or bytes or None - accumulated HTTP request before content length is known, then accumulated content, then GraphQL request
enable_uvloop: bool - enable uvloop for top performance, unless you have a better loop
run: bool - if True, run the loop; False is good for tests
return servers: Servers - await servers.close() to close listening sockets - good for tests
Release files for aiographql 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiographql-0.2.1.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiographql-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / aiographql-0.2.1.tar.gz
| Download URL | aiographql-0.2.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
654ce7d1215d27e60599472866e268aad3bac917b034fccdbe8c3271204425dc
|
|
BLAKE2b-256 checksum How to use checksums |
7ee1e8a3af90327fa5e21b6cedaa518fff3ffe1cace31344a0c38e381e18ab44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiographql-0.2.1-py3-none-any.whl
| Download URL | aiographql-0.2.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
beee65a0e6e41ee0bd6b07d7b199423660d4e8b28886da4076530598e7abb182
|
|
BLAKE2b-256 checksum How to use checksums |
93d13c3909b1515717ceee036267d62562903cdd711423d07bf96d44eb8fc834
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |