Skip to content

Commit

Permalink
Squashed 'apollo-ios-codegen/' changes from 363f942c..d48baeb7
Browse files Browse the repository at this point in the history
d48baeb7 Added Existential Any requirement (#379)

git-subtree-dir: apollo-ios-codegen
git-subtree-split: d48baeb705e8ede2247e8ebbf2fae5c6fd0430df
  • Loading branch information
gh-action-runner authored and gh-action-runner committed Jun 6, 2024
1 parent a507b72 commit f7414b4
Show file tree
Hide file tree
Showing 34 changed files with 100 additions and 93 deletions.
23 changes: 15 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -33,7 +33,8 @@ let package = Package(
"TemplateString",
.product(name: "InflectorKit", package: "InflectorKit"),
.product(name: "OrderedCollections", package: "swift-collections")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "GraphQLCompiler",
Expand All @@ -43,7 +44,8 @@ let package = Package(
],
exclude: [
"JavaScript"
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "IR",
Expand All @@ -52,15 +54,18 @@ let package = Package(
"TemplateString",
"Utilities",
.product(name: "OrderedCollections", package: "swift-collections")
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "TemplateString",
dependencies: []
dependencies: [],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "Utilities",
dependencies: []
dependencies: [],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.executableTarget(
name: "apollo-ios-cli",
Expand All @@ -69,14 +74,16 @@ let package = Package(
],
exclude: [
"README.md",
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.target(
name: "CodegenCLI",
dependencies: [
"ApolloCodegenLib",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
]
)
6 changes: 3 additions & 3 deletions Sources/ApolloCodegenLib/ApolloCodegen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public class ApolloCodegen {

extension ApolloCodegen {
fileprivate func nonFatalErrorCollectingTaskGroup(
_ block: (inout ThrowingTaskGroup<NonFatalErrors.DefinitionEntry, Swift.Error>) async throws -> Void
_ block: (inout ThrowingTaskGroup<NonFatalErrors.DefinitionEntry, any Swift.Error>) async throws -> Void
) async throws -> NonFatalErrors {
return try await withThrowingTaskGroup(
of: (NonFatalErrors.DefinitionEntry).self
Expand All @@ -571,8 +571,8 @@ extension ApolloCodegen {
}

fileprivate func addFileGenerationTask(
for fileGenerator: FileGenerator,
to group: inout ThrowingTaskGroup<ApolloCodegen.NonFatalErrors.DefinitionEntry, Swift.Error>,
for fileGenerator: any FileGenerator,
to group: inout ThrowingTaskGroup<ApolloCodegen.NonFatalErrors.DefinitionEntry, any Swift.Error>,
fileManager: ApolloFileManager
) {
let config = config
Expand Down
32 changes: 16 additions & 16 deletions Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {

/// `Decodable` implementation to allow for properties to be optional in the encoded JSON with
/// specified defaults when not present.
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
try throwIfContainsUnexpectedKey(container: values, type: Self.self, decoder: decoder)
schemaTypes = try values.decode(
Expand All @@ -232,7 +232,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
)
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(self.schemaTypes, forKey: .schemaTypes)
Expand Down Expand Up @@ -294,7 +294,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
/// location.
case other

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

guard let key = container.allKeys.first else {
Expand Down Expand Up @@ -344,7 +344,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
/// control the visibility of generated code, defaults to `.public`.
case absolute(path: String, accessModifier: AccessModifier = .public)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

guard let key = container.allKeys.first else {
Expand Down Expand Up @@ -414,7 +414,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
/// will fail.
case swiftPackage(targetName: String? = nil)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

guard let key = container.allKeys.first else {
Expand Down Expand Up @@ -581,7 +581,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
case markOperationDefinitionsAsFinal
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
try throwIfContainsUnexpectedKey(container: values, type: Self.self, decoder: decoder)

Expand Down Expand Up @@ -641,7 +641,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
) ?? Default.markOperationDefinitionsAsFinal
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(self.additionalInflectionRules, forKey: .additionalInflectionRules)
Expand Down Expand Up @@ -744,7 +744,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
}

@available(*, deprecated) // Deprecation attribute added to supress warning.
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
guard values.allKeys.first != nil else {
throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init(
Expand Down Expand Up @@ -804,7 +804,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
case operationId
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
self = OperationDocumentFormat(rawValue: 0)

var container = try decoder.unkeyedContainer()
Expand All @@ -828,7 +828,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
}
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.unkeyedContainer()
if self.contains(.definition) {
try container.encode(CodingKeys.definition.rawValue)
Expand Down Expand Up @@ -931,7 +931,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
case legacySafelistingCompatibleOperations
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)

legacySafelistingCompatibleOperations = try values.decodeIfPresent(
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
case operationManifest
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(self.schemaNamespace, forKey: .schemaNamespace)
Expand All @@ -1033,7 +1033,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
try throwIfContainsUnexpectedKey(container: values, type: Self.self, decoder: decoder)

Expand Down Expand Up @@ -1177,7 +1177,7 @@ extension ApolloCodegenConfiguration.SelectionSetInitializers {
case definitionsNamed
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
try throwIfContainsUnexpectedKey(container: values, type: Self.self, decoder: decoder)
var options: Options = []
Expand All @@ -1198,7 +1198,7 @@ extension ApolloCodegenConfiguration.SelectionSetInitializers {
forKey: .definitionsNamed) ?? []
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

func encodeIfPresent(option: Options, forKey key: CodingKeys) throws {
Expand Down Expand Up @@ -1502,7 +1502,7 @@ private struct AnyCodingKey: CodingKey {
func throwIfContainsUnexpectedKey<T, C: CodingKey & CaseIterable>(
container: KeyedDecodingContainer<C>,
type: T.Type,
decoder: Decoder
decoder: any Decoder
) throws {
// Map all keys from the input object
let allKeys = Set(try decoder.container(keyedBy: AnyCodingKey.self).allKeys.map(\.stringValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct ApolloSchemaDownloadConfiguration: Equatable, Codable {
case variant
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.apiKey = try container.decode(String.self, forKey: .apiKey)
Expand Down Expand Up @@ -185,7 +185,7 @@ public struct ApolloSchemaDownloadConfiguration: Equatable, Codable {
case outputPath
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.downloadMethod = try container.decode(DownloadMethod.self, forKey: .downloadMethod)
Expand Down
14 changes: 7 additions & 7 deletions Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import GraphQLCompiler
public struct ApolloSchemaDownloader {

public enum SchemaDownloadError: Swift.Error, LocalizedError {
case downloadedRegistryJSONFileNotFound(underlying: Error)
case downloadedIntrospectionJSONFileNotFound(underlying: Error)
case couldNotParseRegistryJSON(underlying: Error)
case downloadedRegistryJSONFileNotFound(underlying: any Error)
case downloadedIntrospectionJSONFileNotFound(underlying: any Error)
case couldNotParseRegistryJSON(underlying: any Error)
case unexpectedRegistryJSONType
case couldNotExtractSDLFromRegistryJSON
case couldNotCreateSDLDataToWrite(schema: String)
case couldNotConvertIntrospectionJSONToSDL(underlying: Error)
case couldNotConvertIntrospectionJSONToSDL(underlying: any Error)
case couldNotCreateURLComponentsFromEndpointURL(url: URL)
case couldNotGetURLFromURLComponents(components: URLComponents)

Expand Down Expand Up @@ -54,7 +54,7 @@ public struct ApolloSchemaDownloader {
public static func fetch(
configuration: ApolloSchemaDownloadConfiguration,
withRootURL rootURL: URL? = nil,
session: NetworkSession? = nil
session: (any NetworkSession)? = nil
) async throws {
try ApolloFileManager.default.createContainingDirectoryIfNeeded(
forPath: configuration.outputPath
Expand Down Expand Up @@ -143,7 +143,7 @@ public struct ApolloSchemaDownloader {
registry: ApolloSchemaDownloadConfiguration.DownloadMethod.ApolloRegistrySettings,
configuration: ApolloSchemaDownloadConfiguration,
withRootURL rootURL: URL?,
session: NetworkSession? = nil
session: (any NetworkSession)? = nil
) async throws {
CodegenLogger.log("Downloading schema from registry", logLevel: .debug)

Expand Down Expand Up @@ -347,7 +347,7 @@ public struct ApolloSchemaDownloader {
includeDeprecatedInputValues: Bool,
configuration: ApolloSchemaDownloadConfiguration,
withRootURL: URL?,
session: NetworkSession? = nil
session: (any NetworkSession)? = nil
) async throws {

CodegenLogger.log("Downloading schema via introspection from \(endpoint)", logLevel: .debug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension ApolloCodegenConfiguration {
case generateManifestOnCodeGeneration
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
try throwIfContainsUnexpectedKey(
container: values,
Expand All @@ -78,7 +78,7 @@ extension ApolloCodegenConfiguration {
)
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(self.path, forKey: .path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct CustomScalarFileGenerator: FileGenerator {
/// Shared codegen configuration.
let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer {
var template: any TemplateRenderer {
CustomScalarTemplate(graphqlScalar: graphqlScalar, config: config)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct EnumFileGenerator: FileGenerator {
/// Shared codegen configuration.
let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer {
var template: any TemplateRenderer {
EnumTemplate(graphqlEnum: graphqlEnum, config: config)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protocol FileGenerator {
var fileName: String { get }
var fileExtension: String { get }
var overwrite: Bool { get }
var template: TemplateRenderer { get }
var template: any TemplateRenderer { get }
var target: FileTarget { get }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct FragmentFileGenerator: FileGenerator {
/// Shared codegen configuration.
let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer { FragmentTemplate(
var template: any TemplateRenderer { FragmentTemplate(
fragment: irFragment,
config: config
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct InputObjectFileGenerator: FileGenerator {
/// Shared codegen configuration.
let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer {
var template: any TemplateRenderer {
InputObjectTemplate(graphqlInputObject: graphqlInputObject, config: config)
}
var target: FileTarget { .inputObject }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct InterfaceFileGenerator: FileGenerator {
/// Shared codegen configuration.
let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer {
var template: any TemplateRenderer {
InterfaceTemplate(graphqlInterface: graphqlInterface, config: config)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct MockInterfacesFileGenerator: FileGenerator {
self.config = config
}

var template: TemplateRenderer {
var template: any TemplateRenderer {
MockInterfacesTemplate(
graphQLInterfaces: graphQLInterfaces,
config: config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct MockObjectFileGenerator: FileGenerator {

let config: ApolloCodegen.ConfigurationContext

var template: TemplateRenderer {
var template: any TemplateRenderer {
MockObjectTemplate(
graphqlObject: graphqlObject,
fields: fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct MockUnionsFileGenerator: FileGenerator {
self.config = config
}

var template: TemplateRenderer {
var template: any TemplateRenderer {
MockUnionsTemplate(
graphQLUnions: graphQLUnions,
config: config
Expand Down
Loading

0 comments on commit f7414b4

Please sign in to comment.