iOS - Add Code Generation Build Step using Swift Scripting Library

Hi guys, I’m following the steps on https://www.apollographql.com/docs/ios/installation/#adding-a-code-generation-build-step which provides 3 script options:

  • Swift Package Manager Run Script
  • CocoaPods Run Script
  • Carthage Run Script

I opted to use the first one but when executing, it warns me that it will be deprecated soon and that I should use the Swift Scripting method instead (https://www.apollographql.com/docs/ios/swift-scripting/).

I was able to configure the template project and download the schema by running swift run ApolloCodegen downloadSchema on the terminal. However, I’m unclear what should I put on the actual Xcode build step. Can you please provide guidance or point me to the correct documentation? Thank you!

So glad you’re trying out the new scripting!

Just a little further down the page was the answer you’re looking for! Swift scripting - Apollo GraphQL Docs

cd "${SRCROOT}"/ApolloCodegen
xcrun -sdk macosx swift run ApolloCodegen generate
1 Like

Thank you Anthony! It was right there in front of me :rofl: but I stopped reading on Adding a .graphql file with an operation because I thought I wasn’t done with the first step. Thanks a lot anyways.

I was a bit confused by the swift scripting instructions.

Does this mean we have to store our swift script within our repo?

Is there no way to use SPMs built in executable support?

Currently, we don’t have support for the SPM built-in-executable yet. We are rebuilding the entire code generation engine, and will be looking into this soon. The new code generation engine is available with our Alpha releases.

Does this mean we have to store our swift script within our repo?

The swift scripts could be stored in a separate repo of their own, or in the same repo as your project. I’d say leaving them in the same repo is easier in most use cases.

I’ll also be the first to say, the Swift Scripting as it exists today is not the easiest thing to use.

For the 1.0 release with the new code generation engine, we plan to provide both a CLI and the option to use Swift Scripts for more advanced custom use cases. Having SPM built-in executables run is also something we want to provide support for.

The Add Code Generation Build Step using Swift Scripting Library has been removed but I would need to know the migration steps to upgrade from breaking change to breaking change. Do you know any way to get the steps indicated on that website? Why are the steps no longer posted even though they appear as deprecated in a certain version?

The docs for using swift scripts in 1.0 are located here. There is also a 1.0 migration guide that has a whole section on setting up the new codegen!

1 Like

Thank you very much for your help. My biggest problem is that I have to upgrade a project to the latest version 0.15.3. I just finished upgrading to 0.16 and I saw the warning with check-and-run-apollo-cli.sh script deprecation. Any suggestions about this migration would be greatly appreciated.