# Guide on multi-module swift packages on iOS?

**URL:** <https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334>\
**Category:** Client SDKs\
**Tags:** ios\
**Created:** [March 27, 2024, 7:20am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334 "2024-03-27T07:20:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chi\_Chiem\_Duc](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/chi_chiem_duc/32/4990_2.png) [@Chi\_Chiem\_Duc](https://community.apollographql.com/u/Chi_Chiem_Duc)\
**Post date:** [March 27, 2024, 7:20am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/1 "2024-03-27T07:20:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![calvincestari](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/calvincestari/32/339_2.png) [@calvincestari](https://community.apollographql.com/u/calvincestari)\
**Post date:** [March 27, 2024, 5:02pm UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/2 "2024-03-27T17:02:22Z")

</div>

Hi @Chi_Chiem_Duc,

For the operations output it looks like you’ll want to use [relative operations output](https://www.apollographql.com/docs/ios/code-generation/codegen-configuration#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](https://www.apollographql.com/docs/ios/code-generation/codegen-configuration#embedded-in-target) or [swift package manager](https://www.apollographql.com/docs/ios/code-generation/codegen-configuration#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.

---

<div class="post-metadata">

**Author:** ![Chi\_Chiem\_Duc](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/chi_chiem_duc/32/4990_2.png) [@Chi\_Chiem\_Duc](https://community.apollographql.com/u/Chi_Chiem_Duc)\
**Post date:** [March 28, 2024, 8:16am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/3 "2024-03-28T08:16:56Z")

</div>

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](https://github.com/chichiem2402/GraphQLMultiModule)

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](https://www.apollographql.com/docs/kotlin/advanced/multi-modules) is pretty clear on this topic

I’m very sorry for bothering you this much 🫠

---

<div class="post-metadata">

**Author:** ![calvincestari](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/calvincestari/32/339_2.png) [@calvincestari](https://community.apollographql.com/u/calvincestari)\
**Post date:** [March 29, 2024, 4:15am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/4 "2024-03-29T04:15:50Z")

</div>

I’ll take a look at the repo but in the meanwhile have you read the [Project Configuration](https://www.apollographql.com/docs/ios/project-configuration/intro) guide on the Apollo iOS docs? The [codegen configuration](https://www.apollographql.com/docs/ios/code-generation/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.

---

<div class="post-metadata">

**Author:** ![Chi\_Chiem\_Duc](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/chi_chiem_duc/32/4990_2.png) [@Chi\_Chiem\_Duc](https://community.apollographql.com/u/Chi_Chiem_Duc)\
**Post date:** [March 29, 2024, 6:06am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/5 "2024-03-29T06:06:25Z")

</div>

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 🙃

---

<div class="post-metadata">

**Author:** ![calvincestari](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/calvincestari/32/339_2.png) [@calvincestari](https://community.apollographql.com/u/calvincestari)\
**Post date:** [March 29, 2024, 6:24am UTC](https://community.apollographql.com/t/guide-on-multi-module-swift-packages-on-ios/7334/6 "2024-03-29T06:24:43Z")

</div>

[Here is a patch file](https://drive.google.com/file/d/1HlueST_N8ujC2WVtXTj_4DUNPzYTV7_Z/view?usp=sharing) 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.
