aws-amplify / aws-amplify/amplify-codegen

Request to support Interfaces for Flutter Codegen in order to utilize Generics for Models

Open
#602 0 comments 0 reactions 0 assignees View on GitHub
feature-request p4 pending-review
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

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

Requesting that the flutter codegen (`amplify codegen models`) also generates and utilizes interface model files:

```
interface ExampleInterface {
customField: String!
}

type ExampleModelA implements ExampleInterface @model {
id: ID!
customField: String!
}

type ExampleModelB implements ExampleInterface @model {
id: ID!
customField: String!
}
```

### Describe the solution you'd like

Codegen creates model interface files and model files which reference the interfaces accordingly

```
abstract class ExampleInterface extends Model {
String customField() {
throw UnimplementedError('getId() has not been implemented on ExampeInterface.');
}
}
```

```
abstract class ExampleModelA extends ExampleInterface {
...
}
```

```
abstract class ExampleModelB extends ExampleInterface {
...
}
```

### Describe alternatives you've considered

Could manually implement ExampleInterface, and then alter the generated Model files. But prefer not to alter generated files.

Reflection is not an option as Flutter does not allow it https://github.com/flutter/flutter/issues/1150

### Additional context

This would allow us as developers to cleanly utilize generics when operating on the generated Models.

Example:
```
String retrieveCustomField(T model) {
return model.customField;
}
```

Thank you for reading!

### 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

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.