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

feat/Support-apiId(Multiple-cloudformation-stacks) #3

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

plezan
Copy link
Owner

@plezan plezan commented Nov 15, 2024

What are the main changes ?

  • Added apiId to appsync config to allow adding resources to an existing appsync api
  • Handle specific config for existing appsync apis
  • Added support for existing data sources
  • Use path relative to serverless.yml when using compose

What else changed in the project ?

  • tsconfig now targets es2018
  • tsconfig now transpiles to an ESM (previously commonjs)
  • Moved validation definition and properties to separate files
  • removed a test on a feature that do not exists anymore
  • Changed how some errors are handled
  • Some methods of the Naming class are now static
  • Changed how the api-keys and graphql endpoints are displayed in the console (now also shown in sls v4)

Copy link
Owner Author

@plezan plezan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments from sid88in#597 (comment)

Thank you for your patience, I had a look at the PR. It looks good but I left some comments for improvements. Especially on typing and validation.

A few more thoughts/questions:

  • should we allow exporting/importing data sources from other stacks?
    e.g. I create my data sources in a main stack (could be a single-table DynamoDB), and then I reference it from resolvers in other stacks.
    Right now, we use an intrinsic function to get the name, which will not work if it's in a different stack. I assume passing the value/name as-is should work.

The same goes for pipeline functions.

  • We also need to update the migration guide and remove the reference that using existing APIs is not supported since this is being re-introduced.
  • I'd really like to have a full guide on what this is for and when and how to use it.

Thank you all for the effort!

src/validation.ts Outdated Show resolved Hide resolved
src/types/plugin.ts Outdated Show resolved Hide resolved
}

hasPipelineFunction(name: string) {
return name in this.config.pipelineFunctions;
return name in (this.config.pipelineFunctions || {});
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/sid88in/serverless-appsync-plugin/pull/597/files#r1223313143

I understand why you made those optional, but I'd rather keep them as required. If you look here, those are actually already optional from a config point of view. Then, getAppSyncConfig() makes sure to fill them with empty {} if needed for when it's injected in the compiler.

endpointResource.Properties,
this.compileAuthenticationProvider(this.config.authentication),
);
if (this.config.authentication) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/sid88in/serverless-appsync-plugin/pull/597/files#r1223301264

authentication is always required in this context. There is probably some TS magic to do (i.e. a type union type or something)

src/resources/Api.ts Outdated Show resolved Hide resolved
src/index.ts Outdated
@@ -410,6 +421,10 @@ class ServerlessAppsyncPlugin {
async getIntrospection() {
const apiId = await this.getApiId();

if (typeof apiId !== 'string') {
return;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/sid88in/serverless-appsync-plugin/pull/597/files#r1223290575

just returning is probably not good enough. I would show a warning.

In fact I would probably not allow calling any of these commands (assoc domain, etc) from a "child" service stack.

Please call this command from the service where the AppSync API is created.

src/index.ts Outdated
@@ -377,6 +384,10 @@ class ServerlessAppsyncPlugin {
async gatherData() {
const apiId = await this.getApiId();

if (typeof apiId !== 'string') {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof apiId !== 'string') {
if (!apiId) {

https://github.com/sid88in/serverless-appsync-plugin/pull/597/files#r1223292215

if for some reason, apiId is an empty string, it probably does not make sense to continue either.

> Note: you should never specify this parameter if you're managing your AppSync through this plugin since it results in removing your API.

### Schema
After specifying this parameter, you need to manually keep your schema up to date or from the main stack where your root AppSync API is defined. The plugin is not taking into account schema property due to AppSync limitation and inability to merge schemas across multiple stacks
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/sid88in/serverless-appsync-plugin/pull/597/files#r1223263789

This whole section is confusing and probably not necessary.

Instead, we should add clear guidelines on how and why you should use the apiId parameters. A bit like described here for API Gateway.

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

Successfully merging this pull request may close these issues.

2 participants