aws-amplify / aws-amplify/amplify-cli

(gen2-migration) `generate` command should handle api overrides

Open
#14,642 0 comments 0 reactions 0 assignees View on GitHub
gen2-migration
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### Is this feature request related to a new or existing Amplify category?

_No response_

### Is this related to another service?

_No response_

### Describe the feature you'd like to request

In Gen1, customers can override the built-in api resources by running `amplify override api`. This creates an `overrides.ts` file where customers can override resource properties using the CDK. For example

```ts
import { AmplifyApiGraphQlResourceStackTemplate, AmplifyProjectInfo } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyApiGraphQlResourceStackTemplate, amplifyProjectInfo: AmplifyProjectInfo) {
resources.api.GraphQLAPI.queryDepthLimit = 5;
}
```

Our code-generation should take this `override.ts` file into account and produce the equivalent Gen2 code.

### Describe the solution you'd like

Ideally, we would transform the `override.ts` to look like this:

```ts
export function override(backend: Backend, amplifyProjectInfo: { envName: string, projectName: string }) {
(backend.data.resources.graphqlApi.node.defaultChild as CfnGraphQLApi).queryDepthLimit = 5;
}
```

And then invoke this function from `backend.ts`:

```ts
import { override as overrideApi } from './api/override.ts`

const branchName = process.env.AWS_BRANCH ?? 'sandbox';
const backend = defineBackend({
...,
data,
});

overrideApi(backend, { envName: branchName, projectName: '' });
```

### Describe alternatives you've considered

None

### Additional context

https://github.com/aws-amplify/amplify-cli/blob/664dabc422d81153a3193996a7324d27829ef3b9/packages/amplify-cli-extensibility-helper/src/types/api/amplify-api-resource-stack-types.ts#L16-L22

Note that its also possible to override REST APIs:

https://github.com/aws-amplify/amplify-cli/blob/664dabc422d81153a3193996a7324d27829ef3b9/packages/amplify-cli-extensibility-helper/src/types/api/types.ts#L20-L26

### Is this something that you'd be interested in working on?

- [ ] 👋 I may be able to implement this feature request

### Would this feature include a breaking change?

- [ ] ⚠️ This feature might incur a breaking change

Contributor guide

Open the contributing guide

Research direction

Start with the linked type definitions in amplify-cli-extensibility-helper and trace the generate command's code-generation entry point. Compare the requested api/override.ts and backend.ts flow, including both GraphQL and REST overrides; done means Gen1 override.ts files are transformed into equivalent Gen2 code and invoked from backend.ts.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, typescript
Domain
backend-api-design, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.