Skip to content

Commit 015e534

Browse files
Merge pull request #1183 from yuzushioh/apolloprefix
Add apollo custom extension to replace `apollo_` prefix
2 parents b893f36 + 332a4c1 commit 015e534

25 files changed

Lines changed: 149 additions & 130 deletions

Apollo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
9FF90A6F1DDDEB420034C3B6 /* InputValueEncodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */; };
183183
9FF90A711DDDEB420034C3B6 /* ReadFieldValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */; };
184184
9FF90A731DDDEB420034C3B6 /* ParseQueryResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */; };
185+
AE1CFBD0245EBA25002C8CEE /* ApolloExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE1CFBCE245EB998002C8CEE /* ApolloExtension.swift */; };
185186
C3279FC72345234D00224790 /* TestCustomRequestCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3279FC52345233000224790 /* TestCustomRequestCreator.swift */; };
186187
C338DF1722DD9DE9006AF33E /* RequestCreatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C338DF1622DD9DE9006AF33E /* RequestCreatorTests.swift */; };
187188
C35D43C222DDD4AC00BCBABE /* b.txt in Resources */ = {isa = PBXBuildFile; fileRef = C35D43BE22DDD3C100BCBABE /* b.txt */; };
@@ -572,6 +573,7 @@
572573
9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputValueEncodingTests.swift; sourceTree = "<group>"; };
573574
9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadFieldValueTests.swift; sourceTree = "<group>"; };
574575
9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParseQueryResponseTests.swift; sourceTree = "<group>"; };
576+
AE1CFBCE245EB998002C8CEE /* ApolloExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloExtension.swift; sourceTree = "<group>"; };
575577
C304EBD322DDC7B200748F72 /* a.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = a.txt; sourceTree = "<group>"; };
576578
C3279FC52345233000224790 /* TestCustomRequestCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCustomRequestCreator.swift; sourceTree = "<group>"; };
577579
C338DF1622DD9DE9006AF33E /* RequestCreatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestCreatorTests.swift; sourceTree = "<group>"; };
@@ -769,6 +771,7 @@
769771
9BD681302405F676000874CB /* Output */,
770772
9B8788702405F0150008789E /* Parsing */,
771773
9BD681342405F6D1000874CB /* SchemaDownload */,
774+
AE1CFBCE245EB998002C8CEE /* ApolloExtension.swift */,
772775
9B518C8A235F8B05004C426D /* ApolloFilePathHelper.swift */,
773776
9BD6812E2405F665000874CB /* JSON.swift */,
774777
9BAEEBF22346DDAD00808306 /* CodegenLogger.swift */,
@@ -1830,6 +1833,7 @@
18301833
9BD6812B2405F410000874CB /* ASTFragment.swift in Sources */,
18311834
9B68F04A24130D6500E97318 /* EnumGenerator.swift in Sources */,
18321835
9B7B6F69233C2C0C00F32205 /* FileManager+Apollo.swift in Sources */,
1836+
AE1CFBD0245EBA25002C8CEE /* ApolloExtension.swift in Sources */,
18331837
9BE74D3D23FB4A8E006D354F /* FileFinder.swift in Sources */,
18341838
9B7B6F59233C287200F32205 /* ApolloCodegen.swift in Sources */,
18351839
9BD6813E2405FAC8000874CB /* ASTField.swift in Sources */,

