From f7414b409e8380a94ca2ac28566cfab164033d8c Mon Sep 17 00:00:00 2001 From: gh-action-runner Date: Thu, 6 Jun 2024 18:24:00 +0000 Subject: [PATCH] Squashed 'apollo-ios-codegen/' changes from 363f942c..d48baeb7 d48baeb7 Added Existential Any requirement (apollographql/apollo-ios-dev#379) git-subtree-dir: apollo-ios-codegen git-subtree-split: d48baeb705e8ede2247e8ebbf2fae5c6fd0430df --- Package.swift | 23 ++++++++----- Sources/ApolloCodegenLib/ApolloCodegen.swift | 6 ++-- .../ApolloCodegenConfiguration.swift | 32 +++++++++---------- .../ApolloSchemaDownloadConfiguration.swift | 4 +-- .../ApolloSchemaDownloader.swift | 14 ++++---- ...ation+OperationManifestConfiguration.swift | 4 +-- .../CustomScalarFileGenerator.swift | 2 +- .../FileGenerators/EnumFileGenerator.swift | 2 +- .../FileGenerators/FileGenerator.swift | 2 +- .../FragmentFileGenerator.swift | 2 +- .../InputObjectFileGenerator.swift | 2 +- .../InterfaceFileGenerator.swift | 2 +- .../MockInterfacesFileGenerator.swift | 2 +- .../MockObjectFileGenerator.swift | 2 +- .../MockUnionsFileGenerator.swift | 2 +- .../FileGenerators/ObjectFileGenerator.swift | 2 +- .../OperationFileGenerator.swift | 2 +- .../SchemaConfigurationFileGenerator.swift | 2 +- .../SchemaMetadataFileGenerator.swift | 2 +- .../FileGenerators/UnionFileGenerator.swift | 2 +- Sources/ApolloCodegenLib/Glob.swift | 4 +-- .../OperationIdentifierFactory.swift | 2 +- .../Templates/MockObjectTemplate.swift | 2 +- .../Templates/SchemaMetadataTemplate.swift | 2 +- .../Templates/SelectionSetTemplate.swift | 6 ++-- Sources/ApolloCodegenLib/URLDownloader.swift | 12 +++---- Sources/CodegenCLI/Commands/FetchSchema.swift | 6 ++-- Sources/CodegenCLI/Commands/Generate.swift | 12 +++---- .../Commands/GenerateOperationManifest.swift | 6 ++-- .../Protocols/SchemaDownloadProvider.swift | 2 +- .../GraphQLCompiler/JavaScriptBridge.swift | 16 +++++----- Sources/IR/IR+FieldCollector.swift | 8 ++--- Sources/IR/IR+RootFieldBuilder.swift | 2 +- Sources/IR/IR+ScopeDescriptor.swift | 2 +- 34 files changed, 100 insertions(+), 93 deletions(-) diff --git a/Package.swift b/Package.swift index 3e4d10990..e794621f2 100644 --- a/Package.swift +++ b/Package.swift @@ -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 @@ -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", @@ -43,7 +44,8 @@ let package = Package( ], exclude: [ "JavaScript" - ] + ], + swiftSettings: [.enableUpcomingFeature("ExistentialAny")] ), .target( name: "IR", @@ -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", @@ -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")] ), ] ) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index eb98cc74c..58ef7a526 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -553,7 +553,7 @@ public class ApolloCodegen { extension ApolloCodegen { fileprivate func nonFatalErrorCollectingTaskGroup( - _ block: (inout ThrowingTaskGroup) async throws -> Void + _ block: (inout ThrowingTaskGroup) async throws -> Void ) async throws -> NonFatalErrors { return try await withThrowingTaskGroup( of: (NonFatalErrors.DefinitionEntry).self @@ -571,8 +571,8 @@ extension ApolloCodegen { } fileprivate func addFileGenerationTask( - for fileGenerator: FileGenerator, - to group: inout ThrowingTaskGroup, + for fileGenerator: any FileGenerator, + to group: inout ThrowingTaskGroup, fileManager: ApolloFileManager ) { let config = config diff --git a/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift b/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift index 078b31df5..7b88933c5 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift @@ -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( @@ -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) @@ -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 { @@ -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 { @@ -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 { @@ -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) @@ -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) @@ -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( @@ -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() @@ -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) @@ -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( @@ -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) @@ -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) @@ -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 = [] @@ -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 { @@ -1502,7 +1502,7 @@ private struct AnyCodingKey: CodingKey { func throwIfContainsUnexpectedKey( container: KeyedDecodingContainer, 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)) diff --git a/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift b/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift index b4b7f146f..05a63c51f 100644 --- a/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift +++ b/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift @@ -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) @@ -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) diff --git a/Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift b/Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift index 46d861c4b..5ea9fa82e 100644 --- a/Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift +++ b/Sources/ApolloCodegenLib/ApolloSchemaDownloader.swift @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration+OperationManifestConfiguration.swift b/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration+OperationManifestConfiguration.swift index fef96343b..682c9f559 100644 --- a/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration+OperationManifestConfiguration.swift +++ b/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration+OperationManifestConfiguration.swift @@ -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, @@ -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) diff --git a/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift index f3e16fd2d..6c096aa00 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift @@ -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) } diff --git a/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift index 84c627c42..e8e156c23 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift @@ -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) } diff --git a/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift index 83d24e976..beb58147f 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift @@ -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 } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift index b3c806b27..1b8bd4472 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift @@ -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 ) } diff --git a/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift index 30a1610b9..1dddd3c34 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift @@ -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 } diff --git a/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift index fb256093d..871b569c7 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift @@ -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) } diff --git a/Sources/ApolloCodegenLib/FileGenerators/MockInterfacesFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/MockInterfacesFileGenerator.swift index 1906845ef..0d7445630 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/MockInterfacesFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/MockInterfacesFileGenerator.swift @@ -18,7 +18,7 @@ struct MockInterfacesFileGenerator: FileGenerator { self.config = config } - var template: TemplateRenderer { + var template: any TemplateRenderer { MockInterfacesTemplate( graphQLInterfaces: graphQLInterfaces, config: config diff --git a/Sources/ApolloCodegenLib/FileGenerators/MockObjectFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/MockObjectFileGenerator.swift index 61f915716..9403d9f70 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/MockObjectFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/MockObjectFileGenerator.swift @@ -13,7 +13,7 @@ struct MockObjectFileGenerator: FileGenerator { let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { + var template: any TemplateRenderer { MockObjectTemplate( graphqlObject: graphqlObject, fields: fields, diff --git a/Sources/ApolloCodegenLib/FileGenerators/MockUnionsFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/MockUnionsFileGenerator.swift index 3e96e197c..577f68e63 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/MockUnionsFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/MockUnionsFileGenerator.swift @@ -18,7 +18,7 @@ struct MockUnionsFileGenerator: FileGenerator { self.config = config } - var template: TemplateRenderer { + var template: any TemplateRenderer { MockUnionsTemplate( graphQLUnions: graphQLUnions, config: config diff --git a/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift index d5512796d..40eccabc8 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift @@ -9,7 +9,7 @@ struct ObjectFileGenerator: FileGenerator { /// Shared codegen configuration. let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { + var template: any TemplateRenderer { ObjectTemplate(graphqlObject: graphqlObject, config: config) } diff --git a/Sources/ApolloCodegenLib/FileGenerators/OperationFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/OperationFileGenerator.swift index ae5ff9b70..f375235dd 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/OperationFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/OperationFileGenerator.swift @@ -10,7 +10,7 @@ struct OperationFileGenerator: FileGenerator { /// Shared codegen configuration let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { + var template: any TemplateRenderer { irOperation.definition.isLocalCacheMutation ? LocalCacheMutationDefinitionTemplate( operation: irOperation, diff --git a/Sources/ApolloCodegenLib/FileGenerators/SchemaConfigurationFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/SchemaConfigurationFileGenerator.swift index feccd14bb..8baa7f9ee 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/SchemaConfigurationFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/SchemaConfigurationFileGenerator.swift @@ -6,7 +6,7 @@ struct SchemaConfigurationFileGenerator: FileGenerator { /// Shared codegen configuration let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { SchemaConfigurationTemplate(config: config) } + var template: any TemplateRenderer { SchemaConfigurationTemplate(config: config) } var overwrite: Bool { false } var target: FileTarget { .schema } var fileName: String { "SchemaConfiguration" } diff --git a/Sources/ApolloCodegenLib/FileGenerators/SchemaMetadataFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/SchemaMetadataFileGenerator.swift index 8e3627cae..f0493ead2 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/SchemaMetadataFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/SchemaMetadataFileGenerator.swift @@ -9,7 +9,7 @@ struct SchemaMetadataFileGenerator: FileGenerator { /// Shared codegen configuration let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { SchemaMetadataTemplate(schema: schema, config: config) } + var template: any TemplateRenderer { SchemaMetadataTemplate(schema: schema, config: config) } var target: FileTarget { .schema } var fileName: String { "SchemaMetadata" } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift index 681d98241..e42d3507b 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift @@ -8,7 +8,7 @@ struct UnionFileGenerator: FileGenerator { /// Shared codegen configuration. let config: ApolloCodegen.ConfigurationContext - var template: TemplateRenderer { UnionTemplate( + var template: any TemplateRenderer { UnionTemplate( graphqlUnion: graphqlUnion, config: config ) } diff --git a/Sources/ApolloCodegenLib/Glob.swift b/Sources/ApolloCodegenLib/Glob.swift index 38184ecb9..a3096d72c 100644 --- a/Sources/ApolloCodegenLib/Glob.swift +++ b/Sources/ApolloCodegenLib/Glob.swift @@ -151,9 +151,9 @@ public struct Glob { do { let resourceKeys: [URLResourceKey] = [.isDirectoryKey] - var enumeratorError: Error? + var enumeratorError: (any Error)? - let errorHandler: ((URL, Error) -> Bool) = { url, error in + let errorHandler: ((URL, any Error) -> Bool) = { url, error in enumeratorError = error return false // aborts enumeration } diff --git a/Sources/ApolloCodegenLib/OperationIdentifierFactory.swift b/Sources/ApolloCodegenLib/OperationIdentifierFactory.swift index 4c49e8222..5e1362636 100644 --- a/Sources/ApolloCodegenLib/OperationIdentifierFactory.swift +++ b/Sources/ApolloCodegenLib/OperationIdentifierFactory.swift @@ -10,7 +10,7 @@ public typealias OperationIdentifierProvider = (_ operation: OperationDescriptor actor OperationIdentifierFactory { private enum CacheEntry { - case inProgress(Task) + case inProgress(Task) case ready(String) } diff --git a/Sources/ApolloCodegenLib/Templates/MockObjectTemplate.swift b/Sources/ApolloCodegenLib/Templates/MockObjectTemplate.swift index 684367a16..35807e9a1 100644 --- a/Sources/ApolloCodegenLib/Templates/MockObjectTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/MockObjectTemplate.swift @@ -126,7 +126,7 @@ struct MockObjectTemplate: TemplateRenderer { let mockType: String switch graphQLCompositeType { case is GraphQLInterfaceType, is GraphQLUnionType: - mockType = "AnyMock" + mockType = "(any AnyMock)" default: mockType = "Mock<\(graphQLCompositeType.formattedName)>" } diff --git a/Sources/ApolloCodegenLib/Templates/SchemaMetadataTemplate.swift b/Sources/ApolloCodegenLib/Templates/SchemaMetadataTemplate.swift index 897008434..f91b66f14 100644 --- a/Sources/ApolloCodegenLib/Templates/SchemaMetadataTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SchemaMetadataTemplate.swift @@ -37,7 +37,7 @@ struct SchemaMetadataTemplate: TemplateRenderer { \(documentation: schema.documentation, config: config) \(parentAccessLevel)enum SchemaMetadata: \(config.ApolloAPITargetName).SchemaMetadata { \(accessControlModifier(for: .member))\ - static let configuration: \(config.ApolloAPITargetName).SchemaConfiguration.Type = SchemaConfiguration.self + static let configuration: any \(config.ApolloAPITargetName).SchemaConfiguration.Type = SchemaConfiguration.self \(objectTypeFunction) } diff --git a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift index d8d0d0b44..b43909540 100644 --- a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift @@ -7,7 +7,7 @@ import Utilities struct SelectionSetTemplate { - let definition: IR.Definition + let definition: any IR.Definition let generateInitializers: Bool let config: ApolloCodegen.ConfigurationContext let nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder @@ -18,7 +18,7 @@ struct SelectionSetTemplate { var isMutable: Bool { definition.isMutable } init( - definition: IR.Definition, + definition: any IR.Definition, generateInitializers: Bool, config: ApolloCodegen.ConfigurationContext, nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder, @@ -236,7 +236,7 @@ struct SelectionSetTemplate { private func ParentTypeTemplate(_ type: GraphQLCompositeType) -> String { """ \(renderAccessControl())\ - static var __parentType: \(config.ApolloAPITargetName).ParentType { \ + static var __parentType: any \(config.ApolloAPITargetName).ParentType { \ \(GeneratedSchemaTypeReference(type)) } """ } diff --git a/Sources/ApolloCodegenLib/URLDownloader.swift b/Sources/ApolloCodegenLib/URLDownloader.swift index fea901330..cce10ba57 100644 --- a/Sources/ApolloCodegenLib/URLDownloader.swift +++ b/Sources/ApolloCodegenLib/URLDownloader.swift @@ -13,14 +13,14 @@ public protocol NetworkSession { /// to `resume`. @discardableResult func loadData( with urlRequest: URLRequest, - completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void + completionHandler: @escaping (Data?, URLResponse?, (any Error)?) -> Void ) -> URLSessionDataTask? } extension URLSession: NetworkSession { public func loadData( with urlRequest: URLRequest, - completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void + completionHandler: @escaping (Data?, URLResponse?, (any Error)?) -> Void ) -> URLSessionDataTask? { let task = dataTask(with: urlRequest) { (data, response, error) in completionHandler(data, response, error) @@ -33,7 +33,7 @@ extension URLSession: NetworkSession { /// A class to help download things from a given remote URL to a given local file URL class URLDownloader { - let session: NetworkSession + let session: any NetworkSession enum DownloadError: Swift.Error, LocalizedError { case badResponse(code: Int, response: String?) @@ -63,7 +63,7 @@ class URLDownloader { /// - Parameters: /// - session: The NetworkSession conforming instance used for downloads, defaults to the /// shared URLSession singleton object. - init(session: NetworkSession? = nil) { + init(session: (any NetworkSession)? = nil) { self.session = session ?? URLSession.shared } @@ -80,10 +80,10 @@ class URLDownloader { timeout: Double ) throws { let semaphore = DispatchSemaphore(value: 0) - var errorToThrow: Error? = DownloadError.downloadTimedOut(after: timeout) + var errorToThrow: (any Error)? = DownloadError.downloadTimedOut(after: timeout) session.loadData(with: request) { data, response, error in - func finished(_ error: Error? = nil) { + func finished(_ error: (any Error)? = nil) { errorToThrow = error semaphore.signal() } diff --git a/Sources/CodegenCLI/Commands/FetchSchema.swift b/Sources/CodegenCLI/Commands/FetchSchema.swift index b853d6efe..bd11e2f2b 100644 --- a/Sources/CodegenCLI/Commands/FetchSchema.swift +++ b/Sources/CodegenCLI/Commands/FetchSchema.swift @@ -23,8 +23,8 @@ public struct FetchSchema: AsyncParsableCommand { func _run( fileManager: FileManager = .default, - schemaDownloadProvider: SchemaDownloadProvider.Type = ApolloSchemaDownloader.self, - logger: LogLevelSetter.Type = CodegenLogger.self + schemaDownloadProvider: any SchemaDownloadProvider.Type = ApolloSchemaDownloader.self, + logger: any LogLevelSetter.Type = CodegenLogger.self ) async throws { logger.SetLoggingLevel(verbose: inputs.verbose) @@ -36,7 +36,7 @@ public struct FetchSchema: AsyncParsableCommand { private func fetchSchema( configuration codegenConfiguration: ApolloCodegenConfiguration, - schemaDownloadProvider: SchemaDownloadProvider.Type + schemaDownloadProvider: any SchemaDownloadProvider.Type ) async throws { guard let schemaDownload = codegenConfiguration.schemaDownload else { throw Error(errorDescription: """ diff --git a/Sources/CodegenCLI/Commands/Generate.swift b/Sources/CodegenCLI/Commands/Generate.swift index 1264ae959..2e7f2bab3 100644 --- a/Sources/CodegenCLI/Commands/Generate.swift +++ b/Sources/CodegenCLI/Commands/Generate.swift @@ -29,9 +29,9 @@ public struct Generate: AsyncParsableCommand { func _run( fileManager: FileManager = .default, projectRootURL: URL? = nil, - codegenProvider: CodegenProvider.Type = ApolloCodegen.self, - schemaDownloadProvider: SchemaDownloadProvider.Type = ApolloSchemaDownloader.self, - logger: LogLevelSetter.Type = CodegenLogger.self + codegenProvider: any CodegenProvider.Type = ApolloCodegen.self, + schemaDownloadProvider: any SchemaDownloadProvider.Type = ApolloSchemaDownloader.self, + logger: any LogLevelSetter.Type = CodegenLogger.self ) async throws { logger.SetLoggingLevel(verbose: inputs.verbose) @@ -49,8 +49,8 @@ public struct Generate: AsyncParsableCommand { private func generate( configuration: ApolloCodegenConfiguration, - codegenProvider: CodegenProvider.Type, - schemaDownloadProvider: SchemaDownloadProvider.Type + codegenProvider: any CodegenProvider.Type, + schemaDownloadProvider: any SchemaDownloadProvider.Type ) async throws { if fetchSchema { guard @@ -86,7 +86,7 @@ public struct Generate: AsyncParsableCommand { private func fetchSchema( configuration: ApolloSchemaDownloadConfiguration, - schemaDownloadProvider: SchemaDownloadProvider.Type + schemaDownloadProvider: any SchemaDownloadProvider.Type ) async throws { try await schemaDownloadProvider.fetch( configuration: configuration, diff --git a/Sources/CodegenCLI/Commands/GenerateOperationManifest.swift b/Sources/CodegenCLI/Commands/GenerateOperationManifest.swift index 67cd210a9..d7a1e8b7e 100644 --- a/Sources/CodegenCLI/Commands/GenerateOperationManifest.swift +++ b/Sources/CodegenCLI/Commands/GenerateOperationManifest.swift @@ -23,8 +23,8 @@ public struct GenerateOperationManifest: AsyncParsableCommand { func _run( fileManager: FileManager = .default, projectRootURL: URL? = nil, - codegenProvider: CodegenProvider.Type = ApolloCodegen.self, - logger: LogLevelSetter.Type = CodegenLogger.self + codegenProvider: any CodegenProvider.Type = ApolloCodegen.self, + logger: any LogLevelSetter.Type = CodegenLogger.self ) async throws { logger.SetLoggingLevel(verbose: inputs.verbose) @@ -40,7 +40,7 @@ public struct GenerateOperationManifest: AsyncParsableCommand { private func generateManifest( configuration: ApolloCodegenConfiguration, - codegenProvider: CodegenProvider.Type + codegenProvider: any CodegenProvider.Type ) async throws { try await codegenProvider.build( with: configuration, diff --git a/Sources/CodegenCLI/Protocols/SchemaDownloadProvider.swift b/Sources/CodegenCLI/Protocols/SchemaDownloadProvider.swift index f8bbc3b8f..2f39ceaa6 100644 --- a/Sources/CodegenCLI/Protocols/SchemaDownloadProvider.swift +++ b/Sources/CodegenCLI/Protocols/SchemaDownloadProvider.swift @@ -6,7 +6,7 @@ public protocol SchemaDownloadProvider { static func fetch( configuration: ApolloSchemaDownloadConfiguration, withRootURL rootURL: URL?, - session: NetworkSession? + session: (any NetworkSession)? ) async throws } diff --git a/Sources/GraphQLCompiler/JavaScriptBridge.swift b/Sources/GraphQLCompiler/JavaScriptBridge.swift index 5b6fa234f..0f5a3578b 100644 --- a/Sources/GraphQLCompiler/JavaScriptBridge.swift +++ b/Sources/GraphQLCompiler/JavaScriptBridge.swift @@ -215,7 +215,7 @@ actor JavaScriptBridge { // We keep a bidirectional mapping between constructors and wrapper types so we can both access the // corresponding wrapper type, and perform an `instanceof` check based on the corresponding constructor // for the expected wrapper type in case there isn't a direct match and we are receiving a subtype. - private var constructorToWrapperType: [JSValue /* constructor function */: JavaScriptObjectDecodable.Type] = [:] + private var constructorToWrapperType: [JSValue /* constructor function */: any JavaScriptObjectDecodable.Type] = [:] private var wrapperTypeToConstructor: [AnyHashable /* JavaScriptObjectDecodable.Type */: JSValue] = [:] /// We keep a map between `JSValue` objects and wrapper objects, to avoid repeatedly creating new @@ -238,7 +238,7 @@ actor JavaScriptBridge { } public func register( - _ wrapperType: JavaScriptObjectDecodable.Type, + _ wrapperType: any JavaScriptObjectDecodable.Type, forJavaScriptClass className: String? = nil, from scope: JSValue ) { @@ -252,9 +252,9 @@ actor JavaScriptBridge { } public func register( - _ wrapperType: JavaScriptObjectDecodable.Type, + _ wrapperType: any JavaScriptObjectDecodable.Type, forJavaScriptClass className: String? = nil, - from scope: JavaScriptCallable + from scope: any JavaScriptCallable ) { register(wrapperType, forJavaScriptClass: className, from: scope.jsValue) } @@ -275,7 +275,7 @@ actor JavaScriptBridge { defaultType: Wrapper.self ) - guard let wrapperType = wrapperType as? JavaScriptReferencedObject.Type else { + guard let wrapperType = wrapperType as? any JavaScriptReferencedObject.Type else { preconditionFailure("Expected JavaScriptReferencedObject.Type, got \(wrapperType).") } @@ -287,8 +287,8 @@ actor JavaScriptBridge { private func wrapperTypeForInitializingObject( from jsValue: JSValue, - defaultType: JavaScriptObjectDecodable.Type - ) -> JavaScriptObjectDecodable.Type { + defaultType: any JavaScriptObjectDecodable.Type + ) -> any JavaScriptObjectDecodable.Type { let constructor = jsValue["constructor"] // If an object doesn't have a prototype or has `Object` as its direct prototype, @@ -447,7 +447,7 @@ actor JavaScriptBridge { defaultType: JavaScriptError.self ) - guard let errorType = errorType as? JavaScriptErrorType.Type else { + guard let errorType = errorType as? any JavaScriptErrorType.Type else { throw Error.unrecognizedJavaScriptErrorThrown(exception) } diff --git a/Sources/IR/IR+FieldCollector.swift b/Sources/IR/IR+FieldCollector.swift index 3e618fc4a..b4327f196 100644 --- a/Sources/IR/IR+FieldCollector.swift +++ b/Sources/IR/IR+FieldCollector.swift @@ -9,7 +9,7 @@ public actor FieldCollector { ] = [:] func collectFields(from selectionSet: CompilationResult.SelectionSet) { - guard let type = selectionSet.parentType as? GraphQLInterfaceImplementingType else { return } + guard let type = selectionSet.parentType as? (any GraphQLInterfaceImplementingType) else { return } for case let .field(field) in selectionSet.selections { add(field: field, to: type) } @@ -17,7 +17,7 @@ public actor FieldCollector { func add( fields: T, - to type: GraphQLInterfaceImplementingType + to type: any GraphQLInterfaceImplementingType ) where T.Element == CompilationResult.Field { for field in fields { add(field: field, to: type) @@ -26,7 +26,7 @@ public actor FieldCollector { func add( field: CompilationResult.Field, - to type: GraphQLInterfaceImplementingType + to type: any GraphQLInterfaceImplementingType ) { var fields = collectedFields[type] ?? [:] add(field, to: &fields) @@ -44,7 +44,7 @@ public actor FieldCollector { } public func collectedFields( - for type: GraphQLInterfaceImplementingType + for type: any GraphQLInterfaceImplementingType ) -> [(String, GraphQLType, deprecationReason: String?)] { var fields = collectedFields[type] ?? [:] diff --git a/Sources/IR/IR+RootFieldBuilder.swift b/Sources/IR/IR+RootFieldBuilder.swift index 967c46b4c..c9cdbfd65 100644 --- a/Sources/IR/IR+RootFieldBuilder.swift +++ b/Sources/IR/IR+RootFieldBuilder.swift @@ -270,7 +270,7 @@ class RootFieldBuilder { } private func scopeCondition( - for conditionalSelectionSet: ConditionallyIncludable, + for conditionalSelectionSet: any ConditionallyIncludable, in parentTypePath: SelectionSet.TypeInfo, isDeferred: Bool = false ) -> ScopeCondition? { diff --git a/Sources/IR/IR+ScopeDescriptor.swift b/Sources/IR/IR+ScopeDescriptor.swift index bd3fd316a..d1238cadc 100644 --- a/Sources/IR/IR+ScopeDescriptor.swift +++ b/Sources/IR/IR+ScopeDescriptor.swift @@ -130,7 +130,7 @@ public struct ScopeDescriptor: Hashable, CustomDebugStringConvertible { var newScope = scope ?? [] newScope.append(newType) - if let newType = newType as? GraphQLInterfaceImplementingType { + if let newType = newType as? (any GraphQLInterfaceImplementingType) { newScope.formUnion(newType.interfaces) }