When running npx ampx generate graphql-client-code --format modelgen --model-target swift on my Amplify Swift project, depending on the models defined in data/resource.ts the decoding initializer does not compile due to a Cannot assign value of type '[MyCustomType]?' to type '[MyCustomType?] error in Xcode.
Expected Behavior
myCustomTypes = try values.decode([MyCustomType?].self, forKey: .myCustomTypes) should be generated
Current Behavior
myCustomTypes = try? values.decode([MyCustomType].self, forKey: .myCustomTypes) is generated
Environment information
Describe the bug
When running
npx ampx generate graphql-client-code --format modelgen --model-target swift
on my Amplify Swift project, depending on the models defined indata/resource.ts
the decoding initializer does not compile due to aCannot assign value of type '[MyCustomType]?' to type '[MyCustomType?]
error in Xcode.Expected Behavior
myCustomTypes = try values.decode([MyCustomType?].self, forKey: .myCustomTypes)
should be generatedCurrent Behavior
myCustomTypes = try? values.decode([MyCustomType].self, forKey: .myCustomTypes)
is generatedReproduction steps
Define the following models in
data/resource.ts
:And run
npx ampx generate graphql-client-code --format modelgen --model-target swift
to create the models.Additional Information/Context
When changing the custom type in the array to a non-optional, the decoding is done correctly.
Environment details (OS name and version, etc.)
macOS 15.1, Xcode 16.1 beta 2, swift-tools-version: 6.0, swiftLanguageModes v5