We’re using the embeddedInTarget
option when using code generation to add code to an existing SPM package target.
Our client package file looks like this:
// swift-tools-version:5.9
import PackageDescription
let package = Package(
name: "Client",
platforms: [
.iOS(.v17),
],
products: [
.library(
name: "Client",
targets: ["Client"]
),
.library(
name: "ClientAPI",
targets: ["ClientAPI"]
),
],
dependencies: [
.package(
url: "https://github.com/apollographql/apollo-ios.git",
.upToNextMajor(from: "1.0.0")
),
],
targets: [
.target(
name: "Client",
dependencies: [
"ClientAPI",
.product(name: "Apollo", package: "apollo-ios"),
]
),
.target(
name: "ClientAPI",
dependencies: [
.product(name: "Apollo", package: "apollo-ios"),
]
),
]
)
We then run the generate option which places the files in the Sources/ClientAPI
directory of the target already defined in our package.
The issue we’re seeing is that the generated types all have import ClientAPI
which leads to dozens of warnings like:
File ‘SomeFragment.graphql.swift’ is part of module ‘ClientAPI’; ignoring import
Even though the files are already in that target.
And worse still, the types sit in a namespace even though the files are already namespaced by the SPM target’s module, which means on the app side we have types that can be referenced by the fully qualified name like ClientAPI.ClientAPI.SomeFragment
ClientAPI
is the the SPM module name, the second ClientAPI
is the Apollo-generated enum namespace and SomeFragment
is the type in question.
Any way we can avoid this?