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

codegen of @hasOne doesn't hide query fields #1623

Closed
kallyaleksiev opened this issue Feb 7, 2022 · 2 comments
Closed

codegen of @hasOne doesn't hide query fields #1623

kallyaleksiev opened this issue Feb 7, 2022 · 2 comments
Assignees
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@kallyaleksiev
Copy link

kallyaleksiev commented Feb 7, 2022

Describe the bug

Codegen of @hasOne for swift with specified fields does not hide those fields.

I have a slight issue with codegen for swift with a schema like for example the following:

type Project @model {
  id: ID!
  
  teamID: ID! @index(name: "byTeamID", queryField: "projectByTeamID")
  team: Team! @hasOne(fields: ["teamID"])
}

type Team @model {
  id: ID!
}

With the old Transformer, the code generation would hide the teamID field, so that I would get something like this

public struct Project: Model {
  public let id: String
  public var team: Team

...

model.fields(
      .id(),
      .belongsTo(project.team, is: .required, ofType: Team.self, targetName: "teamID"))

However, after we migrated to Transformer v2, the codegen no longer hides the teamID so I get something like this

public struct Project: Model {
  public let id: String
  public var teamID: String
  public var team: Team
...
model.fields(
      .id(),
      .field(project.teamID, is: .required, ofType: .string),
      .hasOne(project.team, is: .required, ofType: Team.self, associatedWith: Team.keys.id, targetName: "teamID"),
  • The behaviour of codegen is the same even if I don't have an index on teamID - the only way to hide it is to not specify fields but the issue is we need that secondaryIndex on teamID

  • Why does it not hide it? Given that the team is non-optional and teamID is associated with Team.keys.id, I don't see a reason to keep teamID

  • It was hiding it before the migration and

  • If I manually edit the generated swift model files to remove teamID and to replace the .hasOne association with .belongsTo everything works perfectly

I tried various ways to generate the schema and all that but they all end up the same way.

So is there another "better" way to generate that relationship along with the index so that teamID gets hidden?

Steps To Reproduce

1. Create a new project with api

2. Create a schema like this 

type Project @model {
  id: ID!
  
  teamID: ID! @index(name: "byTeamID", queryField: "projectByTeamID")
  team: Team! @hasOne(fields: ["teamID"])
}

type Team @model {
  id: ID!
}
  1. run amplify codegen models

  2. See generated models

Expected behavior

teamID field of Project is hidden

Amplify Framework Version

1.14.0

Amplify Categories

API

Dependency manager

Cocoapods

Swift version

5.5.2

CLI version

7.6.15

Xcode version

13.2.1

Relevant log output

No response

Is this a regression?

Yes

Regression additional context

No response

Device

iPhone

iOS Version

≥ iOS 13

Specific to simulators

No response

Additional context

No response

@lawmicha lawmicha added bug Something isn't working datastore Issues related to the DataStore category pending-triage Issue is pending triage labels Feb 14, 2022
@kallyaleksiev
Copy link
Author

was wondering if there are any updates or plans on this? I can see the draft pr, but apart from that is it known whether the issue will be addressed anytime soon? as you probably already know, the issue is still there for cli version 7.6.25

@lawmicha lawmicha added the p3 label Jun 8, 2022
@chrisbonifacio chrisbonifacio removed the pending-triage Issue is pending triage label Jun 17, 2022
@lawmicha
Copy link
Contributor

I believe with the latest CLI 12+ and the lazy loading capabilities enabled, described in https://docs.amplify.aws/cli/migration/lazy-load-custom-selection-set/ we have fixed this, ie. the teamId in your example should be hidden and you can lazily load the team from the project. Lazy loading was released sometime in February 2023. Please let us know if you are still blocked on your development and we can further help

@lawmicha lawmicha added the pending-community-response Issue is pending response from the issue requestor label Aug 10, 2023
@ruisebas ruisebas added the closing soon This issue will be closed in 7 days unless further comments are made. label Aug 25, 2023
@ruisebas ruisebas closed this as completed Sep 5, 2023
@github-actions github-actions bot removed pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests

4 participants