Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds additional imported module namespaces to be added in codegen #9

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {

/// Name used to scope the generated schema type files.
public let schemaNamespace: String
/// Names used to add additional scopes the generated schema type files.
public let additionalImportedModuleNamespaces: [String]
/// The input files required for code generation.
public let input: FileInput
/// The paths and files output by code generation.
Expand Down Expand Up @@ -960,6 +962,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
/// - experimentalFeatures: Allows users to enable experimental features.
public init(
schemaNamespace: String,
additionalImportedModuleNamespaces: [String] = [],
input: FileInput,
output: FileOutput,
options: OutputOptions = Default.options,
Expand All @@ -968,6 +971,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
operationManifest: OperationManifestConfiguration? = Default.operationManifest
) {
self.schemaNamespace = schemaNamespace
self.additionalImportedModuleNamespaces = additionalImportedModuleNamespaces
self.input = input
self.output = output
self.options = options
Expand Down
9 changes: 9 additions & 0 deletions Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ struct ImportStatementTemplate {
return """
@_exported import \(apolloAPITargetName)
\(if: config.output.operations != .inSchemaModule, "import \(config.schemaModuleName)")
\(forEachIn: config.additionalImportedModulesNames, {
return "import \($0)"
})
"""
}
}
Expand All @@ -308,4 +311,10 @@ fileprivate extension ApolloCodegenConfiguration {
case .swiftPackageManager, .other: return schemaNamespace.firstUppercased
}
}
var additionalImportedModulesNames: [String] {
switch output.schemaTypes.moduleType {
case .embeddedInTarget: return []
case .swiftPackageManager, .other: return additionalImportedModuleNamespaces.map { $0.firstUppercased }
}
}
}
Loading