Sources/ApolloCodegenLib/ASTVariableType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ASTForthcomingVariableType: Codable {
4646
case .LIST:
4747
return "[\(inner)]?"
4848
case .NON_NULL:
49-
return try inner.apollo_droppingSuffix("?")
49+
return try inner.apollo.droppingSuffix("?")
5050
case .ENUM,
5151
.INPUT_OBJECT,
5252
.INTERFACE,

Sources/ApolloCodegenLib/ApolloCodegen.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public class ApolloCodegen {
2929
public static func run(from folder: URL,
3030
with cliFolderURL: URL,
3131
options: ApolloCodegenOptions) throws -> String {
32-
guard FileManager.default.apollo_folderExists(at: folder) else {
32+
guard FileManager.default.apollo.folderExists(at: folder) else {
3333
throw CodegenError.folderDoesNotExist(folder)
3434
}
3535

3636
switch options.outputFormat {
3737
case .multipleFiles(let folderURL):
38-
try FileManager.default.apollo_createFolderIfNeeded(at: folderURL)
38+
try FileManager.default.apollo.createFolderIfNeeded(at: folderURL)
3939
case .singleFile(let fileURL):
40-
try FileManager.default.apollo_createContainingFolderIfNeeded(for: fileURL)
40+
try FileManager.default.apollo.createContainingFolderIfNeeded(for: fileURL)
4141
}
4242

4343
let cli = try ApolloCLI.createCLI(cliFolderURL: cliFolderURL, timeout: options.downloadTimeout)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
public struct ApolloExtension<Base> {
4+
public let base: Base
5+
}
6+
7+
public protocol ApolloCompatible {
8+
associatedtype Base
9+
var apollo: ApolloExtension<Base> { get }
10+
static var apollo: ApolloExtension<Base>.Type { get }
11+
}
12+
13+
extension ApolloCompatible {
14+
public var apollo: ApolloExtension<Self> {
15+
ApolloExtension(base: self)
16+
}
17+
18+
public static var apollo: ApolloExtension<Self>.Type {
19+
ApolloExtension<Self>.self
20+
}
21+
}

Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct ApolloSchemaDownloader {
1515
@discardableResult
1616
public static func run(with cliFolderURL: URL,
1717
options: ApolloSchemaOptions) throws -> String {
18-
try FileManager.default.apollo_createContainingFolderIfNeeded(for: options.outputURL)
18+
try FileManager.default.apollo.createContainingFolderIfNeeded(for: options.outputURL)
1919

2020
let cli = try ApolloCLI.createCLI(cliFolderURL: cliFolderURL, timeout: options.downloadTimeout)
2121
return try cli.runApollo(with: options.arguments)

Sources/ApolloCodegenLib/CLIDownloader.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct CLIDownloader {
3939
/// - timeout: The maximum time to wait before indicating that the download timed out, in seconds.
4040
static func downloadIfNeeded(cliFolderURL: URL, timeout: Double) throws {
4141
let zipFileURL = ApolloFilePathHelper.zipFileURL(fromCLIFolder: cliFolderURL)
42-
guard !FileManager.default.apollo_fileExists(at: zipFileURL) else {
42+
guard !FileManager.default.apollo.fileExists(at: zipFileURL) else {
4343
CodegenLogger.log("Zip file with the CLI is already downloaded!")
4444
return
4545
}
@@ -54,9 +54,9 @@ struct CLIDownloader {
5454
/// - timeout: The maximum time to wait before indicating that the download timed out, in seconds.
5555
static func forceRedownload(cliFolderURL: URL, timeout: Double) throws {
5656
let zipFileURL = ApolloFilePathHelper.zipFileURL(fromCLIFolder: cliFolderURL)
57-
try FileManager.default.apollo_deleteFile(at: zipFileURL)
57+
try FileManager.default.apollo.deleteFile(at: zipFileURL)
5858
let apolloFolderURL = ApolloFilePathHelper.apolloFolderURL(fromCLIFolder: cliFolderURL)
59-
try FileManager.default.apollo_deleteFolder(at: apolloFolderURL)
59+
try FileManager.default.apollo.deleteFolder(at: apolloFolderURL)
6060

6161
try self.download(to: zipFileURL, timeout: timeout)
6262
}
@@ -67,7 +67,7 @@ struct CLIDownloader {
6767
/// - zipFileURL: The URL where downloaded data should be saved.
6868
/// - timeout: The maximum time to wait before indicating that the download timed out, in seconds.
6969
private static func download(to zipFileURL: URL, timeout: Double) throws {
70-
try FileManager.default.apollo_createContainingFolderIfNeeded(for: zipFileURL)
70+
try FileManager.default.apollo.createContainingFolderIfNeeded(for: zipFileURL)
7171

7272
CodegenLogger.log("Downloading zip file with the CLI...")
7373
let semaphore = DispatchSemaphore(value: 0)

Sources/ApolloCodegenLib/CLIExtractor.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ struct CLIExtractor {
3535
static func extractCLIIfNeeded(from cliFolderURL: URL, expectedSHASUM: String = CLIExtractor.expectedSHASUM) throws -> URL {
3636
let apolloFolderURL = ApolloFilePathHelper.apolloFolderURL(fromCLIFolder: cliFolderURL)
3737

38-
guard FileManager.default.apollo_folderExists(at: apolloFolderURL) else {
38+
guard FileManager.default.apollo.folderExists(at: apolloFolderURL) else {
3939
CodegenLogger.log("Apollo folder doesn't exist, extracting CLI from zip file.")
4040
return try self.extractCLIFromZip(cliFolderURL: cliFolderURL)
4141
}
4242

4343
guard try self.validateSHASUMInExtractedFile(apolloFolderURL: apolloFolderURL, expected: expectedSHASUM) else {
4444
CodegenLogger.log("SHASUM of extracted zip does not match expected, deleting existing folder and re-extracting.")
45-
try FileManager.default.apollo_deleteFolder(at: apolloFolderURL)
45+
try FileManager.default.apollo.deleteFolder(at: apolloFolderURL)
4646
return try self.extractCLIFromZip(cliFolderURL: cliFolderURL)
4747
}
4848

4949
let binaryFolderURL = ApolloFilePathHelper.binaryFolderURL(fromApollo: apolloFolderURL)
5050
let binaryURL = ApolloFilePathHelper.binaryURL(fromBinaryFolder: binaryFolderURL)
51-
guard FileManager.default.apollo_fileExists(at: binaryURL) else {
51+
guard FileManager.default.apollo.fileExists(at: binaryURL) else {
5252
CodegenLogger.log("There was a valid `.shasum` file, but no binary at the expected path. Deleting existing apollo folder and re-extracting.", logLevel: .warning)
53-
try FileManager.default.apollo_deleteFolder(at: apolloFolderURL)
53+
try FileManager.default.apollo.deleteFolder(at: apolloFolderURL)
5454
return try self.extractCLIFromZip(cliFolderURL: cliFolderURL, expectedSHASUM: expectedSHASUM)
5555
}
5656

@@ -65,7 +65,7 @@ struct CLIExtractor {
6565
/// - Returns: true if the shasums match, false if not.
6666
static func validateSHASUMInExtractedFile(apolloFolderURL: URL, expected: String = CLIExtractor.expectedSHASUM) throws -> Bool {
6767
let shasumFileURL = ApolloFilePathHelper.shasumFileURL(fromApollo: apolloFolderURL)
68-
guard FileManager.default.apollo_fileExists(at: shasumFileURL) else {
68+
guard FileManager.default.apollo.fileExists(at: shasumFileURL) else {
6969
return false
7070
}
7171

@@ -104,7 +104,7 @@ struct CLIExtractor {
104104
let apolloFolderURL = ApolloFilePathHelper.apolloFolderURL(fromCLIFolder: cliFolderURL)
105105
let binaryFolderURL = ApolloFilePathHelper.binaryFolderURL(fromApollo: apolloFolderURL)
106106

107-
guard FileManager.default.apollo_folderExists(at: binaryFolderURL) else {
107+
guard FileManager.default.apollo.folderExists(at: binaryFolderURL) else {
108108
throw CLIExtractorError.noBinaryFolderAfterUnzipping(atURL: binaryFolderURL)
109109
}
110110

@@ -118,7 +118,7 @@ struct CLIExtractor {
118118
/// - Parameter zipFileURL: The url to the zip file containing the Apollo CLI.
119119
/// - Parameter expected: The expected SHASUM. Defaults to the real expected SHASUM. This parameter exists mostly for testing.
120120
static func validateZipFileSHASUM(at zipFileURL: URL, expected: String = CLIExtractor.expectedSHASUM) throws {
121-
let shasum = try FileManager.default.apollo_shasum(at: zipFileURL)
121+
let shasum = try FileManager.default.apollo.shasum(at: zipFileURL)
122122
print("SHASUM: \(shasum)")
123123
guard shasum == expected else {
124124
throw CLIExtractorError.zipFileHasInvalidSHASUM(expectedSHASUM: expected, gotSHASUM: shasum)

Sources/ApolloCodegenLib/CodeGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class CodeGenerator<Decoder: FlexibleDecoder> {
6666
private func createFileWithOutput(_ output: String,
6767
named name: String,
6868
inFolder folderURL: URL) throws {
69-
try FileManager.default.apollo_createFolderIfNeeded(at: folderURL)
69+
try FileManager.default.apollo.createFolderIfNeeded(at: folderURL)
7070
let fileURL = folderURL
7171
.appendingPathComponent(name)
7272
.appendingPathExtension("swift")

Sources/ApolloCodegenLib/CodegenLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct CodegenLogger {
3939
}
4040

4141
var standardOutput = FileHandle.standardOutput
42-
print("[\(logLevel.name) - ApolloCodegenLib:\(file.apollo_lastPathComponent):\(line)] - \(logString())", to: &standardOutput)
42+
print("[\(logLevel.name) - ApolloCodegenLib:\(file.apollo.lastPathComponent):\(line)] - \(logString())", to: &standardOutput)
4343
}
4444
}
4545

Sources/ApolloCodegenLib/EnumGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class EnumGenerator {
2121

2222
init(astEnumValue: ASTEnumValue) {
2323
self.name = astEnumValue.name
24-
self.nameVariableDeclaration = astEnumValue.name.apollo_sanitizedVariableDeclaration
25-
self.nameUsage = astEnumValue.name.apollo_sanitizedVariableUsage
24+
self.nameVariableDeclaration = astEnumValue.name.apollo.sanitizedVariableDeclaration
25+
self.nameUsage = astEnumValue.name.apollo.sanitizedVariableUsage
2626
self.description = astEnumValue.description
2727
self.isDeprecated = astEnumValue.isDeprecated
2828
}

0 commit comments

Comments
 (0)