apollo-ios: Unable to run code generation
Bug report
Installing Apollo 1.0.0 via Cocoapods results in code generation error.
Versions
Please fill in the versions you’re currently using:
apollo-ios
SDK version: 1.0.0- Xcode version: 14.0.1
- Swift version: 5.7
- Package manager: N/A
- Cocoapods version: 1.11.3
Steps to reproduce
pod init
Add pod 'Apollo'
pod install
./Pods/Apollo/apollo-ios-cli init --schema-name MySchema
./Pods/Apollo/apollo-ios-cli generate
ApolloCodegenLib/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /Users/xxx/ProjectName/Pods/Apollo/Apollo_ApolloCodegenLib.bundle or /Users/xxx/Library/Caches/CocoaPods/Pods/Release/Apollo/1.0.0-95555/.build/arm64-apple-macosx/release/Apollo_ApolloCodegenLib.bundle
zsh: trace trap ./Pods/Apollo/apollo-ios-cli generate
Further details
Note that cocoapods is installed using Hombrew.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 63 (28 by maintainers)
I’ll be honest; I find the instructions to get code generation to work in 1.0 to be very confusing. Looking at the available options listed in the documentation to install the codegen CLI:
Any help would be appreciated…
It looks like in order to make network requests, the CLI may need to be run with the sandbox disabled. This was not clear to us from Apple’s (very limited) documentation on the switch package plug-in API. We’re going to do some more digging and update the documentation. Thanks do much to everyone who has helped dig into this issue so far!
I’m going to look into if there is a better/easier way for use to deploy the CLI. We felt that a swift package plug-in was the most user friendly way to do this, but it’s looking like the SPM plug-in system is still not mature enough to provide an experience here that is up to our standards.
I genuinely apologize to all of you who have started to attempt the migration to what we felt was a stable 1.0 version and have hit these issues. We’re going to spend time this coming week figuring out what the right option is for making code generation as seamless as possible for all of you.
After bit more digging—including closed issues (thanks Andy Kent)—figured it was a sandbox issue, and this sorts it:
swift package --disable-sandbox --allow-writing-to-package-directory apollo-fetch-schema -v --path "Sources/GraphQLClient/apollo-codegen-config.json"
(Note that
--disable-sandbox
must come before--allow-writing-to-package-directory
.)Anyone who’s watching this issue for a fix to the original issue of
Fatal error: could not load resource bundle
when using CocoaPods; the fix (#2548) has been merged with so if you point your Pod to theHEAD
ofmain
it should work for you now.We’ve got a couple other fixes we want to get into
main
before publishing a1.0.1
release.Same problem. Can’t sleep, the customer is rushing the work. I’m really looking forward to news about the fix.
Hi, The same issue here.
Ok, I’ll have to dig into it a bit later; we’re all en route to Summit at the moment. Will try take a look later today. Apologies for the delay.
Hi @AnthonyMDev it works now 💃🏾.
After upgrading to 1.0.0 i also encounter issue during the codegen phase:
ApolloCodegenLib/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /Users/XXXXXXXX/ios/Pods/Apollo/Apollo_ApolloCodegenLib.bundle or /Users/XXX/Library/Caches/CocoaPods/Pods/Release/Apollo/1.0.0-95555/.build/arm64-apple-macosx/release/Apollo_ApolloCodegenLib.bundle
Thanks @calvincestari , unfortunately adding the
--path
to bothinit
andgenerate
resulted in the same error. I used a path deliberately not in the Pods folder.@calvincestari
It works on GraphiQL.
Thanks for the update @AnthonyMDev - appreciate you and @calvincestari replying to us all and sorting these issues so quickly.
This issue has been closed as the specific cause of it has been corrected. The fix for this will be released in 1.0.1 very soon and is available right now on the
main
branch.If you are having other problems with codegen, please submit a new issue!
Thanks to everyone for all the info as we work this out. We unfortunately did not get enough users during the Beta period to find these edge cases. So we are working quickly to resolve all of them now and will release a patch version ASAP!
Looks like my generate errors were self-inflicted, and due to one or two paths being wrong, such that it was not finding any graphQL files, and passing an empty array; maybe a more accurate error than ‘Precondition failed: Expected JavaScript array but found: undefined’ would be in order. But despite all the trouble, have got it all migrated and working again.
@SilverTab You can run the plugin commands using Xcode like this. https://blog.eidinger.info/xcode-integration-of-swift-package-plugins-in-xcode-14
I’ll update the docs to add this next week!
Thanks for pointing me in the right direction… I was able to get it to build by first doing:
% sudo xcode-select --reset
@sammcode I think there might be some confusion between ApolloCodegenLib and the new apollo-ios-cli. ApolloCodegenLib has always only been designed to run on macOS because code generation does not need to be executed on mobile devices. You can view the ApolloCodegen class from
0.53.0
and it has the same macOS-only designation.v1.0 moves away from recommending that code generation be executed with each build, which is what the bash scripting help before recommended. Note that you can still take that same approach but using the new apollo-ios-cli instead of the legacy Apollo tooling CLI; very similar names I’m sorry.
I am getting similar issue when trying to run cli (get via Pods):
We are also using Xcode to manage Swift packages, so we were also a bit confused on how to set that up. Specifically, it was unclear how we can edit the
apollo-codegen-configuration.json
file in Xcode. We made a little bit of progress with the SPM solution, but we are still running into issues (will go into detail below).Possible workaround for editing configuration file when using SPM
A workaround I tried with the SPM solution was opening the
apollo-codegen-configuration.json
file in a TextEditor rather than Xcode, which at least allowed us to edit the file.Schema fetching errors
But when attempting to fetch the schema, we’re still running into errors.
We’ve tried with two working graphql endpoints and have gotten the same error with both of them. We are unclear as to if there is a problem with our configuration, or if there is a bug of some sort here.
The main error we keep getting is:
It also looks like its having an issue reading from a cache, as we get this error as well:
I tried installing via Package manager. When I add ApolloCodegenLib I have some errors.
same problem here, struggling for 4 days and couldn’t solve it please help