amplify-codegen
amplify-codegen copied to clipboard
Custom primary key @primaryKey doesn’t work with @auth
Description
I have two parent / child tables, and the parent table has custom primary key:
type Book @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
id: ID! @primaryKey(sortKeyFields: ["title", "description"])
title: String!
description: String!
writers: [Writer] @hasMany(indexName: "byBook", fields: ["id"])
pOwner: String!
}
type Writer @model {
id: ID!
fname: String!
lname: String!
bookID: ID! @index(name: "byBook", sortKeyFields: ["id"])
book: Book! @belongsTo(fields: ["bookID"])
pOwner: String!
}
When I add the same @auth to the child, I get the following error on attempt to generate the model with 'amplify codegen models':
InvalidDirectiveError: Invalid @belongsTo on Writer:book. Provided fields do not match the size of primary key(s) for Book
Below are the models that cause this error:
type Book @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
id: ID! @primaryKey(sortKeyFields: ["title", "description"])
title: String!
description: String!
writers: [Writer] @hasMany(indexName: "byBook", fields: ["id"])
pOwner: String!
}
type Writer @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
id: ID!
fname: String!
lname: String!
bookID: ID! @index(name: "byBook", sortKeyFields: ["id"])
book: Book! @belongsTo(fields: ["bookID"])
pOwner: String!
}
Categories
- [ ] Analytics
- [ ] API (REST)
- [ ] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [X] DataStore
- [ ] Notifications (Push)
- [ ] Storage
Steps to Reproduce
No response
Screenshots
No response
Platforms
- [ ] iOS
- [ ] Android
- [ ] Web
- [X] macOS
- [ ] Windows
- [ ] Linux
Flutter Version
3.13.5
Amplify Flutter Version
1.5.0
Deployment Method
Amplify CLI
Schema
No response
Hello @stephenjen - I was able to reproduce this issue. I am going to transfer this issue to our code gen repo.
@Jordan-Nelson Thanks for pushing this forward