aws-amplify / aws-amplify/amplify-codegen

Amplify Swift codegen generates incorrect syntax when custom types reference @model types in GraphQL schema.

Open
#973 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

- Amplify Swift codegen generates incorrect syntax when custom types reference **`@model`** types in GraphQL schema.

Image

### Steps To Reproduce

```swift
1. Create AppSync API with sample schema which uses custom types reference @model types in GraphQL schema.

type Product @model {
id: ID! @primaryKey
name: String!
price: Float!
}

type OrderSummary {
orderId: ID!
product: Product! # References @model type
quantity: Int!
}

type Mutation {
createOrder(productId: ID!, quantity: Int!): OrderSummary
@function(name: "createOrder-${env}")
}

2. Generate models using `amplify codegen models`
3. Check and Verify generated model swift file and use it your application.

// swiftlint:disable all
import Amplify
import Foundation

extension OrderSummary {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case orderId
case product
case quantity
}

public static let keys = CodingKeys.self
// MARK: - ModelSchema

public static let schema = defineSchema { model in
let orderSummary = OrderSummary.keys

model.listPluralName = "OrderSummaries"
model.syncPluralName = "OrderSummaries"

model.fields(
.field(orderSummary.orderId, is: .required, ofType: .string),
.field(orderSummary.product, is: .required, ofType: .model(Product.self)),
.field(orderSummary.quantity, is: .required, ofType: .int)
)
}
}

4. You will get error `Missing argument label 'type:' in call`
```

### Expected behavior

**Problem: Generated code produces:**

```
model(Product.self) // Missing 'type:' parameter
```

** **

```
.model(type: Product.self) // Correct syntax
```

### Amplify Framework Version

2.50.0

### Amplify Categories

API

### Dependency manager

Swift PM

### Swift version

Swift 6.1.2

### CLI version

14.0.0

### Xcode version

16.4

### Relevant log output

```shell

Log Messages

INSERT LOG MESSAGES HERE

```

### Is this a regression?

No

### Regression additional context

_No response_

### Platforms

_No response_

### OS Version

macOS 15.0

### Device

Iphone 16 pro

### Specific to simulators

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.