Skip to content
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
7 changes: 7 additions & 0 deletions Sources/ApolloCodegenLib/ApolloCodegenOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public struct ApolloCodegenOptions {
}

let codegenEngine: CodeGenerationEngine
let customScalarsPrefix: String?
let includes: String
let mergeInFieldsFromFragmentSpreads: Bool
let namespace: String?
Expand Down Expand Up @@ -84,6 +85,7 @@ public struct ApolloCodegenOptions {
/// - urlToSchemaFile: The URL to your schema file.
/// - downloadTimeout: The maximum time to wait before indicating that the download timed out, in seconds. Defaults to 30 seconds.
public init(codegenEngine: CodeGenerationEngine = .default,
customScalarsPrefix: String? = nil,
includes: String = "./**/*.graphql",
mergeInFieldsFromFragmentSpreads: Bool = true,
modifier: AccessModifier = .public,
Expand All @@ -97,6 +99,7 @@ public struct ApolloCodegenOptions {
urlToSchemaFile: URL,
downloadTimeout: Double = 30.0) {
self.codegenEngine = codegenEngine
self.customScalarsPrefix = customScalarsPrefix
self.includes = includes
self.mergeInFieldsFromFragmentSpreads = mergeInFieldsFromFragmentSpreads
self.modifier = modifier
Expand Down Expand Up @@ -153,6 +156,10 @@ public struct ApolloCodegenOptions {
"--localSchemaFile='\(self.urlToSchemaFile.path)'"
]

if let customScalarsPrefix = self.customScalarsPrefix {
arguments.append("--customScalarsPrefix=\(customScalarsPrefix)")
}

if let namespace = self.namespace {
arguments.append("--namespace=\(namespace)")
}
Expand Down
7 changes: 6 additions & 1 deletion Tests/ApolloCodegenTests/ApolloCodegenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ApolloCodegenTests: XCTestCase {

XCTAssertEqual(options.includes, "./**/*.graphql")
XCTAssertTrue(options.mergeInFieldsFromFragmentSpreads)
XCTAssertNil(options.customScalarsPrefix)
XCTAssertNil(options.namespace)
XCTAssertNil(options.only)
XCTAssertNil(options.operationIDsURL)
Expand All @@ -58,6 +59,7 @@ class ApolloCodegenTests: XCTestCase {
}

func testCreatingOptionsWithAllParameters() throws {
let customScalarsPrefix = "Scalar"
let sourceRoot = CodegenTestHelper.sourceRootURL()
let output = sourceRoot.appendingPathComponent("API")
let schema = sourceRoot.appendingPathComponent("schema.json")
Expand All @@ -66,6 +68,7 @@ class ApolloCodegenTests: XCTestCase {
let namespace = "ANameSpace"

let options = ApolloCodegenOptions(codegenEngine: .swiftExperimental,
customScalarsPrefix: customScalarsPrefix,
includes: "*.graphql",
mergeInFieldsFromFragmentSpreads: false,
modifier: .internal,
Expand All @@ -91,6 +94,7 @@ class ApolloCodegenTests: XCTestCase {
XCTAssertEqual(options.urlToSchemaFile, schema)
XCTAssertTrue(options.omitDeprecatedEnumCases)
XCTAssertEqual(options.modifier, .internal)
XCTAssertEqual(options.customScalarsPrefix, customScalarsPrefix)


XCTAssertEqual(options.arguments, [
Expand All @@ -99,7 +103,8 @@ class ApolloCodegenTests: XCTestCase {
"--addTypename",
"--includes='*.graphql'",
"--localSchemaFile='\(schema.path)'",
"--namespace=\(namespace)",
"--customScalarsPrefix=Scalar",
"--namespace=ANameSpace",
"--only='\(only.path)'",
"--operationIdsPath='\(operationIDsURL.path)'",
"--omitDeprecatedEnumCases",
Expand Down