Skip to content

Generated models wont compile after upgrade #882

@jimkqwantegy

Description

@jimkqwantegy

After upgrading both pods and cli, some generated non-model types will not compile. For instance, we use:

type ModelLocationsConnection @aws_iam @aws_cognito_user_pools {
 items: [Location]
 total: Int
 nextToken: String
} 

to return data from an elastic search query (there are multiple examples). Nothing has changed with the models.

The above generates:

public struct ModelLocationsConnection: Embeddable {
  var items: [Location]?
  var total: Int?
  var nextToken: String?
}

and...

extension ModelLocationsConnection {
  // MARK: - CodingKeys 
   public enum CodingKeys: String, ModelKey {
    case items
    case total
    case nextToken
  }
  
  public static let keys = CodingKeys.self
  //  MARK: - ModelSchema 
  
  public static let schema = defineSchema { model in
    let modelLocationsConnection = ModelLocationsConnection.keys
    
    model.pluralName = "ModelLocationsConnections"
    
    model.fields(
      .field(modelLocationsConnection.items, is: .optional, ofType: .collection(of: Location.self)),
      .field(modelLocationsConnection.total, is: .optional, ofType: .int),
      .field(modelLocationsConnection.nextToken, is: .optional, ofType: .string)
    )
    }
}

Im left with a frustrating error as shown below.

Screen Shot 2020-11-10 at 6 47 41 AM

Location is defined as a @model in our schema:

type Location
    @model
    @auth(
    rules: [
        { allow: owner, ownerField: "owner", operations: [create, update, delete, read] },
        { allow: groups, groupsField: "locationAccountId", operations: [create, update, delete, read] },
        { allow: groups, groups: ["Admins"] },
        { allow: groups, groups: ["Owners"] },
        { allow: groups, groups: ["Users"], operations: [read]  },
    ])
    @searchable {
  id: ID!
  owner: String
  locationAccountId: ID!
  name: String!
  address: String!
  region: String
  country: String
  coordinates: Coordinates
  status: Status
  api: String
  capacity: Int
  targetCapacity: Int
  currentCapacity: Int
  requiresAssessment: Boolean!
  requiresAuthentication: Boolean!
  requiresTemperature: Boolean
  requiresAddress: Boolean
  requiresMask: Boolean
  requiredAccessControl: Boolean!
  userTypes: [UserType]
  entries: [EntryArray]
  type: LocationType
  dwellTime: Int
  account: Account @connection(fields: ["locationAccountId"])
}

We have a couple of these issues with different models after upgrading and cannot move forward.

We have tried of course to clean build folder, removed derived data, etc...

It doesnt seem like any of the codegen has changed (confirmed by looking at previous commits), but somehow the Embeddable definition.

The pod update is shown below:
Installing AWSAuthCore 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSCognitoIdentityProvider 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSCognitoIdentityProviderASF 2.18.1 (was 1.0.2 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSCore 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSMobileClient 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSPinpoint 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSPluginsCore 1.4.1 (was 1.2.0 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AWSS3 2.18.1 (was 2.15.3 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing Amplify 1.4.1 (was 1.2.0 and source changed to https://cdn.cocoapods.org/ from trunk)
Installing AmplifyPlugins 1.4.1 (was 1.2.0)
Installing AppSyncRealTimeClient 1.4.2 (was 1.4.1 and source changed to https://cdn.cocoapods.org/ from trunk)

amplify --version
4.32.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdatastoreIssues related to the DataStore category

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions