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

feat(event-handler): Add AppSync handler decorator #363

Merged
merged 19 commits into from
Mar 31, 2021

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented Mar 25, 2021

Issue #, if available:

#356

Description of changes:

Changes:

  • Relocate AppSyncResolver to aws_lambda_powertools/event_handler
  • Add docstrings for AppSyncResolver
  • Fixed aws_lambda_powertools/utilities/data_classes/__init__.py imports
  • Add initial markdown docs for AppSyncResolver
  • Add current_event and lambda_context to AppSyncResolver

UX example:

from aws_lambda_powertools.event_handler import AppSyncResolver

app = AppSyncResolver()

@app.resolver(type_name="Query", field_name="listLocations")
def list_locations(page: int = 0, size: int = 10):
    """ Your logic to fetch locations """

@app.resolver(type_name="Merchant", field_name="extraInfo")
def get_extra_info():
     """ Can use "app.current_event.source" to filter within the parent context  """

@app.resolver(field_name="commonField")
def common_field():
     """ Would match all fieldNames matching 'commonField'  """


def handle(event, context):
    app.resolve(event, context)

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@michaelbrewer
Copy link
Contributor Author

@heitorlessa i moved this to the event_handler location. Just have not added a new section in the docs for event_handler

@codecov-io
Copy link

codecov-io commented Mar 26, 2021

Codecov Report

Merging #363 (02818db) into develop (9f08fa6) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #363      +/-   ##
===========================================
- Coverage    99.94%   99.94%   -0.01%     
===========================================
  Files           97       98       +1     
  Lines         3687     3686       -1     
  Branches       175      173       -2     
===========================================
- Hits          3685     3684       -1     
  Partials         2        2              
Impacted Files Coverage Δ
aws_lambda_powertools/event_handler/__init__.py 100.00% <100.00%> (ø)
aws_lambda_powertools/event_handler/appsync.py 100.00% <100.00%> (ø)
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f08fa6...02818db. Read the comment docs.

@heitorlessa heitorlessa added this to the 1.14.0 milestone Mar 29, 2021
@heitorlessa heitorlessa added area/utilities feature New feature or functionality labels Mar 29, 2021
@heitorlessa heitorlessa self-assigned this Mar 30, 2021
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how simple the UX is, and mostly intuitive. I've added some comments on debugging statements, internal naming and conventions, and the move to a core utility (in 2.0 we will cease to call core vs general utility).

docs/index.md Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
docs/utilities/data_classes.md Show resolved Hide resolved
mkdocs.yml Outdated Show resolved Hide resolved
docs/utilities/event_handler.md Outdated Show resolved Hide resolved
aws_lambda_powertools/utilities/event_handler/appsync.py Outdated Show resolved Hide resolved
@heitorlessa
Copy link
Contributor

Summarizing, as once this is done, we are ready to prep for a new release.

  1. Move to the root instead of utilities/ - We’ll treat this as a core utility, so same for Docs placement
  2. Docstring to have a sample return: feat(event-handler): Add AppSync handler decorator #363 (comment)
  3. Debug statements, for example registering a resolver, and any other area you see it’d be helpful to debug issues raised
  4. The changes we discussed on Slack - remove include_event, bring in current_event, and lambda_context, etc.
  5. Optionally (I can do that) - Getting started vs Advanced docs, we should be providing a simple example to get started with (AppSync Direct Lambda Resolver) and only then Amplify-CLI @function

@michaelbrewer
Copy link
Contributor Author

Summarizing, as once this is done, we are ready to prep for a new release.

  1. Move to the root instead of utilities/ - We’ll treat this as a core utility, so same for Docs placement
  2. Docstring to have a sample return: #363 (comment)
  3. Debug statements, for example registering a resolver, and any other area you see it’d be helpful to debug issues raised
  4. The changes we discussed on Slack - remove include_event, bring in current_event, and lambda_context, etc.
  5. Optionally (I can do that) - Getting started vs Advanced docs, we should be providing a simple example to get started with (AppSync Direct Lambda Resolver) and only then Amplify-CLI @function

Most of this has been done, regarding the documentation I would help to have a complete example for both. Either in the core docs or a referenced article/blog post and repo

@heitorlessa
Copy link
Contributor

looking :)

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last minor change to ease coming back at this code (gotta resolver the resolvers within resolvers :D)

Everything else is good to go!

aws_lambda_powertools/event_handler/appsync.py Outdated Show resolved Hide resolved
aws_lambda_powertools/event_handler/appsync.py Outdated Show resolved Hide resolved
@heitorlessa heitorlessa merged commit a2c82b5 into aws-powertools:develop Mar 31, 2021
heitorlessa referenced this pull request in heitorlessa/aws-lambda-powertools-python Apr 4, 2021
* develop:
  fix(idempotent): Correctly raise IdempotencyKeyError (#378)
  feat(event-handler): Add AppSync handler decorator (#363)
  feat(parameter): add dynamodb_endpoint_url for local_testing (#376)
  fix(parser): S3Model support empty keys (#375)
  fix(data-classes): Add missing operationName (#373)
  fix: perf tests for Logger and fail str msgs
  feat(parser): Add S3 Object Lambda Event (#362)
  build(pre-commit): Add pre-commit to make pr (#368)
  fix(tracer): Correct type hint for MyPy (#365)
  fix(metrics): AttributeError raised by MediaManager and Typing and docs (#357)

Signed-off-by: heitorlessa <[email protected]>
@michaelbrewer michaelbrewer deleted the feat-event-handler-appsync branch April 18, 2021 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants