amplify-codegen
amplify-codegen copied to clipboard
Request to support Interfaces for Flutter Codegen in order to utilize Generics for Models
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 extends ExampleInterface>(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