serverless-appsync-plugin icon indicating copy to clipboard operation
serverless-appsync-plugin copied to clipboard

Multiple GraphQlApi / GraphQlUrl reference

Open NevRA opened this issue 2 years ago • 2 comments

Hey For the single API I can reference it with

ENDPOINT: !GetAtt 
  - GraphQlApi
  - GraphQLUrl

For the multiple APIs we could use https://github.com/sid88in/serverless-appsync-plugin/issues/275 But I can't understand how to make it work without hardcode and with stages support

E.g. I have API with a name ${self:provider.stackName}-public (project-stage-rc-2-public), it will create a resource with logical id Projectstagerc2publicGraphQlApi (without dashes)

How to reference it and have the ability to work with multiple staging environments (without hardcode rc-2 in the YAML file)?

Thanks!

NevRA avatar Jan 24 '22 14:01 NevRA

@NevRA

I understand this is an issue. I do not see an easy fix to that now.

A workaround would be to use js macros to achieve that.

Something like this:

ENDPOINT: ${file(templates/macros.js):getPulblicAppSyncEndpoint()}

in templates/macros.js

const getStage = (serverless) => {
  const { stage } = serverless.options
    ? serverless.options
    : serverless.service.provider;

  return stage;
};

module.exports = {
  getPulblicAppSyncEndpoint(serverless) {
	const name = removeDashes(getStage(serverless)) + 'publicGraphQlApi';
    return { '!GetAtt', [ name, 'GraphQLUrl' ] };
  },
};

On.a side note, version 2 introduces variables which should simplify accessing id, ARN and URL of the API.

However, it also drops support for multiple APIs, which I understand you use.

I'd like to hear your feedback and use case about why using more than one API in a single stack. Feel free to contact me about it

bboure avatar Feb 17 '22 19:02 bboure

@bboure Thank you for the reply! Looks promising The problem is that I have already renamed all stagings without the dash :) Thanks for mentioning v2; I didn't see that. I will write to you about multi API and think about how best to do it because it looks like this multi-API approach is a path to nowhere.

NevRA avatar Feb 22 '22 20:02 NevRA