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

apollo-ios-cli mock code generation fails for string arrays #3130

Closed
Kn3cht opened this issue Jul 20, 2023 · 10 comments · Fixed by #3150
Closed

apollo-ios-cli mock code generation fails for string arrays #3130

Kn3cht opened this issue Jul 20, 2023 · 10 comments · Fixed by #3150
Assignees
Labels
bug Generally incorrect behavior needs investigation planned-next Slated to be included in the next release

Comments

@Kn3cht
Copy link

Kn3cht commented Jul 20, 2023

Summary

I tried out the code generation for mock objects and stubled upon an issue related to the _setList invocation of the initializer of the generated MockObjects.

For all of those invocations I'm getting the compiler error

Type of expression is ambiguous without more context

I alreay read through this related issue: https://github.com/apollographql/apollo-ios/issues/3023. However in my case it even fails for string arrays.

Any help / workarounds for the meantime are appreciated.

Version

v1.3.1

Steps to reproduce the behavior

Example fragment

fragment HumanName on HumanName {
    id
    ...
    maidenNames # [String]
}

Generated:

public extension Mock where O == HumanName {
  convenience init(
    id: String? = nil,
    ...
    maidenNames: [String]? = nil,
  ) {
    self.init()
    _setScalar(id, for: \.id)
    ...
    _setList(maidenNames, for: \.maidenNames) // <- Causing the compiler error
  }
}

iOS Version: 15
Xcode Version: 14.3.1

Logs

No response

Anything else?

No response

@Kn3cht Kn3cht added bug Generally incorrect behavior needs investigation labels Jul 20, 2023
@Kn3cht Kn3cht changed the title apollo-ios-cli mock code generation fails for arrays apollo-ios-cli mock code generation fails for string arrays Jul 20, 2023
@calvincestari
Copy link
Member

Thanks for the bug report @Kn3cht. I believe we have a fix for this already in #3120 which is merged into main but not yet released. We're planning to publish a patch release this week which will include that fix but if you wanted to test it you could point your dependency at the main branch and see if it resolves your issue.

@calvincestari
Copy link
Member

@Kn3cht - the fix I mentioned earlier has just been released in 1.3.2. Please try that and let me know whether it resolves your issue.

@Kn3cht
Copy link
Author

Kn3cht commented Jul 23, 2023

@calvincestari Thx for the fast reply.
Just updated to v1.3.2 but unfortunately the issue still persists.

@ski-u
Copy link

ski-u commented Jul 24, 2023

I have the same issue for enum (which has String raw value) arrays with apollo-ios v1.3.2.

スクリーンショット 2023-07-24 10 47 02

That enum is like this ↓

public enum MyEnum: String, EnumType {
  case front = "FRONT"
  case left = "LEFT"
  case right = "RIGHT"
}

@jarrodrobins
Copy link

I am having the same issue. For me, the last working version of Apollo is 1.1.2 as a result of issues with mock generation.

@BobaFetters
Copy link
Member

Thanks for the additional reports and use cases, we will look into this as soon as we can.

@BobaFetters BobaFetters added the planned-next Slated to be included in the next release label Jul 24, 2023
@BobaFetters BobaFetters self-assigned this Jul 24, 2023
@BobaFetters
Copy link
Member

The fix for this has been merged into main and will go out with the next patch release. If you would like to verify this fixes the issue for you can try pointing your dependency to main.

@cswelin
Copy link
Contributor

cswelin commented Jul 25, 2023

I've pointed to main and still seeing an error similar to #3130 (comment)

image

on the line

_setList(errors, for: .errors)

Enum looks like

public enum GenerateNewRecoveryCodeForAccountError: String, EnumType {
  case enrollmentNotFound = "ENROLLMENT_NOT_FOUND"
}

@BobaFetters
Copy link
Member

BobaFetters commented Jul 25, 2023

@cswelin Just to verify, after pointing to main did you re-run code generation? That would be required for the files to be updated.

@cswelin
Copy link
Contributor

cswelin commented Jul 25, 2023

@cswelin Just to verify, after pointing to main did you re-run code generation? That would be required for the files to be updated.

ah shoot, I missed the codegen package dependencies to point to main, that fixed it thank you.

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 planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants