DEV Community

Yinlin Chen
Yinlin Chen

Posted on

5 3

AWS Amplify AppSync GraphQL custom resolver examples

AWS Amplify is great! It handles AppSync backend with AWS resources, like DynamoDB, ElasticSearch, etc for you. However, sometimes these default generated GraphQL schema and resolvers are not fulfill our business need. We create an Amplify Appsync GraphQL GitHub repo to document some of the custom AppSync Resolver.

There are three steps to create your custom resolvers using AWS Amplify CLI

  • Step1: Add custom type to the schema

    • Add custom Query, Mutation or Subscription type to your schema.
  • Step2: Create custom resolver template

    • Request and response template should be located in <project-root>/amplify/backend/api/<api-name>/resolvers folder.
    • Graphql Transformer follows <TypeName>.<FieldName>.<req/res>.vlt as convention to name the resolvers.
      • Request template: Query.myCustomQuery.req.vtl
      • Response template: Query.myCustomQuery.res.vtl
  • Step3: Add resolvers resource by creating a custom stack

    • By default, there is a file called CustomResources.json in <project-root>/amplify/backend/api/<api-name>/stacks directory of your API.
    • Example: CustomResource.json

Currently, we provides these examples:

  1. Basic models
  2. Enable basic search
  3. Fuzzy search
  4. Query for Interface type
  5. Search with AND/OR operations
  6. Multi-fields search
  7. Custom searchable input
  8. Query for Union type

You can deploy the entire example app here:
amplifybutton

We hopes these examples help! Please feel free to contribute more custom examples to us and make it better!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay