amplify-swift: Incorrect codegen error - DataStore does not support 1 to 1 connection with both sides of connection as optional field

Describe the bug Codegen produces the following error even though both sides of the connection are actually non-optional: “DataStore does not support 1 to 1 connection with both sides of connection as optional field”

To Reproduce

  1. Create the schema below
  2. Add api, push, then run amplify codegen models
  3. See error

Expected behavior Generates the code

Environment:

  • Amplify Framework Version: 4.21.0
  • Dependency Manager: Cocoapods
  • Swift Version : 5.0

Device Information:

  • Device: Simulator
  • iOS Version: iOS 13.5

Additional context Schema:

type PhoneCall @model {
  id: ID!
  caller: Person! @connection(name: "PhoneCallCaller")
  callee: Person! @connection(name: "PhoneCallCallee")
  transcript: Transcript! @connection(name: "PhoneCallTranscript")
}

type Person @model {
  id: ID!
  name: String!
  callerOf: [PhoneCall!] @connection(name: "PhoneCallCaller")
  calleeOf: [PhoneCall!] @connection(name: "PhoneCallCallee")
}

type Transcript @model {
  id: ID!
  text: String!
  language: String
  phoneCall: PhoneCall! @connection(name: "PhoneCallTranscript")
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 24 (5 by maintainers)

Most upvoted comments

Any updates?

Thanks guys. I’ve been told it’s being looked into, has to do with which side of the relationship should be the “owner”. I’ve made a feature request that possibly addresses this and other issues RFC - Simplified @connection directive

type TestModel @model {
  id: ID!
  name: String
}

type TestModel2 @model {
  id: ID!
  test1: TestModel! @connection
}

this works well, but

type TestModel @model {
  id: ID!
  name: String
}

type TestModel2 @model {
  id: ID!
  test1Id: ID!
  test1: TestModel! @connection(fields: ["test1Id"])
}

this causes error: DataStore does not support 1 to 1 connection with both sides of connection as optional field

But,

type TestModel @model {
  id: ID!
  name: String
}

type TestModel2 @model {
  id: ID!
  test1Id: ID!
  test1: TestModel @connection(fields: ["test1Id"]) # `!` removed
}

This works!!! 🙃 @anthonymoretti @watanabethais

Thanks for taking the time to comment. We’re working on ways to make DataStore relationships simpler. We’ll update this issue as soon as we have more information.

For the record this isn’t just a iOS issue. Hit it today trying to get the new Admin UI working on an existing schema, this requires DataStore to be configurated which throws this error when I push 😦

@kldeb we removed the connection for now instead of money-patching; we monkey-patched just to prove out the theory that the if-block is missing a clause and it would fall into that missing clause if added instead of erroring.

@drochetti I guess everyone is busy, but been 6 months since this ticket was opened and the issue looks relatively simple to triage if someone is available to.

This is still a relevant issue and needs to be triaged and prioritized.