Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: AppSync Resolver Event Utils [DRAFT] #324

Closed
michaelbrewer opened this issue Mar 10, 2021 · 3 comments
Closed

RFC: AppSync Resolver Event Utils [DRAFT] #324

michaelbrewer opened this issue Mar 10, 2021 · 3 comments
Labels

Comments

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Mar 10, 2021

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

@michaelbrewer michaelbrewer added RFC triage Pending triage from maintainers labels Mar 10, 2021
@michaelbrewer michaelbrewer changed the title RFC: AppSync Resolver Utils RFC: AppSync Resolver Event Utils Mar 11, 2021
@heitorlessa
Copy link
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.

@michaelbrewer
Copy link
Contributor Author

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

@michaelbrewer michaelbrewer changed the title RFC: AppSync Resolver Event Utils RFC: AppSync Resolver Event Utils [DRAFT] Mar 12, 2021
@michaelbrewer
Copy link
Contributor Author

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

michaelbrewer referenced this issue in gyft/aws-lambda-powertools-python Mar 13, 2021
Changes:
- Move existing scalar util functions in to scalar_types_utils.py
- Add support for timezone offset
- Add docstrings for scalar utils
- Update tests

Closes #324
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants