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

Getting the error "Module ApolloAPI was not compiled for testing" while compiling swift package in "Release" mode in apollo v1.7.0. #3401

Closed
divyansh0201 opened this issue Jul 2, 2024 · 3 comments
Labels
bug Generally incorrect behavior needs investigation

Comments

@divyansh0201
Copy link

Summary

We have recently updated Apollo to version 1.7.0 in our project. We are not willing to update it further for now. We have encountered an issue that requires resolution. Our project setup involves adding ApolloTestSupport and ApolloAPI as targets in our Swift Package Manager (SPM) package along with other targets. This setup is necessary because we need to generate mock responses, and we are using mocks at various places in our code.

Here is a summary of our configuration:

We have added ApolloTestSupport and ApolloAPI as targets in our SPM package.
Inside this SPM, there are multiple targets, each with separate test mock folders generated using ApolloCodegen.
The issue arises when we try to compile the project. The error messages indicate that ApolloAPI was not compiled for testing.

Error Messages:

"Module 'ApolloAPI' was not compiled for testing"
Steps to Reproduce:

Screenshots:

Error Messages:
image

We seek guidance on how to resolve this error without removing ApolloTestSupport and ApolloAPI from our SPM targets since mock responses are a requirement for our project.
Any advice or suggestions would be highly appreciated.

Version

Apollo v1.7.0

Steps to reproduce the behavior

Update Apollo to version 1.7.0.
Add ApolloTestSupport and ApolloAPI as targets in the SPM package.
Attempt to build the project.

Logs

No response

Anything else?

No response

@divyansh0201 divyansh0201 added bug Generally incorrect behavior needs investigation labels Jul 2, 2024
@calvincestari
Copy link
Member

calvincestari commented Jul 2, 2024

Hi @divyansh0201 - this is being caused by the @testable attribute on the import of ApolloAPI in TestMock. As you're finding out, release builds do not enable testability by default. ApolloTestSupport was originally intended only for test cases but it's use has grown outside of that.

We switched to using an SPI import in PR #362 which was released in version 1.12.0. That should resolve the issue for you.

If you're not willing to move further past 1.7.0 you will need to fork from 1.7.0 and attempt to cherry-pick the PR but I'm not sure whether it's compatible.

@calvincestari calvincestari closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2024
Copy link
Contributor

github-actions bot commented Jul 2, 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.

@divyansh0201
Copy link
Author

Thanks, it worked like a charm!

Hi @divyansh0201 - this is being caused by the @testable attribute on the import of ApolloAPI in TestMock. As you're finding out, release builds do not enable testability by default. ApolloTestSupport was originally intended only for test cases but it's use has grown outside of that.

We switched to using an SPI import in PR #362 which was released in version 1.12.0. That should resolve the issue for you.

If you're not willing to move further past 1.7.0 you will need to fork from 1.7.0 and attempt to cherry-pick the PR but I'm not sure whether it's compatible.

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