Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid redeclaration of synthesized property '_id' #3376

Closed
jimisaacs opened this issue May 7, 2024 · 7 comments
Closed

Invalid redeclaration of synthesized property '_id' #3376

jimisaacs opened this issue May 7, 2024 · 7 comments
Labels
bug Generally incorrect behavior needs investigation

Comments

@jimisaacs
Copy link
Contributor

jimisaacs commented May 7, 2024

Summary

I have a rather urgent issue that popped up when trying to use the TestSupport sources. I get the following static compiler error on a MockObject type:

Invalid redeclaration of synthesized property '_id'

The reason seems to be that it's a type in our schema that defines both a _id and a id field, and the codegen outputs that, but Swift doesn't like it.

Version

1.10.0

Steps to reproduce the behavior

Run codegen while generating mocks for a type with both _id and id fields. Then try to use the generated MockObject for that type.

Logs

No response

Anything else?

// @generated
// This file was automatically generated and should not be edited.

import ApolloTestSupport
import MySchema

public class MyGeneratedType: MockObject {
  public static let objectType: ApolloAPI.Object = MyGeneratedSchema.Objects.MyGeneratedType
  public static let _mockFields = MockFields()
  public typealias MockValueCollectionType = Array<Mock<MyGeneratedType>>

  public struct MockFields {
    @Field<MyGeneratedSchema.ID>("_id") public var _id
    @Field<MyGeneratedSchema.ID>("id") public var id
  }
}

public extension Mock where O == MyGeneratedType {
  convenience init(
    _id: MyGeneratedSchema.ID? = nil,
    id: MyGeneratedSchema.ID? = nil
  ) {
    self.init()
    _setScalar(_id, for: \._id)
    _setScalar(id, for: \.id)
  }
}
@jimisaacs jimisaacs added bug Generally incorrect behavior needs investigation labels May 7, 2024
@jimisaacs
Copy link
Contributor Author

@jimisaacs
Copy link
Contributor Author

I think we might be able to use alias, looking into it.

@AnthonyMDev
Copy link
Contributor

Hmmmm... this is one we haven't seen yet.

I don't think alias is going to help here. If I recall correctly, the test mocks use the field names on the schema, they don't pay attention to the aliases for fields in the operation definitions.

@BobaFetters the work you're doing for changing schema type names doesn't apply to changing the names of fields on the types, right? Just the actual type names themselves?

@jimisaacs
Copy link
Contributor Author

@AnthonyMDev actually alias seemed to have worked for me. If you feel like this is a bug worth solving please leave this open, or close with documentation guidance for alias.

@jimisaacs
Copy link
Contributor Author

jimisaacs commented May 7, 2024

The alias did this:

// @generated
// This file was automatically generated and should not be edited.

import ApolloTestSupport
import MySchema

public class MyGeneratedType: MockObject {
  public static let objectType: ApolloAPI.Object = MyGeneratedSchema.Objects.MyGeneratedType
  public static let _mockFields = MockFields()
  public typealias MockValueCollectionType = Array<Mock<MyGeneratedType>>

  public struct MockFields {
    @Field<MyGeneratedSchema.ID>("aliasedId") public var aliasedId
    @Field<MyGeneratedSchema.ID>("id") public var id
  }
}

public extension Mock where O == MyGeneratedType {
  convenience init(
    aliasedId: MyGeneratedSchema.ID? = nil,
    id: MyGeneratedSchema.ID? = nil
  ) {
    self.init()
    _setScalar(aliasedId, for: \.aliasedId)
    _setScalar(id, for: \.id)
  }
}

@AnthonyMDev
Copy link
Contributor

Ohhh, okay! I was remembering how that worked incorrectly. Great. That is actually the correct solution to this problem then! Thanks for the update.

Copy link
Contributor

github-actions bot commented May 7, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

No branches or pull requests

2 participants