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

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

Open
2 tasks
arthurshir opened this issue May 14, 2023 · 0 comments
Labels
feature-request New feature or request p4 pending-review Pending review from core team

Comments

@arthurshir
Copy link

arthurshir commented May 14, 2023

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 flutter/flutter#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
@arthurshir arthurshir added the pending-triage Issues that need further discussion to determine label May 14, 2023
@AnilMaktala AnilMaktala added the pending-review Pending review from core team label May 17, 2023
@alharris-at alharris-at added the feature-request New feature or request label May 25, 2023
@alharris-at alharris-at transferred this issue from aws-amplify/amplify-category-api May 25, 2023
@alharris-at alharris-at added the p4 label May 25, 2023
@dpilch dpilch removed the pending-triage Issues that need further discussion to determine label Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request p4 pending-review Pending review from core team
Projects
None yet
Development

No branches or pull requests

4 participants