aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

How do I create a simple GraphQL query resolver using VTL in Amplify #2644

Closed jon144 closed 4 years ago

jon144 commented 4 years ago

Which Category is your question related to? API, GraphQL

What AWS Services are you utilizing? AWS AppSync

Provide additional details e.g. code snippets Using Amplify CLI, I want to create a custom resolver for the GraphQL query below. It seems like I should be able to do it only using VTL. There is no need to call a Lambda function or use a data source like DynamoDB.

type Query { supportedVersion: String }

The function will return a simple string like "4.3.7"

I have added 2 VTL files to .\backend\api\\resolvers

Query.supportedVersion.req.vtl has the following content { "payload": "4.3.7" }

Query.version.res.vtl has the following content $util.toJson($context.result) or "4.3.7"

After I run 'Amplify push', and look in AppSync, the resolver is not connected to the query. I feel that I am missing a step that connects the query to the resolver.

I have created several custom Lambda node.js resolvers that utilize the 'Amplify add function' process. In this case, I don't want the overhead of Lambda.

kaustavghosh06 commented 4 years ago

@jon144 Yes, you're missing a step here to tie in the resolvers with the query. Please take a look at https://aws-amplify.github.io/docs/cli-toolchain/graphql#custom-resolvers

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.