Initial set up of the Apollo iOS SDK with SPM

Hello! I didn’t realise this was here so had previously had help from @calvincestari on GitHub which has helped me get a step further but this seems like a better place to ask the next question.

At the moment I’m just trying to set up the StarWars schema into the project. Our project is set up in a very similar way to the Point Free isowords project… GitHub - pointfreeco/isowords: Open source game built in SwiftUI and the Composable Architecture.

We’re using a Package.swift file to define all our modules and dependencies.

In there I have added a dependency…

.package(url: "", .upToNextMajor(from: "1.0.0")),

And my target…

	name: "GraphQL",
	dependencies: [
		.product(name: "Apollo", package: "apollo-ios"),
		.product(name: "apollo-ios-cli", package: "apollo-ios"),
	resources: [

And in the GraphQL folder I have added the schema and query.

I’ve also updated the config file to make sure to have it pointing at the correct folders…

  "schemaName" : "GraphQL",
  "input" : {
    "operationSearchPaths" : [
    "schemaSearchPaths" : [
  "output" : {
    "testMocks" : {
      "none" : {
    "schemaTypes" : {
      "path" : "./Sources/GraphQL/Types",
      "moduleType" : {
        "other" : {
    "operations" : {
      "relative" : {

Now when I right click on the Package and choose generate…

Screenshot 2022-11-01 at 11.04.54

It generates the types and files for me…

If someone could embed this image it would help a lot. This is my first post so I can only embed one image. Thanks

However, now when I build the project I get a lot of errors throughout the project telling me Cannot find type 'ApolloCodegen' in scope. But these errors are coming from the Apollo library files rather than the generated files.

I saw this error mentioned in another thread but in there it was mentioned that this was due to the sandbox mode when fetching the schema (I think). But I’m not doing that, just generating code.

Any help would be appreciated.


Putting this here for visibility for others. In the end once I managed to get this far I went back to trying to use the cli command to generate the code and removed apollo-ios-cli from the Package.swift file.

Then I ran…

swift package --allow-writing-to-package-directory apollo-generate

And this was able to generate the same files but no longer had the issues with the ApolloCodegen.

I knew I was close to getting completed, just had that one step to go.


1 Like

I’ll add this here for completeness too:

apollo-ios-cli is really just an executable wrapper around the CodegenCLI library target, you shouldn’t ever need to include that in the list of dependency targets.