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

Gen 2 codegen generates wrong getters for "id" field in a model #790

Open
1 of 14 tasks
salihgueler opened this issue Feb 26, 2024 · 3 comments
Open
1 of 14 tasks

Gen 2 codegen generates wrong getters for "id" field in a model #790

salihgueler opened this issue Feb 26, 2024 · 3 comments
Labels
bug Something isn't working Gen 2 transferred Issue has been transferred from another Amplify repository

Comments

@salihgueler
Copy link
Member

Description

In a scenario that we have a CDK backend with a new L3 construct, the new Amplify codegen does not generate the "id" property properly from a schema file. When the id is an integer it assumes it is a String and the generated code is broken.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Create a schema and a model with a field called "id" with type int.
  2. Run the following command with proper fields
npx @aws-amplify/cli codegen models   --model-schema <schema-path>   --target flutter   --output-dir ./lib/models
  1. Check the generated file.

Following lines will fail:

@Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.')
@override
String getId() => id;
return ModelName._internal(
  id: id == null ? amplify_core.UUID.getUUID() : id,
ModelName.fromJson(Map<String, dynamic> json)  
  : id = (json['id'] as num?)?.toInt(),

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.16.9

Amplify Flutter Version

1.6.1

Deployment Method

Amplify CLI

Schema

type Puzzle
  @model
  @auth(
    rules: [{ allow: public, operations: [read, update] }, { allow: owner }]
  ) {
  id: Int! @primaryKey
  question: String!
  solution: Solution @hasOne(references: ["puzzleId"])
  submissions: [Submission!]! @hasMany(references: ["puzzleId"])
  votes: [String!]!
  createdAt: AWSDate @refersTo(name: "created_at")
}

type Solution
  @model
  @auth(rules: [{ allow: public, operations: [read] }, { allow: owner }]) {
  id: Int! @primaryKey
  solutionText: String! @refersTo(name: "solution_text")
  language: String!
  createdAt: AWSDate @refersTo(name: "created_at")
  puzzleId: String @refersTo(name: "puzzle_id")
}

type Submission
  @model
  @auth(
    rules: [{ allow: public, operations: [read, update] }, { allow: owner }]
  ) {
  id: Int! @primaryKey
  votes: [String!]!
  createdAt: AWSDate @refersTo(name: "created_at")
  puzzleId: String! @refersTo(name: "puzzle_id")
}
@Equartey Equartey transferred this issue from aws-amplify/amplify-flutter Feb 27, 2024
@Equartey
Copy link
Contributor

Hey @salihgueler, thanks for finding this. I've transferred your issue to the Amplify CLI team for better support.

@ykethan
Copy link

ykethan commented Feb 27, 2024

apologies on this additional transfer, the API repository maybe the appropriate place for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Feb 27, 2024
@ykethan ykethan added the transferred Issue has been transferred from another Amplify repository label Feb 27, 2024
@dpilch dpilch transferred this issue from aws-amplify/amplify-category-api Feb 27, 2024
@dpilch dpilch added the bug Something isn't working label Feb 27, 2024
@dpilch
Copy link
Contributor

dpilch commented Feb 27, 2024

I was able to reproduce this issue and I marking this as a bug.

@dpilch dpilch added the Gen 2 label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gen 2 transferred Issue has been transferred from another Amplify repository
Projects
None yet
Development

No branches or pull requests

4 participants