sid88in / serverless-appsync-plugin

serverless plugin for appsync
MIT License
951 stars 189 forks source link

Allow user to specify logical ID for the GraphQLApi resource #477

Open theburningmonk opened 2 years ago

theburningmonk commented 2 years ago

At the moment, the logical ID for the AWS::AppSync::GraphQLApi resource is generated based on the API name, it'll be great to have the option to specify the logical ID ourselves.

Otherwise, it makes it painfully hard to reference the API resource in some cases. For example, I include the stage name in the API name because we use temporary stacks for each developer, and for feature work, but all these stacks are deployed in the same dev account.

You can try to add ${self:provider.stage} in places where you need to reference the GraphQL API resource, but there are plenty of places where the Serverless framework doesn't transform these, e.g. when used in environment variables or stack outputs.

It'll be great to be able to do something like this:

myApi:
  name: myapi-${self:provider.stage}
  logicalId: MyGraphQLApi
  ...
bboure commented 2 years ago

Are you using multiple APIs in the same stack, or passing the appSync configuration as an array (even with just one item)?

The logical ID should be GraphQlApi for single API configs (without prefix), when custom.appSync is an object. The Api name is only added in the case of multiple APIs (array of objects).

Obviously, changing that now will force the AWS::AppSync::GraphQLApi resource to be recreated. This might be a problem if you already went to production (It would also be the case with custom names, though).

Side note: In v2, variables should make this less painful.

We could do one of two things:

theburningmonk commented 2 years ago

V2's variables looks great, is it easy to backport to v1? and is it supported by Serverless framework v2?

bboure commented 2 years ago

is it easy to backport to v1?

it should be easy enough.

and is it supported by Serverless framework v2?

I need to double-check that, but I think it is.