Skip to main content

version badge GitHub

Sleemo: AWS AppSync Direct Lambda Resolver Framework

A Simple yet powerful serverless GraphQL framework powered by AWS AppSync Direct Lambda Resolver.

Features

  • No need to manually import other resolver functions and manage the tedious if-else based router from the gateway Lambda handler.
  • The arguments of AppSync operations(queries and mutations) being parsed and passed to each resolver functions automatically.
  • A utility functions provided to easily convert from and to AppSync scalar types such as AWSDateTime or AWSJSON

Installation

pip install sleemo

Usage

Project Structure

An example of the Sleemo project could be structured like below:

/
|-- gatewayLambda.py
|-- resolvers/
|----- getTodo.py
|----- listTodo.py
|----- createTodo.py
|----- updateTodo.py
|----- deleteTodo.py
|-- requirements.txt

An example code with this project structure is given in the next section.

An Example GraphQL Schema

type Todo {
  id: ID!
  author: String!
  title: String!
  content: String
  done: Boolean!
  createdAt: AWSDateTime!
}

input CreateTodoInput {
  author: String!
  title: String!
  content: String
  done: Boolean
}

input UpdateTodoInput {
  author: String
  title: String
  content: String
  done: Boolean
}

type Query {
  getTodo(id: ID!): Todo
  listTodo: [Todo!]!
}

type Mutation {
  createTodo(input: CreateTodoInput!): Todo
  updateTodo(input: UpdateTodoInput!): Todo
  deleteTodo(id: ID!): Todo
}

An Example Python Code

gatewayLambda.py is the default gateway of the AppSync resolver. It receives the event and route this event to appropriate functions.

from sleemo.framework import get_appsync_framework

sleemo = get_appsync_framework(resolver_path='resolvers')

@sleemo.default_gateway()
def handler(event, context):
    return sleemo.resolve(event)

resolver_path represents where your resolver files are located.

Now, let's take a look at how each resolver file lookes like. Sleemo doesn't care of how each resolver function should be implemented. You can use any libraries you prefer to implement your resolvers. Sleemo just passes the operation argument input: CreateTodoInput to createTodo() function with the original event variable.

from sleemo.utils import get_type_utils
from sleemo.framework import get_logger

logger = get_logger()

def createTodo(input, event):

    ## Your business logic here. 
    ## Below is an example of return data

    logger.info('createTodo start')

    utils = get_type_utils(timezone_offset=9)

    todo = {
        'id': utils.createUUID(),
        'author': input['author'],
        'title': input['title'],
        'content': input['content'],
        'done': False,
        'createdAt': utils.createAWSDateTime(),
    }

    logger.info('createTodo end')

    return todo

Let's take another example of the resolver function getTodo().

from sleemo.utils import get_type_utils

def getTodo(id, event):

    ## Your business logic here. 
    ## Below is an example of return data

    utils = get_type_utils(timezone_offset=9)

    todo = {
        'id': utils.createUUID(),
        'author': 'Taewoo Kim',
        'title': 'Sleemo Usage Example',
        'content': 'Simple yet powerful serverless GraphQL framework',
        'done': False,
        'createdAt': utils.createAWSDateTime(),
    }

    return todo

LICENSE

MIT LICENSE

Metadata

Release files for sleemo 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sleemo 0.1.2
File Size Uploaded
sleemo-0.1.2.tar.gz 5.7 kB Details

Release files / sleemo-0.1.2.tar.gz

Download URL sleemo-0.1.2.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7f5cfc4a4274b62e14a407239914afef5b2d13f2aae0b7de7f010000944bd768
BLAKE2b-256 checksum
How to use checksums
88c4ae952e3a3b3b2827fb436c60fe8349df679b9beeb6ec01476ba6b97bbefb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page