0

I'm implementing substacks in my AWS serverless app, I would like to know if there is a way to extract the from my template of appsync resolvers the content that is in the field RequestMappingTemplate, and my ResponseMappingTemplate

currently the resolver resource looks like this

AppSyncResolver:
    Type: "AWS::AppSync::Resolver"
    Properties:
      TypeName: "Query"
      FieldName: "my_resolver"
      DataSourceName: !GetAtt AppSyncDataSource.Name
      RequestMappingTemplate: |
        #set($SCHEMA = $ctx.args.schema)
        #set($limit = $ctx.args.limit)
        #set($table = ".customers")
        #set($customers = $SCHEMA$table_ordendscto_lote)

        {
            "version": "2018-05-29",
            "statements": [
            "SELECT * FROM $customers LIMIT $limit ;"
            ]
        }
      ResponseMappingTemplate: |
        ## Raise a GraphQL field error in case of a datasource invocation error
        #if($ctx.error)
            $utils.error($ctx.error.message, $ctx.error.type)
        #end

        $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
      Kind: "UNIT"
      ApiId: !GetAtt AppSyncGraphQLApi.ApiId

and I wanted something like this

AppSyncResolver:
    Type: "AWS::AppSync::Resolver"
    Properties:
      TypeName: "Query"
      FieldName: "my_resolver"
      DataSourceName: !GetAtt AppSyncDataSource.Name
      RequestMappingTemplate: src/resolvers/my-resolver
      ResponseMappingTemplate: src/resolvers/my-resolver-response 
      Kind: "UNIT"
      ApiId: !GetAtt AppSyncGraphQLApi.ApiId

is it possible?

WhiteAB
  • 162
  • 3
  • 11

1 Answers1

0

That is definitely possible. I've done it in yml but you should be able to convert it easily. I'm using serverless-appsync-plugin v2.

appSync:
    name: myApi
    schema: './utils/graphql/schema.graphql'
    resolvers:
      Query.getPets:
        functions:
          - dataSource: petsAuroraDb
            request: './utils/graphql/mapping-templates/pets/list-pets-request.vtl'
            response: './utils/graphql/mapping-templates/pets/list-pets-response.vtl'
hunain60
  • 188
  • 3
  • 6