Skip to content

Latest commit

 

History

History
101 lines (78 loc) · 4.12 KB

README.md

File metadata and controls

101 lines (78 loc) · 4.12 KB

aiographql

asyncio + graphql = fast and simple api

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, remote_addr, etc:
https://github.com/academicmerit/aiographql/tree/master/tests

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

TODO

License

aiographql version 0.2.1
Created and maintained by Denis Ryzhkov <[email protected]> and other aiographql authors
Copyright (C) 2018 by AcademicMerit LLC (dba FineTune)
MIT License, see https://opensource.org/licenses/MIT