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(appsync): add Router to allow large resolver composition #776

Merged
merged 3 commits into from
Oct 29, 2021

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented Oct 24, 2021

Add support for splitting resolvers into multiple files

Issue #, if available:

  • #652

Description of changes:

Add support for splitting an AppSyncResolver into multiple files (very similar to #645).

Example main.py:

from typing import Dict

from aws_lambda_powertools import Tracer, Logger
from aws_lambda_powertools.event_handler import AppSyncResolver
from aws_lambda_powertools.logging.correlation_paths import APPSYNC_RESOLVER
from aws_lambda_powertools.utilities.typing import LambdaContext

from .resolvers import location, merchant

tracer = Tracer()
logger = Logger()
app = AppSyncResolver()
app.include_router(location.router)
app.include_router(merchant.router)


@tracer.capture_lambda_handler
@logger.inject_lambda_context(correlation_id_path=APPSYNC_RESOLVER)
def lambda_handler(event: Dict, context: LambdaContext):
    app.resolve(event, context)

Example resolvers/location.py:

from typing import List, Dict, Any

from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler.appsync import Router

logger = Logger(child=True)
router = Router()


@router.resolver(type_name="Query", field_name="listLocations")
def list_locations(merchant_id: str) -> List[Dict[str, Any]]:
    return [{"name": "Location name", "merchant_id": merchant_id}]


@router.resolver(type_name="Location", field_name="status")
def resolve_status(merchant_id: str) -> str:
    logger.debug(f"Resolve status for merchant_id: {merchant_id}")
    return "FOO"

Checklist

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

Add support for splitting resolvers into multiple files
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 24, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2021

Codecov Report

Merging #776 (3a2c2e8) into develop (c3769f3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #776   +/-   ##
========================================
  Coverage    99.97%   99.97%           
========================================
  Files          116      116           
  Lines         4939     4948    +9     
  Branches       275      275           
========================================
+ Hits          4938     4947    +9     
  Partials         1        1           
Impacted Files Coverage Δ
aws_lambda_powertools/event_handler/appsync.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 c3769f3...3a2c2e8. Read the comment docs.

@michaelbrewer michaelbrewer changed the title feat(appsync): Support splitting resolvers feat(appsync): Support splitting resolvers into multiple files Oct 24, 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.

Question on whether Router is a better name than Resolver since we already have AppSyncResolver

aws_lambda_powertools/event_handler/appsync.py Outdated Show resolved Hide resolved
@heitorlessa heitorlessa added the feature New feature or functionality label Oct 29, 2021
@heitorlessa heitorlessa changed the title feat(appsync): Support splitting resolvers into multiple files feat(appsync): add Router to allow large resolver composition Oct 29, 2021
@heitorlessa heitorlessa merged commit 8b01fc5 into aws-powertools:develop Oct 29, 2021
@heitorlessa heitorlessa deleted the feat/app-sync-splitting branch October 29, 2021 09:58
heitorlessa added a commit to gyft/aws-lambda-powertools-python that referenced this pull request Oct 29, 2021
…uter

* michaelbrewer/docs/router:
  feat(data-classes): ActiveMQ and RabbitMQ support (aws-powertools#770)
  feat(appsync): add Router to allow large resolver composition (aws-powertools#776)
  chore(deps-dev): bump mkdocs-material from 7.3.3 to 7.3.5 (aws-powertools#781)
  chore(deps-dev): bump flake8-isort from 4.0.0 to 4.1.1 (aws-powertools#785)
  chore(deps): bump urllib3 from 1.26.4 to 1.26.5 (aws-powertools#787)
  chore(deps-dev): bump flake8-eradicate from 1.1.0 to 1.2.0 (aws-powertools#784)
  chore(deps): bump boto3 from 1.18.61 to 1.19.6 (aws-powertools#783)
  chore(deps-dev): bump pytest-asyncio from 0.15.1 to 0.16.0 (aws-powertools#782)
  docs: fix indentation of SAM snippets in install section (aws-powertools#778)
  Fix middleware sample (aws-powertools#772)
  Removed unused import, added typing imports, fixed typo in example. (aws-powertools#774)
  Fix middleware sample (aws-powertools#772)
  Removed unused import, added typing imports, fixed typo in example. (aws-powertools#774)
  Update docs/core/event_handler/api_gateway.md

# Conflicts:
#	docs/core/event_handler/api_gateway.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants