#✅ - Amplify @belongsTo with @auth causes failure

1 messages · Page 1 of 1 (latest)

lapis ferry
#

I am currently experiencing an issue with @belongsTo in connection with @auth when more than one sortKey is inside of the parent element.

The following error comes up when I try to amplify push the schema:

🛑 Invalid @belongsTo on Comments:todo. Provided fields do not match the size of primary key(s) for Todos

Below schema should reproduce the error:

type Todos @model @auth(rules: [{ allow: public }]) {
  id: ID!
  createdAt: String
  number: Int
  title: String
  description: String
  comments: [Comments] @hasMany(indexName: "byComments", fields: ["id"])
  baseType: String
    @index(
      name: "byNumber"
      queryField: "todosByNumber"
      sortKeyFields: ["number"]
    )
    @index(
      name: "byTitle"
      queryField: "todosByTitle"
      sortKeyFields: ["title"]
    )
    @index(
      name: "byDescription"
      queryField: "todosByDescription"
      sortKeyFields: ["description"]
    )
}

type Comments @model @auth(rules: [{ allow: public }]) {
  id: ID!
  todosID: ID! @index(name: "byComments")
  todo: Todos @belongsTo(fields: ["todosID"])
  createdAt: String
  firstName: String
  lastName: String
  messageID: ID @index(name: "commentsByMessages")
  message: Messages @belongsTo(fields: "messageID")
}

type Messages @model @auth(rules: [{ allow: public }]) {
  id: ID!
  title: String
  content: String
  comments: [Comments] @hasMany(indexName: "byComments", fields: ["id"])
}

Does anyone have a solution on how to setup @belongsTo and @auth correctly or is this a bug?

Looking forward to your help!🙂

lapis ferry
#

Does anyone have an idea about that? Still struggeling...

I think it might has something to do with having two @belongsTo inside of the Comments Table...

lapis ferry
#

The problem was that I forget the brackets inside of one @belongTo like so: @belongsTo(fields: "messageID")

After I changed it to @belongsTo(fields: ["messageId"]), I was able to push everything correctly.

harsh mesaBOT
#

✅ - Amplify @belongsTo with @auth causes failure