diff --git a/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift b/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift index 47e33be997..9fb608b5f1 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift @@ -53,6 +53,7 @@ public struct ApolloCodegenOptions { } let codegenEngine: CodeGenerationEngine + let customScalarsPrefix: String? let includes: String let mergeInFieldsFromFragmentSpreads: Bool let namespace: String? @@ -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, @@ -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 @@ -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)") } diff --git a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift index c154e96b9c..89cd5536ba 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift @@ -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) @@ -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") @@ -66,6 +68,7 @@ class ApolloCodegenTests: XCTestCase { let namespace = "ANameSpace" let options = ApolloCodegenOptions(codegenEngine: .swiftExperimental, + customScalarsPrefix: customScalarsPrefix, includes: "*.graphql", mergeInFieldsFromFragmentSpreads: false, modifier: .internal, @@ -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, [ @@ -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",