Schema and Resolvers

Cannula levelages schema first design to generate schema. This allows your schema to have maximum portability and also is very easy to read and document.

Using the API

class cannula.api.API(*args, resolvers=[], context=<class 'cannula.context.Context'>, middleware=[], **kwargs)

Cannula API

Your entry point into the fun filled world of graphql. Just dive right in:

import cannula

api = cannula.API(__name__, schema='''
    extend type Query {
        hello(who: String): String

def hello(who):
    return f'Hello {who}!'
call(document, request=None, variables=None)

Preform a query against the schema.

This is meant to be called in an asyncio.loop, if you are using a web framework that is synchronous use the call_sync method.

Return type


class cannula.api.Resolver(name, schema=None, schema_directory='schema', query_directory='queries')

Resolver Registry

This class is a helper to organize your project as it grows. It allows you to put your resolver modules and schema in different packages. For example:

app/  # `api = cannula.API(__name__)`
    subpackage/  # `app = cannula.Resolver(__name__)`

You then register resolvers and dataloaders in the same way:
import cannula

app = cannula.Resolver(__name__)

def my_query(source, info):
    return 'Hello'
import cannula

from import app

api = cannula.API(__name__)
  • name (str) – The import name of the resolver, typically __name__

  • schema (Union[str, DocumentNode, None]) – GraphQL Schema for this resolver.

  • schema_directory (str) – Directory name to search for schema files.

  • query_directory (str) – Directory name to search for query docs.

get_form_mutation(name, **kwargs)

Get registered form mutation document

Return type


get_form_query(name, **kwargs)

Get registered form query document

Return type