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

Overwrite data source of Amplify-generated resolvers #69

Open
zirkelc opened this issue Mar 29, 2022 · 4 comments
Open

Overwrite data source of Amplify-generated resolvers #69

zirkelc opened this issue Mar 29, 2022 · 4 comments
Labels

Comments

@zirkelc
Copy link

zirkelc commented Mar 29, 2022

I want extend the the Amplify generated resolver Mutation.createOrgnaization for the model Organization with some custom logic. I followed the official documentation and added two resolver templates Mutation.createOrganization.postUpdate.1.req.vtl and Mutation.createOrganization.postUpdate.1.res.vtl. These resolvers get picked up by Amplify and added into the final pipeline resolver as postUpdate resolver.

The problem is that the postUpdate resolver is created with data source NONE. However, I want to invoke a Lambda function so I need to change the data source to another value. I can change the data source via the AppSync Console, but every push overwrites it again. I tried to use the CustomResources.json file to change the definition of postUpdate resolver, but instead it creates a second resolver with the same name.

Is there any way to overwrite the data source of these resolver templates?

CustomResources.json

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "An auto-generated nested stack.",
  "Metadata": {},
  "Parameters": {
    "AppSyncApiId": {
      "Type": "String",
      "Description": "The id of the AppSync API associated with this project."
    },
    "AppSyncApiName": {
      "Type": "String",
      "Description": "The name of the AppSync API",
      "Default": "AppSyncSimpleTransform"
    },
    "env": {
      "Type": "String",
      "Description": "The environment name. e.g. Dev, Test, or Production",
      "Default": "NONE"
    },
    "S3DeploymentBucket": {
      "Type": "String",
      "Description": "The S3 bucket containing all deployment assets for the project."
    },
    "S3DeploymentRootKey": {
      "Type": "String",
      "Description": "An S3 key relative to the S3DeploymentBucket that points to the root\nof the deployment directory."
    }
  },
  "Resources": {
    "EmptyResource": {
      "Type": "Custom::EmptyResource",
      "Condition": "AlwaysFalse"
    },
    "MutationcreateOrganizationpostUpdate0FunctionMutationcreateOrganizationpostUpdate0FunctionAppSyncFunctionB7AE84E3": {
      "Type": "AWS::AppSync::FunctionConfiguration",
      "Properties": {
        "ApiId": {
          "Ref": "AppSyncApiId"
        },
        "DataSourceName": "NebulaApiResolverLambdaDataSource",
        "FunctionVersion": "2018-05-29",
        "Name": "MutationcreateOrganizationpostUpdate0Function",
        "RequestMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Mutation.createOrganization.postUpdate.1.req.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        },
        "ResponseMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Mutation.createOrganization.postUpdate.1.res.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        }
      }
    }
  },
  "Conditions": {
    "HasEnvironmentParameter": {
      "Fn::Not": [
        {
          "Fn::Equals": [
            {
              "Ref": "env"
            },
            "NONE"
          ]
        }
      ]
    },
    "AlwaysFalse": {
      "Fn::Equals": [
        "true",
        "false"
      ]
    }
  },
  "Outputs": {
    "EmptyOutput": {
      "Description": "An empty output. You may delete this if you have at least one resource above.",
      "Value": ""
    }
  }
}

Which Category is your question related to?
API (GraphQL) with GraphQL Transformer v2

Amplify CLI Version
7.6.22
You can use amplify -v to check the amplify cli version on your system

What AWS Services are you utilizing?
AWS AppSync

Provide additional details e.g. code snippets. Be sure to remove any sensitive data.

@zirkelc zirkelc added the question Further information is requested label Mar 29, 2022
@edwardfoyle
Copy link
Member

Hi @zirkelc this currently isn't possible but could be a feature we would implement. Can you describe more about your use case for changing the data source to lambda?

@edwardfoyle edwardfoyle added feature-request New feature or request graphql-transformer-v2 and removed question Further information is requested labels Apr 5, 2022
@zirkelc
Copy link
Author

zirkelc commented Apr 6, 2022

Hi @edwardfoyle

for a detailed use case I will link you to my comment on another issue: #430

AppSync Pipeline resolvers and the ability to override and extend resolvers is great idea in general. However, due to the fact that an overriden resolver is always being generated with DataSource=NONE make them not really usable. That limits the possible use cases to only static use cases where it is enough to do some filtering via VTL.

I created this issue hoping that there are any workarounds to change the DataSource on the generated CloudFormation template somehow.

@alharris-at alharris-at transferred this issue from aws-amplify/amplify-cli May 17, 2022
@gxxcastillo
Copy link

Are there any updates wrt the timeline for this feature? I filed a related issue and was referred to this one. The solution proposed in #430, "make the top line of the resolver file define the data source" seems reasonable.

@gxxcastillo
Copy link

The solution proposed here aws-amplify/amplify-cli#9623 (comment), which involves using override.ts to manually set the value of models.{ModelName}.appsyncFunctions.{ResolverName}.dataSourceName solved this for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants