Guide on multi-module swift packages on iOS?

I’ve read the documentation on project configuration but it’s still not quite clear on how to actually set it up.

Let’s say we have the following structure:

  • MainApp (Xcode Project)
    –Feature A (dependency of MainApp through SPM, have FetchAQuery.graphql)
    –Feature B (dependency of MainApp through SPM, have FetchBQuery.graphql)
    ----Network (dependency of Feature A and Feature B, have apollo, schema.graphqls and apollo-ios-cli)

What will I have to do to generate FetchAQuery and FetchBQuery in their respective Feature modules, using the shared schema in Network module?

Thanks a lot

Hi @Chi_Chiem_Duc,

For the operations output it looks like you’ll want to use relative operations output. As the documentation states, that will generate the Swift models alongside the operation definition files (.graphql)

For a shared schema I think you could use either the embedded in target or swift package manager options. Either should be able to work with your configuration, it’s dependent on how much control you want over the generation/maintenance of the shared schema module.

Hi @calvincestari

Thanks for the reply, but I still can’t make the shared schema work, maybe because I have some missing pieces of knowledge
To make it easier, I’ve created a repo here

In the repo I have 2 packages

  • GraphQLFeature
  • GraphQLCore

GraphQLFeature is the one having the Operation file (LaunchListFeature.graphql)
GraphQLCore is the one having .graphqls schema (schema.graphqls)

GraphQLFeature depends on GraphQLCore

The ultimate goal is to run code generate on GraphQLFeature to generate LaunchListFeatureQuery

The steps I imagined:

  1. Install apollo-ios-cli on GraphQLFeature
  2. Run apollo-ios-cli init and configure the json file to have relative operations output
  3. Run apollo-ios-cli generate

Are these steps correct?
Or is it missing something from GraphQL/SPM side?

It would be super cool if we can collab on the repo and make a working example
Maybe we can include a tutorial in github as well, since I’ve been searching on the internet for 2 days and couldn’t find a good tutorial about multi-modules/shared schema on iOS.
Meanwhile the document on Android is pretty clear on this topic

I’m very sorry for bothering you this much :melting_face:

I’ll take a look at the repo but in the meanwhile have you read the Project Configuration guide on the Apollo iOS docs? The codegen configuration alone could be confusing with all the options but we wrote the project configuration guide to have more content focused on multi-module configurations.

Yes, I’ve read it multiple times and still quite confused and doesn’t know how to make it work
Maybe it’s just me, since I couldn’t find people asking about this, it could be that others understand the docs perfectly :upside_down_face:

Here is a patch file that modifies the two SPM packages (for platform only) and the codegen config for both projects. There is an issue with this configuration where the namespace file is added twice in different path causing a build error. It’s the conflict of having both build the schema module but in different ways.

I think a better configuration would be to have a third SPM module for the schema module (using swiftPackageManager module option), which becomes another SPM dependency for both packages and they can each then have their own queries.