Skip to content

RFC: AppSync Resolver Event Utils [DRAFT] #324

Closed

Description

@michaelbrewer

Key information

Summary

One paragraph explanation of the feature.

Motivation

Why are we doing this? What use cases does it support? What is the expected outcome?

Make it easier to map multiple AppSync resolvers to a single lambda. Also to have a collection of useful utility functions.

Proposal

Something like : https://github.com/twkiiim/sleemo

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import AppSyncResolverEvent
from aws_lambda_powertools.utilities.data_classes.appsync_resolver_utils import (
    AppSyncResolver,
    make_id,
    aws_date,
    aws_datetime,
    aws_time,
    aws_timestamp,
)

logger = Logger()
app = AppSyncResolver()


@app.resolver(field_name="locations", include_event=True, include_context: True)
def get_locations(event: AppSyncResolverEvent, context: LambdaContext, name: str = None):
    logger.info(event)
    return f"returning locations for {name}"


@app.resolver(type_name="Merchant", field_name="anotherField")
def another_field_resolver(count: int):
    return {
        "id": make_id(),
        "date": aws_date(),
        "date_time": aws_datetime(),
        "time": aws_time(),
        "ts": aws_timestamp(),
        "message": f"another_field_resolver with parameter count={count}",
    }


@app.resolver(type_name="Query", field_name="noParams")
def no_params():
    return "no_params has no params"


def handler(event: dict, context):
    return app.resolve(event, context)

This is the bulk of the RFC.

Explain the design in enough detail for somebody familiar with Powertools to understand it, and for somebody familiar with the implementation to implement it.

This should get into specifics and corner-cases, and include examples of how the feature is used. Any new terminology should be defined here.

Drawbacks

Why should we not do this?

Do we need additional dependencies? Impact performance/package size?

Rationale and alternatives

  • What other designs have been considered? Why not them?
  • What is the impact of not doing this?

Unresolved questions

Optional, stash area for topics that need further development e.g. TBD

Activity

  1. heitorlessa commented on Mar 12, 2021

    @heitorlessa
    Contributor

    Hey @michaelbrewer - Could you let us know when the RFC body is ready to review? It's missing a few sections like summary, drawbacks, rationale, and any open questions you might have (if any), etc.

  2. michaelbrewer commented on Mar 12, 2021

    @michaelbrewer
    ContributorAuthor

    Sorry yes @heitorlessa i will put that in. I was just mentally making sure i would look at this :)

  3. michaelbrewer commented on Mar 13, 2021

    @michaelbrewer
    ContributorAuthor

    @heitorlessa i guess it is mostly implemented what i wanted to support initially, but i will try to describe it more

  4. removed
    triage
    on Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions