0

I'm doing an application in AppSync and I'm trying to create with Cloud Formation one schema where one mutation is linked to one resolver and a second mutation is linked to a second resolver. But it always give me an error saying that I can't attach two mutations in a single request.

If I try to do in console, I can attach two mutations in two resolvers.

Someone has any idea how I can provision everything in Cloud Formation ?

[EDIT] I added this resolver to the template

AppSyncMutationResolverOne:
   Type: "AWS::AppSync::Resolver"
   DependsOn: AppSyncSchema
   Properties:
     ApiId: !Ref GraphApiId
     TypeName: Mutation
     FieldName: exampleOne
     DataSourceName: !GetAtt DataSourceOne.example
     RequestMappingTemplate: !Ref RequestMappingTemplate
     ResponseMappingTemplate: !Ref ResponseRequestMappingTemplate

But when I try to add a second Mutation Resolver, pretty similar with this first one

 AppSyncMutationResolverTwo:
    Type: "AWS::AppSync::Resolver"
    DependsOn: AppSyncSchema
    Properties:
      ApiId: !Ref GraphApiId
      TypeName: Mutation
      FieldName: exampleTwo
      DataSourceName: !GetAtt DataSourceTwo.example
      RequestMappingTemplate: !Ref RequestMappingTemplate
      ResponseMappingTemplate: !Ref ResponseRequestMappingTemplate

It returns me an error saying that I can't add two mutation resolvers to the same API

This is my RequestMappingTemplate that is used for both mutations:

    {
       "version": "2017-02-28",
       "operation": "Invoke",
       "payload": { 
             "arguments": $utils.toJson($context.arguments)
          }
    }
Thauany Moedano
  • 551
  • 2
  • 8
  • 21

1 Answers1

1

Your Cloudformation template seems fine to me, but, depending on which type of DataSource you are using, you define the name of the field on the RequestMappingTemplate too (i.e. Lambda data source) as explained here, like this:

{
    "version": "2018-05-29",
    "operation": "Invoke",
    "payload": {
        "field": "getPost",
        "postId": "1",
    }
}

So, based on that, it seems that you're using the same RequestMappingTemplate for the two mutation resolvers. Check that the two Request Mappings correspond to the same FieldName defined on the Cloudformation template for each resolver. That could be the reason why it works on the console but not through Cloudformation.

Douglas Figueroa
  • 675
  • 6
  • 17