Skip to main content

Graphene Tornado integration

Project description

Build Status Coverage Status


A project for running Graphene on top of Tornado in Python 2 and 3. The codebase is a port of graphene-django.

Getting started

Create a Tornado application and add the GraphQL handlers:

import tornado.web
from tornado.ioloop import IOLoop

from graphene_tornado.schema import schema
from graphene_tornado.tornado_graphql_handler import TornadoGraphQLHandler

class ExampleApplication(tornado.web.Application):

    def __init__(self):
        handlers = [
            (r'/graphql', TornadoGraphQLHandler, dict(graphiql=True, schema=schema)),
            (r'/graphql/batch', TornadoGraphQLHandler, dict(graphiql=True, schema=schema, batch=True)),
            (r'/graphql/graphiql', TornadoGraphQLHandler, dict(graphiql=True, schema=schema))
        tornado.web.Application.__init__(self, handlers)

if __name__ == '__main__':
    app = ExampleApplication()

When writing your resolvers, decorate them with either Tornado’s @coroutine decorator for Python 2.7:

def resolve_foo(self, info):
  foo = yield db.get_foo()
  raise Return(foo)

Or use the async / await pattern in Python 3:

async def resolve_foo(self, info):
  foo = await db.get_foo()
  return foo

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for graphene-tornado, version 2.6.0
Filename, size File type Python version Upload date Hashes
Filename, size graphene_tornado-2.6.0-py2.py3-none-any.whl (51.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size graphene-tornado-2.6.0.tar.gz (39.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page