Using PyQL

PyQL provides a convenient way of defining GraphQL APIs.


pipenv install pyql


You can replace the contents of app/ with the PyQL equivalent.


PySQL Schema objects need to be compiled into a graphql-core schema object before being passed to GraphQLView.

Replace this line in app/

app = create_graphql_app(schema)

with this:

app = create_graphql_app(schema.compile())

File: app/

from typing import List

from pyql import Schema, Object

from app.db.query.example import (
    create_note, delete_note, get_note, list_notes, update_note)

schema = Schema()

Note = Object('Note', {
    'id': int,
    'title': str,
    'body': str,

def resolve_list_notes(root, info) -> List[Note]:
    return list_notes()

def resolve_list_notes(root, info, id: int) -> Note:
    return get_note(id)

CreateNoteResult = Object('CreateNoteResult', {'ok': bool, 'note_id': int})

def resolve_create_node(root, info) -> CreateNoteResult:
    note_id = create_note(title, body)
    return CreateNoteResult(ok=True, noteId=note_id)

# ... etc ...