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

docs(appsync): add mutation example and infrastructure fix #1964

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Feb 28, 2023

Issue number: #1953

Summary

Changes

Please provide a summary of what's being changed

This PR extends the getting started example by adding a mutation. Previously, we only had queries, making it harder to work with mutations for newcomers of Event Handler AppSync.

  • Add createTodo mutation in the schema
  • Enable mutations in the GraphQL Schema (schema { mutation: Mutation })
  • Updated code snippet to include a mutation event resolution (getting_started_graphql_api_resolver.py)
  • Improved documentation experience when viewing multiple sample events with a new tab (Sample events)

It also improves the example infrastructure to ease reproducing it in the future:

  • Replace Definition with DefinitionS3Location within TodosApiSchema AppSync API resource. This removes schema duplication and prevent error-prone updates by centralizing in a single source of truth
  • Add cfn-lint exception since DefinitionS3Location only works with SAM CLI
  • Add requirements.txt with dependencies used so it can be built with sam build --use-container
  • Add samconfig.toml to ease deploying next time (sam deploy, or sam deploy -g in other accounts). On the fence about this one as someone else deploying will change the file; will keep it for now as it doesn't harm

User experience

Please share what the user experience looks like before and after this change

Schema extended

image

New Sample events tab

image

Sample resolver extended

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@heitorlessa heitorlessa requested a review from a team as a code owner February 28, 2023 17:08
@heitorlessa heitorlessa requested review from am29d and removed request for a team February 28, 2023 17:08
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Feb 28, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 28, 2023
@heitorlessa heitorlessa linked an issue Feb 28, 2023 that may be closed by this pull request
1 task
@tb102122
Copy link

@heitorlessa I think you like to remove "or Title under Todo" in the type explanation section or?
For completion we should also extend the event examples.
image

I assume something like this:

{
    "arguments": {
        "title": "Titel of DEMO ToDo"
    },
    "identity": null,
    "source": null,
    "request": {
        "headers": {
            "x-forwarded-for": "1.2.3.4, 5.6.7.8",
            "accept-encoding": "gzip, deflate, br",
            "cloudfront-viewer-country": "NL",
            "cloudfront-is-tablet-viewer": "false",
            "referer": "https://eu-west-1.console.aws.amazon.com/appsync/home?region=eu-west-1",
            "via": "2.0 9fce949f3749407c8e6a75087e168b47.cloudfront.net (CloudFront)",
            "cloudfront-forwarded-proto": "https",
            "origin": "https://eu-west-1.console.aws.amazon.com",
            "x-api-key": "da1-c33ullkbkze3jg5hf5ddgcs4fq",
            "content-type": "application/json",
            "x-amzn-trace-id": "Root=1-606eb2f2-1babc433453a332c43fb4494",
            "x-amz-cf-id": "SJw16ZOPuMZMINx5Xcxa9pB84oMPSGCzNOfrbJLvd80sPa0waCXzYQ==",
            "content-length": "114",
            "x-amz-user-agent": "AWS-Console-AppSync/",
            "x-forwarded-proto": "https",
            "host": "ldcvmkdnd5az3lm3gnf5ixvcyy.appsync-api.eu-west-1.amazonaws.com",
            "accept-language": "en-US,en;q=0.5",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0",
            "cloudfront-is-desktop-viewer": "true",
            "cloudfront-is-mobile-viewer": "false",
            "accept": "*/*",
            "x-forwarded-port": "443",
            "cloudfront-is-smarttv-viewer": "false"
        }
    },
    "prev": null,
    "info": {
        "parentTypeName": "Mutation",
        "selectionSetList": [
            "title",
            "id"
        ],
        "selectionSetGraphQL": "{\n  title\n  id\n}",
        "fieldName": "createTodo",
        "variables": {}
    },
    "stash": {}
}

@heitorlessa
Copy link
Contributor Author

heitorlessa commented Feb 28, 2023 via email

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 1, 2023
@heitorlessa
Copy link
Contributor Author

Now it's ready @tb102122 - Added a sample createTodo JSON event (real event), grouped all events under a new tab Sample events to ease discoverability and improve reading experience.

Also fixed unrelated issues as I was reproducing it with our sample infrastructure.

image

@heitorlessa
Copy link
Contributor Author

I'll assume the 🎉 reaction as approval ;) Since @leandrodamascena and @rubenfonseca are unavailable this week, I'm merging and rebuilding the latest doc to prevent any confusion until our next release.

Thanks a lot @tb102122 once again.

@heitorlessa heitorlessa changed the title docs(appsync): add mutation example docs(appsync): add mutation example and infrastructure fix Mar 1, 2023
@heitorlessa heitorlessa merged commit 80befe9 into aws-powertools:develop Mar 1, 2023
@heitorlessa heitorlessa deleted the docs/event-handler-appsync-mutation branch March 1, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: create Example for usage of AppSync for Mutations
2 participants