Skip to content

Commit 9aff812

Browse files
author
Tiziano Coroneo
committed
Added #if availability check to all ApolloCodeGenLib sources to prevent compilation on other platforms. This previously caused an issue that prevented SwiftUI previews on iOS targets from working properly, if that target included Apollo as a dependency.
1 parent 165f078 commit 9aff812

24 files changed

Lines changed: 120 additions & 6 deletions

Sources/ApolloCodegenLib/ASTEnumValue.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
class ASTEnumValue: Codable {
47
/// The raw name of the enum value
58
let name: String
@@ -10,3 +13,5 @@ class ASTEnumValue: Codable {
1013
/// If the enum value is deprecated.
1114
let isDeprecated: Bool
1215
}
16+
17+
#endif

Sources/ApolloCodegenLib/ASTField.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// A field with data on any item.
47
class ASTField: Codable {
58

@@ -45,3 +48,5 @@ class ASTField: Codable {
4548
/// [optional] Any Fragments defined inline at this level
4649
let inlineFragments: [ASTInlineFragment]?
4750
}
51+
52+
#endif

Sources/ApolloCodegenLib/ASTFragment.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// A resuable fragment to generate code for
47
class ASTFragment: Codable {
58
/// The primary type the fragment is defined on
@@ -41,3 +44,5 @@ class ASTInlineFragment: Codable {
4144
/// The names of any named fragments at this level of the fragment.
4245
let fragmentSpreads: [String]
4346
}
47+
48+
#endif

Sources/ApolloCodegenLib/ASTOperation.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// The representation of a single operation defined in a .graphql file.
47
class ASTOperation: Codable {
58

@@ -55,3 +58,5 @@ class ASTOperation: Codable {
5558
/// [optional] The calculated ID for the operation. Will only be generated if `operationIDsURL` is passed into `ApolloCodegenOptions`.`
5659
let operationId: String?
5760
}
61+
62+
#endif

Sources/ApolloCodegenLib/ASTOutput.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// The top-level output of the AST generator
47
class ASTOutput: Codable {
58
/// An array of all operations to generate code for.
@@ -11,3 +14,5 @@ class ASTOutput: Codable {
1114
/// An array of "all" types used <-- TODO: Figure out why some are not in here
1215
let typesUsed: [ASTTypeUsed]
1316
}
17+
18+
#endif

Sources/ApolloCodegenLib/ASTTypeUsed.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// A type to generate code for.
47
class ASTTypeUsed: Codable {
58

@@ -32,3 +35,5 @@ class ASTTypeUsed: Codable {
3235
/// [optional] Any fields used on this type
3336
let fields: [ASTTypeUsed.Field]?
3437
}
38+
39+
#endif

Sources/ApolloCodegenLib/ASTVariableType.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// Placeholder typealias while this is getting added to tooling
47
typealias ASTVariableType = String
58

@@ -60,3 +63,5 @@ class ASTForthcomingVariableType: Codable {
6063
}
6164
}
6265
}
66+
67+
#endif

Sources/ApolloCodegenLib/ApolloCLI.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// Wrapper for calling the bundled node-based Apollo CLI.
4-
@available(OSX, message: "Only available on macOS")
57
public struct ApolloCLI {
68

79
/// Creates an instance of `ApolloCLI`, downloading and extracting if needed
@@ -47,3 +49,5 @@ public struct ApolloCLI {
4749
return try Basher.run(command: command, from: folder)
4850
}
4951
}
52+
53+
#endif

Sources/ApolloCodegenLib/ApolloCodegen.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// A class to facilitate running code generation
4-
@available(OSX, message: "Only available on macOS")
57
public class ApolloCodegen {
68

79
/// Errors which can happen with code generation
@@ -42,3 +44,5 @@ public class ApolloCodegen {
4244
return try cli.runApollo(with: options.arguments, from: folder)
4345
}
4446
}
47+
48+
#endif

Sources/ApolloCodegenLib/ApolloCodegenOptions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22

3+
// Only available on macOS
4+
#if os(macOS)
5+
36
/// An object to hold all the various options for running codegen
47
public struct ApolloCodegenOptions {
58

@@ -177,3 +180,5 @@ extension ApolloCodegenOptions: CustomDebugStringConvertible {
177180
self.arguments.joined(separator: "\n")
178181
}
179182
}
183+
184+
#endif

0 commit comments

Comments
 (0)