You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!}
run amplify codegen models
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
The text was updated successfully, but these errors were encountered:
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
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
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:With the old Transformer, the code generation would hide the
teamID
field, so that I would get something like thisHowever, after we migrated to Transformer v2, the codegen no longer hides the
teamID
so I get something like thisThe 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 onteamID
Why does it not hide it? Given that the
team
is non-optional andteamID
is associated withTeam.keys.id
, I don't see a reason to keepteamID
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 perfectlyI 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
run
amplify codegen models
See generated models
Expected behavior
teamID
field of Project is hiddenAmplify 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
The text was updated successfully, but these errors were encountered: