Skip to content

academicmerit/aiographql

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 <denisr@denisr.com> and other aiographql authors
Copyright (C) 2018 by AcademicMerit LLC (dba FineTune)
MIT License, see https://opensource.org/licenses/MIT

About

asyncio + graphql = fast and simple api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published