From b32dcc9e13ff25fd5c88b22315b35c2cc4fcd3f9 Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:39:35 -0500 Subject: [PATCH 01/10] Codegen config options and tests Setup codegen config options and tests for new spm module type version --- ...olloCodegenConfigurationCodableTests.swift | 513 ++++++++++++++++++ .../ApolloCodegenTests.swift | 42 +- .../FileGenerators/FileGeneratorTests.swift | 2 +- .../FileGenerator_ResolvePath_Tests.swift | 84 +-- .../OperationManifestFileGeneratorTests.swift | 4 +- .../SchemaModuleFileGeneratorTests.swift | 2 +- .../Templates/CustomScalarTemplateTests.swift | 2 +- .../Templates/EnumTemplateTests.swift | 2 +- .../Templates/FragmentTemplateTests.swift | 2 +- .../Templates/InputObjectTemplateTests.swift | 46 +- ...CacheMutationDefinitionTemplateTests.swift | 12 +- .../Templates/MockObjectTemplateTests.swift | 28 +- .../Templates/ObjectTemplateTests.swift | 2 +- ...efinitionTemplate_DocumentType_Tests.swift | 12 +- ...nDefinition_VariableDefinition_Tests.swift | 6 +- .../SchemaConfigurationTemplateTests.swift | 2 +- .../SchemaMetadataTemplateTests.swift | 6 +- .../SelectionSetTemplateTests.swift | 24 +- ...ctionSetTemplate_ErrorHandling_Tests.swift | 4 +- ...ectionSetTemplate_Initializers_Tests.swift | 14 +- ...SetTemplate_LocalCacheMutation_Tests.swift | 2 +- ...TemplateRenderer_OperationFile_Tests.swift | 24 +- .../TemplateRenderer_SchemaFile_Tests.swift | 66 +-- .../TemplateRenderer_TestMockFile_Tests.swift | 14 +- .../Templates/UnionTemplateTests.swift | 2 +- .../Commands/GenerateTests.swift | 2 +- .../Commands/InitializeTests.swift | 2 +- .../MockApolloCodegenConfiguration.swift | 2 +- .../ApolloCodegenConfiguration.swift | 58 +- .../ConfigurationValidation.swift | 2 +- .../FileGenerators/FileGenerator.swift | 6 +- 31 files changed, 778 insertions(+), 211 deletions(-) rename apollo-ios-codegen/Sources/ApolloCodegenLib/{ => CodegenConfiguration}/ApolloCodegenConfiguration.swift (97%) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index aee606c90..b994d1691 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1238,4 +1238,517 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { XCTAssertEqual(context.debugDescription, "Unrecognized keys found: contact_info, motto") } } + + // MARK: Module Type Tests + + func test__codableSPMModuleType_noVersionProvided() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager() + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + "version" : { + "default" : { + + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + print("Actual JSON - \(actualJSON)") + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_defaultVersion() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager(version: .default) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + "version" : { + "default" : { + + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + print("Actual JSON - \(actualJSON)") + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withBranchVersion() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager(version: .branch(name: "branchName")) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + "version" : { + "branch" : { + "name" : "branchName" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + print("Actual JSON - \(actualJSON)") + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withCommitHashVersion() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager(version: .commitHash(hash: "hash")) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + "version" : { + "commitHash" : { + "hash" : "hash" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + print("Actual JSON - \(actualJSON)") + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withLocalPathVersion() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager(version: .localPath(path: "path")) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + "version" : { + "localPath" : { + "path" : "path" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + print("Actual JSON - \(actualJSON)") + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + } diff --git a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift index 9a58e9c02..8d5f99512 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift @@ -640,7 +640,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule, path: directoryURL.path ) @@ -756,7 +756,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: operationsOutputURL.path), path: directoryURL.path ) @@ -862,7 +862,7 @@ class ApolloCodegenTests: XCTestCase { input: .init(schemaPath: schemaPath, operationSearchPaths: [operationsPath]), output: .init( schemaTypes: .init(path: directoryURL.path, - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule, testMocks: .absolute(path: directoryURL.appendingPathComponent("TestMocks").path) ) @@ -938,7 +938,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule, path: "./RelativePath" ) @@ -1051,7 +1051,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "./RelativeOperations"), path: "./RelativePath" ) @@ -1183,7 +1183,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule ), options: .init(pruneGeneratedFiles: false) @@ -1241,7 +1241,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule ) ) @@ -1295,7 +1295,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .absolute(path: "OperationPath") ) ) @@ -1364,7 +1364,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: nil) ) ) @@ -1437,7 +1437,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: nil) ) ) @@ -1489,7 +1489,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: schemaDirectory, - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: relativeSubPath) ), options: .init( @@ -1586,7 +1586,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: "subpath") ) ) @@ -1694,7 +1694,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: "subpath") ) ) @@ -1796,7 +1796,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .relative(subpath: "subpath") ) ) @@ -1860,7 +1860,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule, testMocks: .absolute(path: absolutePath) ) @@ -1917,7 +1917,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), testMocks: .swiftPackage() ) ) @@ -1975,7 +1975,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), testMocks: .swiftPackage(targetName: testMockTargetName) ) ) @@ -2285,7 +2285,7 @@ class ApolloCodegenTests: XCTestCase { func test__validation__givenSchemaTypesModule_swiftPackageManager_withCocoapodsCompatibleImportStatements_true_shouldThrow() throws { // given let config = ApolloCodegenConfiguration.mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(cocoapodsCompatibleImportStatements: true) ) @@ -2301,7 +2301,7 @@ class ApolloCodegenTests: XCTestCase { func test__validation__givenSchemaTypesModule_swiftPackageManager_withCocoapodsCompatibleImportStatements_false_shouldNotThrow() throws { // given let config = ApolloCodegenConfiguration.mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(cocoapodsCompatibleImportStatements: false) ) @@ -2387,7 +2387,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule ) ) @@ -2538,7 +2538,7 @@ class ApolloCodegenTests: XCTestCase { input: .init(schemaPath: schemaPath, operationSearchPaths: [operationsPath]), output: .init( schemaTypes: .init(path: directoryURL.path, - moduleType: .swiftPackageManager), + moduleType: .swiftPackageManager()), operations: .inSchemaModule ), options: .init( diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift index 32b74170a..3d3c985d8 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift @@ -30,7 +30,7 @@ class FileGeneratorTests: XCTestCase { private func buildConfig() { let mockedConfig = ApolloCodegenConfiguration.mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule )) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift index f4fd41a06..f3b15d42f 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift @@ -143,7 +143,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -162,7 +162,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -180,7 +180,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -198,7 +198,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -356,7 +356,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -375,7 +375,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -393,7 +393,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -411,7 +411,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -569,7 +569,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -588,7 +588,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -606,7 +606,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -624,7 +624,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -782,7 +782,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -801,7 +801,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -819,7 +819,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -837,7 +837,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -995,7 +995,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1014,7 +1014,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1032,7 +1032,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1050,7 +1050,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1208,7 +1208,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1227,7 +1227,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1245,7 +1245,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1263,7 +1263,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1421,7 +1421,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1439,7 +1439,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager, operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1456,7 +1456,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1473,7 +1473,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1622,7 +1622,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .fragment(irFragment.definition) // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1642,7 +1642,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager, operations: .absolute(path: path)) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Fragments" @@ -1658,7 +1658,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .fragment(irFragment.definition) // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = deleteLastPathComponent(irFragment.definition.filePath) @@ -1675,7 +1675,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "NewPath" - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: path)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: path)) let expected = deleteLastPathComponent(irFragment.definition.filePath, appending: path) @@ -1832,7 +1832,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1852,7 +1852,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1872,7 +1872,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager, operations: .inSchemaModule) + buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1893,7 +1893,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager, operations: .absolute(path: path)) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Queries" @@ -1910,7 +1910,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager, operations: .absolute(path: path)) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Mutations" @@ -1927,7 +1927,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager, operations: .absolute(path: path)) + buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Subscriptions" @@ -1943,7 +1943,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) let expected = deleteLastPathComponent(irOperation.definition.filePath) @@ -1960,7 +1960,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "NewPath" - buildConfig(module: .swiftPackageManager, operations: .relative(subpath: path)) + buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: path)) let expected = deleteLastPathComponent(irOperation.definition.filePath, appending: path) @@ -2265,7 +2265,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when buildConfig( - module: .swiftPackageManager, + module: .swiftPackageManager(), operations: .inSchemaModule, testMocks: .swiftPackage() ) @@ -2286,7 +2286,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when buildConfig( - module: .swiftPackageManager, + module: .swiftPackageManager(), operations: .inSchemaModule, testMocks: .swiftPackage(targetName: "CustomMockTarget") ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift index 5aeea32ec..74c2f5b49 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift @@ -33,7 +33,7 @@ class OperationManifestFileGeneratorTests: XCTestCase { subject = OperationManifestFileGenerator( config: ApolloCodegen.ConfigurationContext(config: ApolloCodegenConfiguration.mock( output: .init( - schemaTypes: .init(path: "", moduleType: .swiftPackageManager) + schemaTypes: .init(path: "", moduleType: .swiftPackageManager()) ), operationManifest: manifest )) @@ -46,7 +46,7 @@ class OperationManifestFileGeneratorTests: XCTestCase { // given let config = ApolloCodegenConfiguration.mock( output: .init( - schemaTypes: .init(path: "", moduleType: .swiftPackageManager) + schemaTypes: .init(path: "", moduleType: .swiftPackageManager()) ), operationManifest: .init( path: "a/file/path" diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift index f8826be32..cc6abdc83 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift @@ -30,7 +30,7 @@ class SchemaModuleFileGeneratorTests: XCTestCase { let fileURL = rootURL.appendingPathComponent("Package.swift") let configuration = ApolloCodegen.ConfigurationContext(config: ApolloCodegenConfiguration.mock( - .swiftPackageManager, + .swiftPackageManager(), to: rootURL.path )) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift index 4d0a61041..92d35d683 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift @@ -99,7 +99,7 @@ class CustomScalarTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesTypealias_withPublicAccess() { // given - buildSubject(config: .mock(.swiftPackageManager)) + buildSubject(config: .mock(.swiftPackageManager())) let expected = """ public typealias MyCustomScalar = String diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift index ff1ebbff7..1cca7158f 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift @@ -56,7 +56,7 @@ class EnumTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesSwiftEnum_withPublicAccess() { // given - buildSubject(config: .mock(.swiftPackageManager)) + buildSubject(config: .mock(.swiftPackageManager())) let expected = """ public enum TestEnum: String, EnumType { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift index 8fc52f075..d4d851d16 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift @@ -352,7 +352,7 @@ class FragmentTemplateTests: XCTestCase { func test__render__givenModuleType_swiftPackageManager_generatesFragmentDefinition_withPublicAccess() async throws { // given - try await buildSubjectAndFragment(config: .mock(.swiftPackageManager)) + try await buildSubjectAndFragment(config: .mock(.swiftPackageManager())) let expected = """ public struct TestFragment: TestSchema.SelectionSet, Fragment { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift index 7bc49141c..99c514660 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift @@ -17,7 +17,7 @@ class InputObjectTemplateTests: XCTestCase { customName: String? = nil, fields: [GraphQLInputField] = [], documentation: String? = nil, - config: ApolloCodegenConfiguration = .mock(.swiftPackageManager) + config: ApolloCodegenConfiguration = .mock(.swiftPackageManager()) ) { let inputObject = GraphQLInputObjectType.mock( name, @@ -80,7 +80,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil ) ], - config: .mock(.swiftPackageManager) + config: .mock(.swiftPackageManager()) ) let expected = """ @@ -539,7 +539,7 @@ class InputObjectTemplateTests: XCTestCase { type: .list(.scalar(.string())), defaultValue: nil ) - ], config: .mock(.swiftPackageManager, schemaNamespace: "TestSchema")) + ], config: .mock(.swiftPackageManager(), schemaNamespace: "TestSchema")) let expected = """ public init( @@ -698,9 +698,9 @@ class InputObjectTemplateTests: XCTestCase { """ let tests: [(config: ApolloCodegenConfiguration.FileOutput, expected: String)] = [ - (.mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil)), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom")), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), expectedNoNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)), expectedWithNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom")), expectedWithNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), expectedNoNamespace), (.mock(moduleType: .other, operations: .relative(subpath: nil)), expectedWithNamespace), (.mock(moduleType: .other, operations: .absolute(path: "custom")), expectedWithNamespace), (.mock(moduleType: .other, operations: .inSchemaModule), expectedNoNamespace), @@ -1073,7 +1073,7 @@ class InputObjectTemplateTests: XCTestCase { documentation: "Field Documentation!") ], documentation: documentation, - config: .mock(.swiftPackageManager, options: .init(schemaDocumentation: .include)) + config: .mock(.swiftPackageManager(), options: .init(schemaDocumentation: .include)) ) let expected = """ @@ -1115,7 +1115,7 @@ class InputObjectTemplateTests: XCTestCase { documentation: "Field Documentation!") ], documentation: documentation, - config: .mock(.swiftPackageManager, options: .init(schemaDocumentation: .exclude)) + config: .mock(.swiftPackageManager(), options: .init(schemaDocumentation: .exclude)) ) let expected = """ @@ -1158,7 +1158,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include, warningsOnDeprecatedUsage: .include) ) ) @@ -1196,7 +1196,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1241,7 +1241,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1280,7 +1280,7 @@ class InputObjectTemplateTests: XCTestCase { ], documentation: documentation, config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1328,7 +1328,7 @@ class InputObjectTemplateTests: XCTestCase { ], documentation: documentation, config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1389,7 +1389,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1480,7 +1480,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager, + .swiftPackageManager(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1797,7 +1797,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, - config: .mock(.swiftPackageManager, + config: .mock(.swiftPackageManager(), options: .init( conversionStrategies: .init(inputObjects: .none) ), @@ -2214,7 +2214,7 @@ class InputObjectTemplateTests: XCTestCase { fields: fields, config: .mock(schemaNamespace: "testschema", output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil) ), options: .init( @@ -2275,7 +2275,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "testschema", output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil))) ) @@ -2331,7 +2331,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "TESTSCHEMA", output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil))) ) @@ -2387,7 +2387,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "TestSchema", output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil))) ) @@ -2429,7 +2429,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "testschema", - output: .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil)) + output: .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)) ) ) @@ -2461,7 +2461,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "TESTSCHEMA", - output: .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil)) + output: .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)) ) ) @@ -2493,7 +2493,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "TestSchema", - output: .mock(moduleType:.swiftPackageManager ,operations: .relative(subpath: nil)) + output: .mock(moduleType:.swiftPackageManager() ,operations: .relative(subpath: nil)) ) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift index db265d758..2081f7e22 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift @@ -99,7 +99,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule )) @@ -168,7 +168,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public) )) @@ -191,7 +191,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .internal) )) @@ -214,7 +214,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .public) )) @@ -237,7 +237,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .internal) )) @@ -487,7 +487,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesClassDefinition_withPublicModifier() async throws { // given - config = .mock(.swiftPackageManager) + config = .mock(.swiftPackageManager()) try await buildSubjectAndOperation() let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift index eecf31d2f..6b2eb6b20 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift @@ -25,7 +25,7 @@ class MockObjectTemplateTests: XCTestCase { interfaces: [GraphQLInterfaceType] = [], fields: [String : GraphQLField] = [:], schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager, + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), testMocks: ApolloCodegenConfiguration.TestMockFileOutput = .swiftPackage(), warningsOnDeprecatedUsage: ApolloCodegenConfiguration.Composition = .exclude ) { @@ -64,7 +64,7 @@ class MockObjectTemplateTests: XCTestCase { func test__render__givenSchemaType_generatesExtension() { // given - buildSubject(name: "Dog", moduleType: .swiftPackageManager) + buildSubject(name: "Dog", moduleType: .swiftPackageManager()) let expected = """ public class Dog: MockObject { @@ -171,7 +171,7 @@ class MockObjectTemplateTests: XCTestCase { "objectNestedList": .mock("objectNestedList", type: .list(.nonNull(.list(.nonNull(Cat))))), "objectOptionalList": .mock("objectOptionalList", type: .list(Cat)), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -202,7 +202,7 @@ class MockObjectTemplateTests: XCTestCase { "enumType": .mock("enumType", type: .enum(.mock(name: "enumType"))), "object": .mock("object", type: Cat), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -279,7 +279,7 @@ class MockObjectTemplateTests: XCTestCase { "Type": .mock("Type", type: .nonNull(.string())), "Any": .mock("Any", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -356,7 +356,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Interface)), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -379,7 +379,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Union)), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -402,7 +402,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Object)), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -474,7 +474,7 @@ class MockObjectTemplateTests: XCTestCase { "enumList": .mock("enumList", type: .list(.nonNull(.enum(.mock(name: "enumType"))))), "enumOptionalList": .mock("enumOptionalList", type: .list(.enum(.mock(name: "enumType")))) ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -547,7 +547,7 @@ class MockObjectTemplateTests: XCTestCase { func test__render__givenSchemaTypeWithoutFields_doesNotgenerateConvenienceInitializer() { // given - buildSubject(moduleType: .swiftPackageManager) + buildSubject(moduleType: .swiftPackageManager()) let expected = """ } @@ -624,7 +624,7 @@ class MockObjectTemplateTests: XCTestCase { "Type": .mock("Type", type: .nonNull(.string())), "Any": .mock("Any", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ @@ -862,7 +862,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string()), deprecationReason: "Cause I said so!"), ], - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), warningsOnDeprecatedUsage: .include ) @@ -885,7 +885,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string()), deprecationReason: "Cause I said so!"), ], - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), warningsOnDeprecatedUsage: .exclude ) @@ -914,7 +914,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager + moduleType: .swiftPackageManager() ) let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift index 4bfb028cc..317ede3f7 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift @@ -99,7 +99,7 @@ class ObjectTemplateTests: XCTestCase { GraphQLInterfaceType.mock("Animal", fields: ["species": GraphQLField.mock("species", type: .scalar(.string()))]), GraphQLInterfaceType.mock("Pet", fields: ["name": GraphQLField.mock("name", type: .scalar(.string()))]) ], - config: .mock(.swiftPackageManager) + config: .mock(.swiftPackageManager()) ) let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift index b4a957939..0cf2d73ad 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift @@ -39,7 +39,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { private func buildSubjectAndOperation( named operationName: String = "NameQuery", operationIdentifier: String? = nil, - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager, + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule, operationDocumentFormat: ApolloCodegenConfiguration.OperationDocumentFormat = .definition, cocoapodsCompatibleImportStatements: Bool = false @@ -359,7 +359,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule ) @@ -434,7 +434,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public) ) @@ -459,7 +459,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .internal) ) @@ -484,7 +484,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .public) ) @@ -509,7 +509,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .internal) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift index 57b16366f..7831494a4 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift @@ -332,9 +332,9 @@ class OperationDefinition_VariableDefinition_Tests: XCTestCase { """ let tests: [(config: ApolloCodegenConfiguration.FileOutput, expected: String)] = [ - (.mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil)), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom")), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), expectedNoNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)), expectedWithNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom")), expectedWithNamespace), + (.mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), expectedNoNamespace), (.mock(moduleType: .other, operations: .relative(subpath: nil)), expectedWithNamespace), (.mock(moduleType: .other, operations: .absolute(path: "custom")), expectedWithNamespace), (.mock(moduleType: .other, operations: .inSchemaModule), expectedNoNamespace), diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift index 88d9b4c9f..9cd81d7aa 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift @@ -16,7 +16,7 @@ class SchemaConfigurationTemplateTests: XCTestCase { private func buildSubject( name: String = "testSchema", - config: ApolloCodegenConfiguration = ApolloCodegenConfiguration.mock(.swiftPackageManager) + config: ApolloCodegenConfiguration = ApolloCodegenConfiguration.mock(.swiftPackageManager()) ) { subject = SchemaConfigurationTemplate( config: ApolloCodegen.ConfigurationContext(config: config) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift index 34f09a246..0aea3a115 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift @@ -131,7 +131,7 @@ class SchemaMetadataTemplateTests: XCTestCase { // given buildSubject( config: .mock( - .swiftPackageManager, + .swiftPackageManager(), schemaNamespace: "aName" ) ) @@ -266,7 +266,7 @@ class SchemaMetadataTemplateTests: XCTestCase { func test__render__givenModuleSwiftPackageManager_shouldGenerateEnumDefinition_withPublicModifier() { // given - buildSubject(config: .mock(.swiftPackageManager)) + buildSubject(config: .mock(.swiftPackageManager())) let expected = """ public enum SchemaMetadata: ApolloAPI.SchemaMetadata { @@ -449,7 +449,7 @@ class SchemaMetadataTemplateTests: XCTestCase { GraphQLInputObjectType.mock("InputObjectC"), ], schemaRootTypes: .mock()), config: .mock( - .swiftPackageManager, + .swiftPackageManager(), schemaNamespace: "ObjectSchema" ) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift index 769e25324..b416ba20a 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift @@ -625,9 +625,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -696,9 +696,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -4694,9 +4694,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -4762,9 +4762,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager, operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift index 572ba8382..97381c840 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift @@ -43,7 +43,7 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase { ) let config = ApolloCodegenConfiguration.mock( schemaNamespace: "TestSchema", - output: .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + output: .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), experimentalFeatures: .init( fieldMerging: fieldMerging ) @@ -68,7 +68,7 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase { let fragment = await ir.build(fragment: fragmentDefinition) let config = ApolloCodegenConfiguration.mock( schemaNamespace: "TestSchema", - output: .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule), + output: .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), options: .init() ) let mockTemplateRenderer = MockTemplateRenderer( diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift index 51223c2a4..384a1f99c 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift @@ -30,7 +30,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { func buildSubjectAndOperation( named operationName: String = "TestOperation", schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager, + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) @@ -58,7 +58,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { func buildSubjectAndFragment( named fragmentName: String = "TestFragment", schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager, + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws -> IRTestWrapper { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) @@ -115,7 +115,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule ) @@ -181,7 +181,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public) ) @@ -203,7 +203,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .internal) ) @@ -225,7 +225,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .public) ) @@ -247,7 +247,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .absolute(path: "", accessModifier: .internal) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift index 50d22d7d1..8d70e74d3 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift @@ -30,7 +30,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { func buildSubjectAndOperation( schemaNamespace: String = "TestSchema", named operationName: String = "TestOperation", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager, + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift index 53006c621..bfe5da523 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift @@ -45,9 +45,9 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager, operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager, operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager, operations: .inSchemaModule), + (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -93,17 +93,17 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { expectation: String )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedAPI ), @@ -176,17 +176,17 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { expectation: String )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedAPI ), @@ -269,19 +269,19 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 7 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 7 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift index 3741a7e1c..2c3d7d5fc 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift @@ -45,9 +45,9 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager, operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager, operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager, operations: .inSchemaModule), + (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -80,15 +80,15 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil) ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path") ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule ), ( @@ -141,15 +141,15 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil) ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path") ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule ), ( @@ -237,19 +237,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -330,17 +330,17 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, atLine: 6 ), @@ -441,19 +441,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -569,19 +569,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -697,19 +697,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -827,19 +827,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -957,19 +957,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -1087,19 +1087,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift index 74ddae70f..b7b9d6389 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift @@ -39,9 +39,9 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager, operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager, operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager, operations: .inSchemaModule), + (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -70,17 +70,17 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { importModuleName: String )] = [ ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil), importModuleName: "TestSchema" ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path"), importModuleName: "TestSchema" ), ( - schemaTypes: .swiftPackageManager, + schemaTypes: .swiftPackageManager(), operations: .inSchemaModule, importModuleName: "TestSchema" ), @@ -141,7 +141,7 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { """ let config = buildConfig( - moduleType: .swiftPackageManager, + moduleType: .swiftPackageManager(), operations: .inSchemaModule, cocoapodsCompatibleImportStatements: true ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift index f805ccf5b..3bb1daff8 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift @@ -203,7 +203,7 @@ class UnionTemplateTests: XCTestCase { func test_render_givenSchemaUnion_schemaTypesNotEmbeddedInTarget_generatesPossibleTypesPropertyWithoutSchemaNamespace() throws { // given - buildSubject(config: .mock(.swiftPackageManager)) + buildSubject(config: .mock(.swiftPackageManager())) let expected = """ possibleTypes: [ diff --git a/Tests/CodegenCLITests/Commands/GenerateTests.swift b/Tests/CodegenCLITests/Commands/GenerateTests.swift index 53207066e..6e6d50d4b 100644 --- a/Tests/CodegenCLITests/Commands/GenerateTests.swift +++ b/Tests/CodegenCLITests/Commands/GenerateTests.swift @@ -211,7 +211,7 @@ class GenerateTests: XCTestCase { schemaPath: "./schema.graphqls" ), output: .init( - schemaTypes: .init(path: ".", moduleType: .swiftPackageManager) + schemaTypes: .init(path: ".", moduleType: .swiftPackageManager()) ) ) diff --git a/Tests/CodegenCLITests/Commands/InitializeTests.swift b/Tests/CodegenCLITests/Commands/InitializeTests.swift index b4ea26cc7..d3f32c6c5 100644 --- a/Tests/CodegenCLITests/Commands/InitializeTests.swift +++ b/Tests/CodegenCLITests/Commands/InitializeTests.swift @@ -333,7 +333,7 @@ class InitializeTests: XCTestCase { // then let decoded = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encoded) - expect(decoded.output.schemaTypes.moduleType).to(equal(.swiftPackageManager)) + expect(decoded.output.schemaTypes.moduleType).to(equal(.swiftPackageManager())) } func test__moduleType__givenModuleTypeExpressibleByArgument_other_shouldEqualSchemaTypesFileOutputModuleType_other() throws { diff --git a/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift b/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift index 047adff77..e72f0f933 100644 --- a/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift +++ b/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift @@ -9,7 +9,7 @@ extension ApolloCodegenConfiguration { schemaPath: "./schema.graphqls" ), output: .init( - schemaTypes: .init(path: ".", moduleType: .swiftPackageManager) + schemaTypes: .init(path: ".", moduleType: .swiftPackageManager()) ), options: .init( operationDocumentFormat: [.definition, .operationId] diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift similarity index 97% rename from apollo-ios-codegen/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift rename to apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index df4de29c4..8576fd6d6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -283,7 +283,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { case embeddedInTarget(name: String, accessModifier: AccessModifier = .internal) /// Generates a `Package.swift` file that is suitable for linking the generated schema types /// files to your project using Swift Package Manager. - case swiftPackageManager + case swiftPackageManager(version: ApolloPackageVersion = .default) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the /// module you will create in the `schemaNamespace` property as this will be used in `import` @@ -321,13 +321,67 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: - self = .swiftPackageManager + let nestedContainer = try container.nestedContainer( + keyedBy: SwiftPackageManagerCodingKeys.self, + forKey: .swiftPackageManager + ) + + let version = try nestedContainer.decodeIfPresent(ApolloPackageVersion.self, forKey: .version) ?? .default + self = .swiftPackageManager(version: version) case .other: self = .other } } } + + public enum ApolloPackageVersion: Codable, Equatable { + case `default` + case branch(name: String) + case commitHash(hash: String) + case localPath(path: String) + + public init(from decoder: any Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + guard let key = container.allKeys.first else { + throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( + codingPath: container.codingPath, + debugDescription: "Invalid number of keys found, expected one.", + underlyingError: nil + )) + } + + switch key { + case .default: + self = .default + case .branch: + let nestedContainer = try container.nestedContainer( + keyedBy: BranchCodingKeys.self, + forKey: .branch + ) + + let name = try nestedContainer.decode(String.self, forKey: .name) + self = .branch(name: name) + case .commitHash: + let nestedContainer = try container.nestedContainer( + keyedBy: CommitHashCodingKeys.self, + forKey: .commitHash + ) + + let hash = try nestedContainer.decode(String.self, forKey: .hash) + self = .commitHash(hash: hash) + case .localPath: + let nestedContainer = try container.nestedContainer( + keyedBy: LocalPathCodingKeys.self, + forKey: .localPath + ) + + let path = try nestedContainer.decode(String.self, forKey: .path) + self = .localPath(path: path) + } + } + } } /// The local path structure for the generated operation object files. diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift index f644df9c4..eea457385 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift @@ -34,7 +34,7 @@ extension ApolloCodegen.ConfigurationContext { } if case .swiftPackage = self.output.testMocks, - self.output.schemaTypes.moduleType != .swiftPackageManager { + self.output.schemaTypes.moduleType != .swiftPackageManager() { throw ApolloCodegen.Error.testMocksInvalidSwiftPackageConfiguration } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift index beb58147f..c7a57b5fc 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift @@ -112,7 +112,7 @@ enum FileTarget: Equatable { forConfig config: ApolloCodegen.ConfigurationContext ) -> String { var moduleSubpath: String = "/" - if config.output.schemaTypes.moduleType == .swiftPackageManager { + if config.output.schemaTypes.moduleType == .swiftPackageManager() { moduleSubpath += "Sources/" } if config.output.operations.isInModule { @@ -132,7 +132,7 @@ enum FileTarget: Equatable { switch config.output.operations { case .inSchemaModule: var url = URL(fileURLWithPath: config.output.schemaTypes.path, relativeTo: config.rootURL) - if config.output.schemaTypes.moduleType == .swiftPackageManager { + if config.output.schemaTypes.moduleType == .swiftPackageManager() { url = url.appendingPathComponent("Sources") } @@ -167,7 +167,7 @@ enum FileTarget: Equatable { switch config.output.operations { case .inSchemaModule: var url = URL(fileURLWithPath: config.output.schemaTypes.path, relativeTo: config.rootURL) - if config.output.schemaTypes.moduleType == .swiftPackageManager { + if config.output.schemaTypes.moduleType == .swiftPackageManager() { url = url.appendingPathComponent("Sources") } if !operation.isLocalCacheMutation { From a9ddd8d37efd1b820bc557be6c944cd536ec77d2 Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:33:51 -0500 Subject: [PATCH 02/10] Finish Implementation Finished implementation in SchemaModuleTemplate for new spm module type versions --- ...olloCodegenConfigurationCodableTests.swift | 102 ++++++++++++++++-- ...iftPackageManagerModuleTemplateTests.swift | 63 ++++++++++- .../ApolloCodegenConfiguration.swift | 20 ++-- .../Sources/ApolloCodegenLib/Constants.swift | 5 + .../SchemaModuleFileGenerator.swift | 5 +- .../SwiftPackageManagerModuleTemplate.swift | 27 ++++- .../scripts/version-constants.sh | 1 + scripts/set-version.sh | 7 ++ 8 files changed, 206 insertions(+), 24 deletions(-) create mode 100644 apollo-ios-codegen/Sources/ApolloCodegenLib/Constants.swift diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index b994d1691..5e729d5a1 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1241,7 +1241,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { // MARK: Module Type Tests - func test__codableSPMModuleType_noVersionProvided() throws { + func test__codableSPMModuleType_noStructVersionProvided() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -1336,8 +1336,98 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { } let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - print("Actual JSON - \(actualJSON)") expect(actualJSON).to(equalLineByLine(encodedJSON)) + } + + func test__codableSPMModuleType_noJSONVersionProvided() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager() + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackageManager" : { + + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) expect(actualStruct).to(equal(decodedStruct)) @@ -1560,7 +1650,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .commitHash(hash: "hash")) + moduleType: .swiftPackageManager(version: .commit(hash: "hash")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1622,7 +1712,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackageManager" : { "version" : { - "commitHash" : { + "commit" : { "hash" : "hash" } } @@ -1662,7 +1752,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .localPath(path: "path")) + moduleType: .swiftPackageManager(version: .local(path: "path")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1724,7 +1814,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackageManager" : { "version" : { - "localPath" : { + "local" : { "path" : "path" } } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index d7962437b..5e3df989c 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -14,11 +14,13 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { private func buildSubject( testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput = .none, - config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule") + config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule"), + version: ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion = .default ) { subject = .init( testMockConfig: testMockConfig, - config: .init(config: config) + config: .init(config: config), + version: version ) } @@ -148,13 +150,64 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 13, ignoringExtraLines: true)) } - func test__packageDescription__generatesNoDependencies() { + func test__packageDescription__generatesDefaultVersionDependency() { // given - buildSubject() + buildSubject(version: .default) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios.git", exact: "\(ApolloCodegenLib.Constants.CodegenVersion)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesBranchVersionDependency() { + // given + let branchName = "testBranch" + buildSubject(version: .branch(name: branchName)) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios.git", branch: "\(branchName)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesCommitVersionDependency() { + // given + let hash = "testHash" + buildSubject(version: .commit(hash: hash)) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesLocalVersionDependency() { + // given + let path = "localPath" + buildSubject(version: .local(path: path)) let expected = """ dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"), + .package(path: "\(path)"), ], """ // when diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index 8576fd6d6..34f34a86f 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -338,8 +338,8 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { public enum ApolloPackageVersion: Codable, Equatable { case `default` case branch(name: String) - case commitHash(hash: String) - case localPath(path: String) + case commit(hash: String) + case local(path: String) public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) @@ -363,22 +363,22 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { let name = try nestedContainer.decode(String.self, forKey: .name) self = .branch(name: name) - case .commitHash: + case .commit: let nestedContainer = try container.nestedContainer( - keyedBy: CommitHashCodingKeys.self, - forKey: .commitHash + keyedBy: CommitCodingKeys.self, + forKey: .commit ) let hash = try nestedContainer.decode(String.self, forKey: .hash) - self = .commitHash(hash: hash) - case .localPath: + self = .commit(hash: hash) + case .local: let nestedContainer = try container.nestedContainer( - keyedBy: LocalPathCodingKeys.self, - forKey: .localPath + keyedBy: LocalCodingKeys.self, + forKey: .local ) let path = try nestedContainer.decode(String.self, forKey: .path) - self = .localPath(path: path) + self = .local(path: path) } } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Constants.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Constants.swift new file mode 100644 index 000000000..94ad05648 --- /dev/null +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Constants.swift @@ -0,0 +1,5 @@ +import Foundation + +public enum Constants { + public static let CodegenVersion: String = "1.15.3" +} diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift index f47dec6d6..797b37e23 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift @@ -20,11 +20,12 @@ struct SchemaModuleFileGenerator { let errors: [ApolloCodegen.NonFatalError] switch config.output.schemaTypes.moduleType { - case .swiftPackageManager: + case .swiftPackageManager(let version): filePath = pathURL.appendingPathComponent("Package.swift").path (rendered, errors) = SwiftPackageManagerModuleTemplate( testMockConfig: config.output.testMocks, - config: config + config: config, + version: version ).render() case .embeddedInTarget: diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 7c3fa07dc..0db58a04b 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -10,6 +10,8 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { let target: TemplateTarget = .moduleFile let config: ApolloCodegen.ConfigurationContext + + let version: ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion func renderHeaderTemplate( nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder @@ -42,7 +44,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { """}) ], dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"), + \(version.dependencyString), ], targets: [ .target( @@ -81,3 +83,26 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { } } } + +fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion { + var dependencyString: TemplateString { + switch self { + case .default: + return """ + .package(url: "https://github.com/apollographql/apollo-ios.git", exact: "\(Constants.CodegenVersion)") + """ + case .branch(let name): + return """ + .package(url: "https://github.com/apollographql/apollo-ios.git", branch: "\(name)") + """ + case .commit(let hash): + return """ + .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)") + """ + case .local(let path): + return """ + .package(path: "\(path)") + """ + } + } +} diff --git a/apollo-ios-codegen/scripts/version-constants.sh b/apollo-ios-codegen/scripts/version-constants.sh index 1b9dafd1d..211cd7cdd 100644 --- a/apollo-ios-codegen/scripts/version-constants.sh +++ b/apollo-ios-codegen/scripts/version-constants.sh @@ -1 +1,2 @@ CLI_CONSTANTS_FILE="Sources/CodegenCLI/Constants.swift" +CODEGEN_CONSTANTS_FILE="Sources/ApolloCodegenLib/Constants.swift" diff --git a/scripts/set-version.sh b/scripts/set-version.sh index 7a501c3e8..90d9088bd 100755 --- a/scripts/set-version.sh +++ b/scripts/set-version.sh @@ -32,6 +32,13 @@ SEARCH_TEXT="$MATCH_TEXT$CURRENT_CODEGEN_VERSION" REPLACE_TEXT="$MATCH_TEXT$NEW_VERSION" sed -i '' -e "s/$SEARCH_TEXT/$REPLACE_TEXT/" $codegenDirectory/$CLI_CONSTANTS_FILE +# Set Codegen version constant + +MATCH_TEXT='CodegenVersion: String = "' +SEARCH_TEXT="$MATCH_TEXT$CURRENT_CODEGEN_VERSION" +REPLACE_TEXT="$MATCH_TEXT$NEW_VERSION" +sed -i '' -e "s/$SEARCH_TEXT/$REPLACE_TEXT/" $codegenDirectory/$CODEGEN_CONSTANTS_FILE + # Feedback echo "Committing change from version $CURRENT_VERSION to $NEW_VERSION" git add -A && git commit -m "Updated version numbers" From 60579a52b11c8164d4fd352ab5f63d6f07e146d7 Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:02:38 -0500 Subject: [PATCH 03/10] Addressing feedback --- ...olloCodegenConfigurationCodableTests.swift | 230 ++++++++++++++++-- .../ApolloCodegenTests.swift | 42 ++-- .../FileGenerators/FileGeneratorTests.swift | 2 +- .../FileGenerator_ResolvePath_Tests.swift | 84 +++---- .../OperationManifestFileGeneratorTests.swift | 4 +- .../SchemaModuleFileGeneratorTests.swift | 2 +- .../Templates/CustomScalarTemplateTests.swift | 2 +- .../Templates/EnumTemplateTests.swift | 2 +- .../Templates/FragmentTemplateTests.swift | 2 +- .../Templates/InputObjectTemplateTests.swift | 46 ++-- ...CacheMutationDefinitionTemplateTests.swift | 12 +- .../Templates/MockObjectTemplateTests.swift | 28 +-- .../Templates/ObjectTemplateTests.swift | 2 +- ...efinitionTemplate_DocumentType_Tests.swift | 12 +- ...nDefinition_VariableDefinition_Tests.swift | 6 +- .../SchemaConfigurationTemplateTests.swift | 2 +- .../SchemaMetadataTemplateTests.swift | 6 +- .../SelectionSetTemplateTests.swift | 24 +- ...ctionSetTemplate_ErrorHandling_Tests.swift | 4 +- ...ectionSetTemplate_Initializers_Tests.swift | 14 +- ...SetTemplate_LocalCacheMutation_Tests.swift | 2 +- ...iftPackageManagerModuleTemplateTests.swift | 12 +- ...TemplateRenderer_OperationFile_Tests.swift | 24 +- .../TemplateRenderer_SchemaFile_Tests.swift | 66 ++--- .../TemplateRenderer_TestMockFile_Tests.swift | 14 +- .../Templates/UnionTemplateTests.swift | 2 +- .../Commands/GenerateTests.swift | 2 +- .../Commands/InitializeTests.swift | 2 +- .../MockApolloCodegenConfiguration.swift | 2 +- .../ApolloCodegenConfiguration.swift | 106 ++++---- .../ConfigurationValidation.swift | 4 +- .../FileGenerators/FileGenerator.swift | 6 +- .../SchemaModuleFileGenerator.swift | 11 +- .../SwiftPackageManagerModuleTemplate.swift | 6 +- .../Templates/TemplateRenderer.swift | 3 +- 35 files changed, 496 insertions(+), 292 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index 5e729d5a1..1fc023e52 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1241,7 +1241,105 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { // MARK: Module Type Tests - func test__codableSPMModuleType_noStructVersionProvided() throws { + func test__codableSPMModuleType_deprecatedSPMStructVersionProvided() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackageManager + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "dependencyType" : { + "default" : { + + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + expect(actualJSON).to(equalLineByLine(encodedJSON)) + } + + func test__codableSPMModuleType_deprecatedSPMJSONVersionProvided() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -1254,7 +1352,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1315,7 +1413,101 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackageManager" : { - "version" : { + + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_noStructVersionProvided() throws { + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackage() + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "dependencyType" : { "default" : { } @@ -1352,7 +1544,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1412,7 +1604,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { }, "schemaTypes" : { "moduleType" : { - "swiftPackageManager" : { + "swiftPackage" : { } }, @@ -1446,7 +1638,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .default) + moduleType: .swiftPackage(dependencyType: .default) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1506,8 +1698,8 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { }, "schemaTypes" : { "moduleType" : { - "swiftPackageManager" : { - "version" : { + "swiftPackage" : { + "dependencyType" : { "default" : { } @@ -1528,7 +1720,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { } let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - print("Actual JSON - \(actualJSON)") expect(actualJSON).to(equalLineByLine(encodedJSON)) let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) @@ -1548,7 +1739,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .branch(name: "branchName")) + moduleType: .swiftPackage(dependencyType: .branch(name: "branchName")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1608,8 +1799,8 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { }, "schemaTypes" : { "moduleType" : { - "swiftPackageManager" : { - "version" : { + "swiftPackage" : { + "dependencyType" : { "branch" : { "name" : "branchName" } @@ -1630,7 +1821,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { } let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - print("Actual JSON - \(actualJSON)") expect(actualJSON).to(equalLineByLine(encodedJSON)) let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) @@ -1650,7 +1840,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .commit(hash: "hash")) + moduleType: .swiftPackage(dependencyType: .commit(hash: "hash")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1710,8 +1900,8 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { }, "schemaTypes" : { "moduleType" : { - "swiftPackageManager" : { - "version" : { + "swiftPackage" : { + "dependencyType" : { "commit" : { "hash" : "hash" } @@ -1732,7 +1922,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { } let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - print("Actual JSON - \(actualJSON)") expect(actualJSON).to(equalLineByLine(encodedJSON)) let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) @@ -1752,7 +1941,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackageManager(version: .local(path: "path")) + moduleType: .swiftPackage(dependencyType: .local(path: "path")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1812,8 +2001,8 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { }, "schemaTypes" : { "moduleType" : { - "swiftPackageManager" : { - "version" : { + "swiftPackage" : { + "dependencyType" : { "local" : { "path" : "path" } @@ -1834,7 +2023,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { } let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - print("Actual JSON - \(actualJSON)") expect(actualJSON).to(equalLineByLine(encodedJSON)) let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift index 8d5f99512..70ead76df 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift @@ -640,7 +640,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule, path: directoryURL.path ) @@ -756,7 +756,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: operationsOutputURL.path), path: directoryURL.path ) @@ -862,7 +862,7 @@ class ApolloCodegenTests: XCTestCase { input: .init(schemaPath: schemaPath, operationSearchPaths: [operationsPath]), output: .init( schemaTypes: .init(path: directoryURL.path, - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule, testMocks: .absolute(path: directoryURL.appendingPathComponent("TestMocks").path) ) @@ -938,7 +938,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule, path: "./RelativePath" ) @@ -1051,7 +1051,7 @@ class ApolloCodegenTests: XCTestCase { operationSearchPaths: [operationsPath] ), output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "./RelativeOperations"), path: "./RelativePath" ) @@ -1183,7 +1183,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule ), options: .init(pruneGeneratedFiles: false) @@ -1241,7 +1241,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule ) ) @@ -1295,7 +1295,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .absolute(path: "OperationPath") ) ) @@ -1364,7 +1364,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: nil) ) ) @@ -1437,7 +1437,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: nil) ) ) @@ -1489,7 +1489,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: schemaDirectory, - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: relativeSubPath) ), options: .init( @@ -1586,7 +1586,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: "subpath") ) ) @@ -1694,7 +1694,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: "subpath") ) ) @@ -1796,7 +1796,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .relative(subpath: "subpath") ) ) @@ -1860,7 +1860,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule, testMocks: .absolute(path: absolutePath) ) @@ -1917,7 +1917,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), testMocks: .swiftPackage() ) ) @@ -1975,7 +1975,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), testMocks: .swiftPackage(targetName: testMockTargetName) ) ) @@ -2285,7 +2285,7 @@ class ApolloCodegenTests: XCTestCase { func test__validation__givenSchemaTypesModule_swiftPackageManager_withCocoapodsCompatibleImportStatements_true_shouldThrow() throws { // given let config = ApolloCodegenConfiguration.mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(cocoapodsCompatibleImportStatements: true) ) @@ -2301,7 +2301,7 @@ class ApolloCodegenTests: XCTestCase { func test__validation__givenSchemaTypesModule_swiftPackageManager_withCocoapodsCompatibleImportStatements_false_shouldNotThrow() throws { // given let config = ApolloCodegenConfiguration.mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(cocoapodsCompatibleImportStatements: false) ) @@ -2387,7 +2387,7 @@ class ApolloCodegenTests: XCTestCase { ), output: .init( schemaTypes: .init(path: "SchemaModule", - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule ) ) @@ -2538,7 +2538,7 @@ class ApolloCodegenTests: XCTestCase { input: .init(schemaPath: schemaPath, operationSearchPaths: [operationsPath]), output: .init( schemaTypes: .init(path: directoryURL.path, - moduleType: .swiftPackageManager()), + moduleType: .swiftPackage()), operations: .inSchemaModule ), options: .init( diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift index 3d3c985d8..4e38b0943 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGeneratorTests.swift @@ -30,7 +30,7 @@ class FileGeneratorTests: XCTestCase { private func buildConfig() { let mockedConfig = ApolloCodegenConfiguration.mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule )) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift index f3b15d42f..f3cc225dc 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FileGenerator_ResolvePath_Tests.swift @@ -143,7 +143,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -162,7 +162,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -180,7 +180,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -198,7 +198,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .object // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -356,7 +356,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -375,7 +375,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -393,7 +393,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -411,7 +411,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .enum // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -569,7 +569,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -588,7 +588,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -606,7 +606,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -624,7 +624,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .interface // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -782,7 +782,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -801,7 +801,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -819,7 +819,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -837,7 +837,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .union // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -995,7 +995,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1014,7 +1014,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1032,7 +1032,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1050,7 +1050,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .inputObject // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1208,7 +1208,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1227,7 +1227,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1245,7 +1245,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1263,7 +1263,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .customScalar // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1421,7 +1421,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1439,7 +1439,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .absolute(path: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1456,7 +1456,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = directoryURL .appendingPathComponent("Sources") @@ -1473,7 +1473,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .schema // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: "NewPath")) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: "NewPath")) let expected = directoryURL .appendingPathComponent("Sources") @@ -1622,7 +1622,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .fragment(irFragment.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1642,7 +1642,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) + buildConfig(module: .swiftPackage(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Fragments" @@ -1658,7 +1658,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .fragment(irFragment.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = deleteLastPathComponent(irFragment.definition.filePath) @@ -1675,7 +1675,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "NewPath" - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: path)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: path)) let expected = deleteLastPathComponent(irFragment.definition.filePath, appending: path) @@ -1832,7 +1832,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1852,7 +1852,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1872,7 +1872,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .inSchemaModule) + buildConfig(module: .swiftPackage(), operations: .inSchemaModule) let expected = directoryURL .appendingPathComponent("Sources") @@ -1893,7 +1893,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) + buildConfig(module: .swiftPackage(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Queries" @@ -1910,7 +1910,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) + buildConfig(module: .swiftPackage(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Mutations" @@ -1927,7 +1927,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "New/Path" - buildConfig(module: .swiftPackageManager(), operations: .absolute(path: path)) + buildConfig(module: .swiftPackage(), operations: .absolute(path: path)) let expected = currentWorkingDirectoryPath + path + "/Subscriptions" @@ -1943,7 +1943,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { subject = .operation(irOperation.definition) // when - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: nil)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: nil)) let expected = deleteLastPathComponent(irOperation.definition.filePath) @@ -1960,7 +1960,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when let path = "NewPath" - buildConfig(module: .swiftPackageManager(), operations: .relative(subpath: path)) + buildConfig(module: .swiftPackage(), operations: .relative(subpath: path)) let expected = deleteLastPathComponent(irOperation.definition.filePath, appending: path) @@ -2265,7 +2265,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when buildConfig( - module: .swiftPackageManager(), + module: .swiftPackage(), operations: .inSchemaModule, testMocks: .swiftPackage() ) @@ -2286,7 +2286,7 @@ class FileGenerator_ResolvePath_Tests: XCTestCase { // when buildConfig( - module: .swiftPackageManager(), + module: .swiftPackage(), operations: .inSchemaModule, testMocks: .swiftPackage(targetName: "CustomMockTarget") ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift index 74c2f5b49..a9f9ae6b5 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/OperationManifestFileGeneratorTests.swift @@ -33,7 +33,7 @@ class OperationManifestFileGeneratorTests: XCTestCase { subject = OperationManifestFileGenerator( config: ApolloCodegen.ConfigurationContext(config: ApolloCodegenConfiguration.mock( output: .init( - schemaTypes: .init(path: "", moduleType: .swiftPackageManager()) + schemaTypes: .init(path: "", moduleType: .swiftPackage()) ), operationManifest: manifest )) @@ -46,7 +46,7 @@ class OperationManifestFileGeneratorTests: XCTestCase { // given let config = ApolloCodegenConfiguration.mock( output: .init( - schemaTypes: .init(path: "", moduleType: .swiftPackageManager()) + schemaTypes: .init(path: "", moduleType: .swiftPackage()) ), operationManifest: .init( path: "a/file/path" diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift index cc6abdc83..dc0fc1c77 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/SchemaModuleFileGeneratorTests.swift @@ -30,7 +30,7 @@ class SchemaModuleFileGeneratorTests: XCTestCase { let fileURL = rootURL.appendingPathComponent("Package.swift") let configuration = ApolloCodegen.ConfigurationContext(config: ApolloCodegenConfiguration.mock( - .swiftPackageManager(), + .swiftPackage(), to: rootURL.path )) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift index 92d35d683..0ddc75436 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift @@ -99,7 +99,7 @@ class CustomScalarTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesTypealias_withPublicAccess() { // given - buildSubject(config: .mock(.swiftPackageManager())) + buildSubject(config: .mock(.swiftPackage())) let expected = """ public typealias MyCustomScalar = String diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift index 1cca7158f..762a0c9ab 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift @@ -56,7 +56,7 @@ class EnumTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesSwiftEnum_withPublicAccess() { // given - buildSubject(config: .mock(.swiftPackageManager())) + buildSubject(config: .mock(.swiftPackage())) let expected = """ public enum TestEnum: String, EnumType { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift index d4d851d16..ce471b8cc 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift @@ -352,7 +352,7 @@ class FragmentTemplateTests: XCTestCase { func test__render__givenModuleType_swiftPackageManager_generatesFragmentDefinition_withPublicAccess() async throws { // given - try await buildSubjectAndFragment(config: .mock(.swiftPackageManager())) + try await buildSubjectAndFragment(config: .mock(.swiftPackage())) let expected = """ public struct TestFragment: TestSchema.SelectionSet, Fragment { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift index 99c514660..1a10db48c 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift @@ -17,7 +17,7 @@ class InputObjectTemplateTests: XCTestCase { customName: String? = nil, fields: [GraphQLInputField] = [], documentation: String? = nil, - config: ApolloCodegenConfiguration = .mock(.swiftPackageManager()) + config: ApolloCodegenConfiguration = .mock(.swiftPackage()) ) { let inputObject = GraphQLInputObjectType.mock( name, @@ -80,7 +80,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil ) ], - config: .mock(.swiftPackageManager()) + config: .mock(.swiftPackage()) ) let expected = """ @@ -539,7 +539,7 @@ class InputObjectTemplateTests: XCTestCase { type: .list(.scalar(.string())), defaultValue: nil ) - ], config: .mock(.swiftPackageManager(), schemaNamespace: "TestSchema")) + ], config: .mock(.swiftPackage(), schemaNamespace: "TestSchema")) let expected = """ public init( @@ -698,9 +698,9 @@ class InputObjectTemplateTests: XCTestCase { """ let tests: [(config: ApolloCodegenConfiguration.FileOutput, expected: String)] = [ - (.mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom")), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), expectedNoNamespace), + (.mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil)), expectedWithNamespace), + (.mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom")), expectedWithNamespace), + (.mock(moduleType: .swiftPackage(), operations: .inSchemaModule), expectedNoNamespace), (.mock(moduleType: .other, operations: .relative(subpath: nil)), expectedWithNamespace), (.mock(moduleType: .other, operations: .absolute(path: "custom")), expectedWithNamespace), (.mock(moduleType: .other, operations: .inSchemaModule), expectedNoNamespace), @@ -1073,7 +1073,7 @@ class InputObjectTemplateTests: XCTestCase { documentation: "Field Documentation!") ], documentation: documentation, - config: .mock(.swiftPackageManager(), options: .init(schemaDocumentation: .include)) + config: .mock(.swiftPackage(), options: .init(schemaDocumentation: .include)) ) let expected = """ @@ -1115,7 +1115,7 @@ class InputObjectTemplateTests: XCTestCase { documentation: "Field Documentation!") ], documentation: documentation, - config: .mock(.swiftPackageManager(), options: .init(schemaDocumentation: .exclude)) + config: .mock(.swiftPackage(), options: .init(schemaDocumentation: .exclude)) ) let expected = """ @@ -1158,7 +1158,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include, warningsOnDeprecatedUsage: .include) ) ) @@ -1196,7 +1196,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1241,7 +1241,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1280,7 +1280,7 @@ class InputObjectTemplateTests: XCTestCase { ], documentation: documentation, config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1328,7 +1328,7 @@ class InputObjectTemplateTests: XCTestCase { ], documentation: documentation, config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1389,7 +1389,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .include) ) ) @@ -1480,7 +1480,7 @@ class InputObjectTemplateTests: XCTestCase { ) ], config: .mock( - .swiftPackageManager(), + .swiftPackage(), options: .init(schemaDocumentation: .include,warningsOnDeprecatedUsage: .exclude) ) ) @@ -1797,7 +1797,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, - config: .mock(.swiftPackageManager(), + config: .mock(.swiftPackage(), options: .init( conversionStrategies: .init(inputObjects: .none) ), @@ -2214,7 +2214,7 @@ class InputObjectTemplateTests: XCTestCase { fields: fields, config: .mock(schemaNamespace: "testschema", output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil) ), options: .init( @@ -2275,7 +2275,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "testschema", output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil))) ) @@ -2331,7 +2331,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "TESTSCHEMA", output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil))) ) @@ -2387,7 +2387,7 @@ class InputObjectTemplateTests: XCTestCase { buildSubject( fields: fields, config: .mock(schemaNamespace: "TestSchema", output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil))) ) @@ -2429,7 +2429,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "testschema", - output: .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)) + output: .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil)) ) ) @@ -2461,7 +2461,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "TESTSCHEMA", - output: .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)) + output: .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil)) ) ) @@ -2493,7 +2493,7 @@ class InputObjectTemplateTests: XCTestCase { defaultValue: nil)], config: .mock( schemaNamespace: "TestSchema", - output: .mock(moduleType:.swiftPackageManager() ,operations: .relative(subpath: nil)) + output: .mock(moduleType:.swiftPackage() ,operations: .relative(subpath: nil)) ) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift index 2081f7e22..83038df69 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift @@ -99,7 +99,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule )) @@ -168,7 +168,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public) )) @@ -191,7 +191,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .internal) )) @@ -214,7 +214,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .public) )) @@ -237,7 +237,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { """ config = .mock(output: .mock( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .internal) )) @@ -487,7 +487,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { func test_render_givenModuleType_swiftPackageManager_generatesClassDefinition_withPublicModifier() async throws { // given - config = .mock(.swiftPackageManager()) + config = .mock(.swiftPackage()) try await buildSubjectAndOperation() let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift index 6b2eb6b20..fc8370e4d 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift @@ -25,7 +25,7 @@ class MockObjectTemplateTests: XCTestCase { interfaces: [GraphQLInterfaceType] = [], fields: [String : GraphQLField] = [:], schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackage(), testMocks: ApolloCodegenConfiguration.TestMockFileOutput = .swiftPackage(), warningsOnDeprecatedUsage: ApolloCodegenConfiguration.Composition = .exclude ) { @@ -64,7 +64,7 @@ class MockObjectTemplateTests: XCTestCase { func test__render__givenSchemaType_generatesExtension() { // given - buildSubject(name: "Dog", moduleType: .swiftPackageManager()) + buildSubject(name: "Dog", moduleType: .swiftPackage()) let expected = """ public class Dog: MockObject { @@ -171,7 +171,7 @@ class MockObjectTemplateTests: XCTestCase { "objectNestedList": .mock("objectNestedList", type: .list(.nonNull(.list(.nonNull(Cat))))), "objectOptionalList": .mock("objectOptionalList", type: .list(Cat)), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -202,7 +202,7 @@ class MockObjectTemplateTests: XCTestCase { "enumType": .mock("enumType", type: .enum(.mock(name: "enumType"))), "object": .mock("object", type: Cat), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -279,7 +279,7 @@ class MockObjectTemplateTests: XCTestCase { "Type": .mock("Type", type: .nonNull(.string())), "Any": .mock("Any", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -356,7 +356,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Interface)), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -379,7 +379,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Union)), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -402,7 +402,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "actor": .mock("actor", type: .entity(Actor_Object)), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -474,7 +474,7 @@ class MockObjectTemplateTests: XCTestCase { "enumList": .mock("enumList", type: .list(.nonNull(.enum(.mock(name: "enumType"))))), "enumOptionalList": .mock("enumOptionalList", type: .list(.enum(.mock(name: "enumType")))) ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -547,7 +547,7 @@ class MockObjectTemplateTests: XCTestCase { func test__render__givenSchemaTypeWithoutFields_doesNotgenerateConvenienceInitializer() { // given - buildSubject(moduleType: .swiftPackageManager()) + buildSubject(moduleType: .swiftPackage()) let expected = """ } @@ -624,7 +624,7 @@ class MockObjectTemplateTests: XCTestCase { "Type": .mock("Type", type: .nonNull(.string())), "Any": .mock("Any", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ @@ -862,7 +862,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string()), deprecationReason: "Cause I said so!"), ], - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), warningsOnDeprecatedUsage: .include ) @@ -885,7 +885,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string()), deprecationReason: "Cause I said so!"), ], - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), warningsOnDeprecatedUsage: .exclude ) @@ -914,7 +914,7 @@ class MockObjectTemplateTests: XCTestCase { fields: [ "string": .mock("string", type: .nonNull(.string())), ], - moduleType: .swiftPackageManager() + moduleType: .swiftPackage() ) let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift index 317ede3f7..c345895e1 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift @@ -99,7 +99,7 @@ class ObjectTemplateTests: XCTestCase { GraphQLInterfaceType.mock("Animal", fields: ["species": GraphQLField.mock("species", type: .scalar(.string()))]), GraphQLInterfaceType.mock("Pet", fields: ["name": GraphQLField.mock("name", type: .scalar(.string()))]) ], - config: .mock(.swiftPackageManager()) + config: .mock(.swiftPackage()) ) let expected = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift index 0cf2d73ad..3dd636371 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplate_DocumentType_Tests.swift @@ -39,7 +39,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { private func buildSubjectAndOperation( named operationName: String = "NameQuery", operationIdentifier: String? = nil, - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackage(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule, operationDocumentFormat: ApolloCodegenConfiguration.OperationDocumentFormat = .definition, cocoapodsCompatibleImportStatements: Bool = false @@ -359,7 +359,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule ) @@ -434,7 +434,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public) ) @@ -459,7 +459,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .internal) ) @@ -484,7 +484,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .public) ) @@ -509,7 +509,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .internal) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift index 7831494a4..799e71103 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinition_VariableDefinition_Tests.swift @@ -332,9 +332,9 @@ class OperationDefinition_VariableDefinition_Tests: XCTestCase { """ let tests: [(config: ApolloCodegenConfiguration.FileOutput, expected: String)] = [ - (.mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil)), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom")), expectedWithNamespace), - (.mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), expectedNoNamespace), + (.mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil)), expectedWithNamespace), + (.mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom")), expectedWithNamespace), + (.mock(moduleType: .swiftPackage(), operations: .inSchemaModule), expectedNoNamespace), (.mock(moduleType: .other, operations: .relative(subpath: nil)), expectedWithNamespace), (.mock(moduleType: .other, operations: .absolute(path: "custom")), expectedWithNamespace), (.mock(moduleType: .other, operations: .inSchemaModule), expectedNoNamespace), diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift index 9cd81d7aa..c878f9a83 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaConfigurationTemplateTests.swift @@ -16,7 +16,7 @@ class SchemaConfigurationTemplateTests: XCTestCase { private func buildSubject( name: String = "testSchema", - config: ApolloCodegenConfiguration = ApolloCodegenConfiguration.mock(.swiftPackageManager()) + config: ApolloCodegenConfiguration = ApolloCodegenConfiguration.mock(.swiftPackage()) ) { subject = SchemaConfigurationTemplate( config: ApolloCodegen.ConfigurationContext(config: config) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift index 0aea3a115..c3c64b0e4 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaMetadataTemplateTests.swift @@ -131,7 +131,7 @@ class SchemaMetadataTemplateTests: XCTestCase { // given buildSubject( config: .mock( - .swiftPackageManager(), + .swiftPackage(), schemaNamespace: "aName" ) ) @@ -266,7 +266,7 @@ class SchemaMetadataTemplateTests: XCTestCase { func test__render__givenModuleSwiftPackageManager_shouldGenerateEnumDefinition_withPublicModifier() { // given - buildSubject(config: .mock(.swiftPackageManager())) + buildSubject(config: .mock(.swiftPackage())) let expected = """ public enum SchemaMetadata: ApolloAPI.SchemaMetadata { @@ -449,7 +449,7 @@ class SchemaMetadataTemplateTests: XCTestCase { GraphQLInputObjectType.mock("InputObjectC"), ], schemaRootTypes: .mock()), config: .mock( - .swiftPackageManager(), + .swiftPackage(), schemaNamespace: "ObjectSchema" ) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift index b416ba20a..e71e7780a 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift @@ -625,9 +625,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -696,9 +696,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -4694,9 +4694,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), @@ -4762,9 +4762,9 @@ class SelectionSetTemplateTests: XCTestCase { """ let tests: [ApolloCodegenConfiguration.FileOutput] = [ - .mock(moduleType: .swiftPackageManager(), operations: .relative(subpath: nil, accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .absolute(path: "custom", accessModifier: .public)), - .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + .mock(moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .absolute(path: "custom", accessModifier: .public)), + .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), .mock(moduleType: .other, operations: .relative(subpath: nil, accessModifier: .public)), .mock(moduleType: .other, operations: .absolute(path: "custom", accessModifier: .public)), .mock(moduleType: .other, operations: .inSchemaModule), diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift index 97381c840..f7a549c91 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_ErrorHandling_Tests.swift @@ -43,7 +43,7 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase { ) let config = ApolloCodegenConfiguration.mock( schemaNamespace: "TestSchema", - output: .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + output: .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), experimentalFeatures: .init( fieldMerging: fieldMerging ) @@ -68,7 +68,7 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase { let fragment = await ir.build(fragment: fragmentDefinition) let config = ApolloCodegenConfiguration.mock( schemaNamespace: "TestSchema", - output: .mock(moduleType: .swiftPackageManager(), operations: .inSchemaModule), + output: .mock(moduleType: .swiftPackage(), operations: .inSchemaModule), options: .init() ) let mockTemplateRenderer = MockTemplateRenderer( diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift index 384a1f99c..8b1dd1958 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift @@ -30,7 +30,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { func buildSubjectAndOperation( named operationName: String = "TestOperation", schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackage(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) @@ -58,7 +58,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { func buildSubjectAndFragment( named fragmentName: String = "TestFragment", schemaNamespace: String = "TestSchema", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackage(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws -> IRTestWrapper { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) @@ -115,7 +115,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule ) @@ -181,7 +181,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .public) ) @@ -203,7 +203,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .relative(subpath: nil, accessModifier: .internal) ) @@ -225,7 +225,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .public) ) @@ -247,7 +247,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { """ try await buildSubjectAndOperation( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .absolute(path: "", accessModifier: .internal) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift index 8d70e74d3..255cb4c4d 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift @@ -30,7 +30,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { func buildSubjectAndOperation( schemaNamespace: String = "TestSchema", named operationName: String = "TestOperation", - moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackageManager(), + moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType = .swiftPackage(), operations: ApolloCodegenConfiguration.OperationsFileOutput = .inSchemaModule ) async throws { ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index 5e3df989c..8b53fa87e 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -15,12 +15,12 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { private func buildSubject( testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput = .none, config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule"), - version: ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion = .default + dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType = .default ) { subject = .init( testMockConfig: testMockConfig, config: .init(config: config), - version: version + dependencyType: dependencyType ) } @@ -152,7 +152,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesDefaultVersionDependency() { // given - buildSubject(version: .default) + buildSubject(dependencyType: .default) let expected = """ dependencies: [ @@ -169,7 +169,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesBranchVersionDependency() { // given let branchName = "testBranch" - buildSubject(version: .branch(name: branchName)) + buildSubject(dependencyType: .branch(name: branchName)) let expected = """ dependencies: [ @@ -186,7 +186,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesCommitVersionDependency() { // given let hash = "testHash" - buildSubject(version: .commit(hash: hash)) + buildSubject(dependencyType: .commit(hash: hash)) let expected = """ dependencies: [ @@ -203,7 +203,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesLocalVersionDependency() { // given let path = "localPath" - buildSubject(version: .local(path: path)) + buildSubject(dependencyType: .local(path: path)) let expected = """ dependencies: [ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift index bfe5da523..e3def51b5 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift @@ -45,9 +45,9 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), + (schemaTypes: .swiftPackage(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackage(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackage(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -93,17 +93,17 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { expectation: String )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedAPI ), @@ -176,17 +176,17 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { expectation: String )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedAPIAndSchema ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedAPI ), @@ -269,19 +269,19 @@ class TemplateRenderer_OperationFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 7 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 7 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift index 2c3d7d5fc..3c4dcd33d 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_SchemaFile_Tests.swift @@ -45,9 +45,9 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), + (schemaTypes: .swiftPackage(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackage(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackage(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -80,15 +80,15 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil) ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path") ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule ), ( @@ -141,15 +141,15 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil) ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path") ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule ), ( @@ -237,19 +237,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -330,17 +330,17 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, atLine: 6 ), @@ -441,19 +441,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -569,19 +569,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -697,19 +697,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -827,19 +827,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -957,19 +957,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 @@ -1087,19 +1087,19 @@ class TemplateRenderer_SchemaFile_Tests: XCTestCase { atLine: Int )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), expectation: expectedNoNamespace, atLine: 6 ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, expectation: expectedNoNamespace, atLine: 6 diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift index b7b9d6389..df2e46183 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_TestMockFile_Tests.swift @@ -39,9 +39,9 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType, operations: ApolloCodegenConfiguration.OperationsFileOutput )] = [ - (schemaTypes: .swiftPackageManager(), operations: .relative(subpath: nil)), - (schemaTypes: .swiftPackageManager(), operations: .absolute(path: "path")), - (schemaTypes: .swiftPackageManager(), operations: .inSchemaModule), + (schemaTypes: .swiftPackage(), operations: .relative(subpath: nil)), + (schemaTypes: .swiftPackage(), operations: .absolute(path: "path")), + (schemaTypes: .swiftPackage(), operations: .inSchemaModule), (schemaTypes: .other, operations: .relative(subpath: nil)), (schemaTypes: .other, operations: .absolute(path: "path")), (schemaTypes: .other, operations: .inSchemaModule), @@ -70,17 +70,17 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { importModuleName: String )] = [ ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .relative(subpath: nil), importModuleName: "TestSchema" ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .absolute(path: "path"), importModuleName: "TestSchema" ), ( - schemaTypes: .swiftPackageManager(), + schemaTypes: .swiftPackage(), operations: .inSchemaModule, importModuleName: "TestSchema" ), @@ -141,7 +141,7 @@ class TemplateRenderer_TestMockFile_Tests: XCTestCase { """ let config = buildConfig( - moduleType: .swiftPackageManager(), + moduleType: .swiftPackage(), operations: .inSchemaModule, cocoapodsCompatibleImportStatements: true ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift index 3bb1daff8..0fc7c74a4 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift @@ -203,7 +203,7 @@ class UnionTemplateTests: XCTestCase { func test_render_givenSchemaUnion_schemaTypesNotEmbeddedInTarget_generatesPossibleTypesPropertyWithoutSchemaNamespace() throws { // given - buildSubject(config: .mock(.swiftPackageManager())) + buildSubject(config: .mock(.swiftPackage())) let expected = """ possibleTypes: [ diff --git a/Tests/CodegenCLITests/Commands/GenerateTests.swift b/Tests/CodegenCLITests/Commands/GenerateTests.swift index 6e6d50d4b..bff729150 100644 --- a/Tests/CodegenCLITests/Commands/GenerateTests.swift +++ b/Tests/CodegenCLITests/Commands/GenerateTests.swift @@ -211,7 +211,7 @@ class GenerateTests: XCTestCase { schemaPath: "./schema.graphqls" ), output: .init( - schemaTypes: .init(path: ".", moduleType: .swiftPackageManager()) + schemaTypes: .init(path: ".", moduleType: .swiftPackage()) ) ) diff --git a/Tests/CodegenCLITests/Commands/InitializeTests.swift b/Tests/CodegenCLITests/Commands/InitializeTests.swift index d3f32c6c5..5542cb34c 100644 --- a/Tests/CodegenCLITests/Commands/InitializeTests.swift +++ b/Tests/CodegenCLITests/Commands/InitializeTests.swift @@ -333,7 +333,7 @@ class InitializeTests: XCTestCase { // then let decoded = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encoded) - expect(decoded.output.schemaTypes.moduleType).to(equal(.swiftPackageManager())) + expect(decoded.output.schemaTypes.moduleType).to(equal(.swiftPackage())) } func test__moduleType__givenModuleTypeExpressibleByArgument_other_shouldEqualSchemaTypesFileOutputModuleType_other() throws { diff --git a/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift b/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift index e72f0f933..4cf10432a 100644 --- a/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift +++ b/Tests/CodegenCLITests/Support/MockApolloCodegenConfiguration.swift @@ -9,7 +9,7 @@ extension ApolloCodegenConfiguration { schemaPath: "./schema.graphqls" ), output: .init( - schemaTypes: .init(path: ".", moduleType: .swiftPackageManager()) + schemaTypes: .init(path: ".", moduleType: .swiftPackage()) ), options: .init( operationDocumentFormat: [.definition, .operationId] diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index 34f34a86f..d55b28f0a 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -268,7 +268,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { moduleType: ModuleType ) { self.path = path - self.moduleType = moduleType + self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(dependencyType: .default) : moduleType } /// Compatible dependency manager automation. @@ -283,7 +283,12 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { case embeddedInTarget(name: String, accessModifier: AccessModifier = .internal) /// Generates a `Package.swift` file that is suitable for linking the generated schema types /// files to your project using Swift Package Manager. - case swiftPackageManager(version: ApolloPackageVersion = .default) + @available(*, deprecated, message: "Use .swiftPackage(dependencyType:) case instead.") + case swiftPackageManager + /// Generates a `Package.swift` file that is suitable for linking then generated schema types + /// files to your project using Swift Package Manager. Uses the `dependencyType` associated + /// value to determine how to setup the dependency on `apollo-ios`. + case swiftPackage(dependencyType: ApolloDependencyType = .default) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the /// module you will create in the `schemaNamespace` property as this will be used in `import` @@ -321,64 +326,67 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: + self = .swiftPackage(dependencyType: .default) + + case .swiftPackage: let nestedContainer = try container.nestedContainer( - keyedBy: SwiftPackageManagerCodingKeys.self, - forKey: .swiftPackageManager + keyedBy: SwiftPackageCodingKeys.self, + forKey: .swiftPackage ) - let version = try nestedContainer.decodeIfPresent(ApolloPackageVersion.self, forKey: .version) ?? .default - self = .swiftPackageManager(version: version) + let dependencyType = try nestedContainer.decodeIfPresent(ApolloDependencyType.self, forKey: .dependencyType) ?? .default + self = .swiftPackage(dependencyType: dependencyType) case .other: self = .other } } - } - - public enum ApolloPackageVersion: Codable, Equatable { - case `default` - case branch(name: String) - case commit(hash: String) - case local(path: String) - public init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - guard let key = container.allKeys.first else { - throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( - codingPath: container.codingPath, - debugDescription: "Invalid number of keys found, expected one.", - underlyingError: nil - )) - } + public enum ApolloDependencyType: Codable, Equatable { + case `default` + case branch(name: String) + case commit(hash: String) + case local(path: String) - switch key { - case .default: - self = .default - case .branch: - let nestedContainer = try container.nestedContainer( - keyedBy: BranchCodingKeys.self, - forKey: .branch - ) + public init(from decoder: any Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) - let name = try nestedContainer.decode(String.self, forKey: .name) - self = .branch(name: name) - case .commit: - let nestedContainer = try container.nestedContainer( - keyedBy: CommitCodingKeys.self, - forKey: .commit - ) - - let hash = try nestedContainer.decode(String.self, forKey: .hash) - self = .commit(hash: hash) - case .local: - let nestedContainer = try container.nestedContainer( - keyedBy: LocalCodingKeys.self, - forKey: .local - ) + guard let key = container.allKeys.first else { + throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( + codingPath: container.codingPath, + debugDescription: "Invalid number of keys found, expected one.", + underlyingError: nil + )) + } - let path = try nestedContainer.decode(String.self, forKey: .path) - self = .local(path: path) + switch key { + case .default: + self = .default + case .branch: + let nestedContainer = try container.nestedContainer( + keyedBy: BranchCodingKeys.self, + forKey: .branch + ) + + let name = try nestedContainer.decode(String.self, forKey: .name) + self = .branch(name: name) + case .commit: + let nestedContainer = try container.nestedContainer( + keyedBy: CommitCodingKeys.self, + forKey: .commit + ) + + let hash = try nestedContainer.decode(String.self, forKey: .hash) + self = .commit(hash: hash) + case .local: + let nestedContainer = try container.nestedContainer( + keyedBy: LocalCodingKeys.self, + forKey: .local + ) + + let path = try nestedContainer.decode(String.self, forKey: .path) + self = .local(path: path) + } } } } @@ -1239,7 +1247,7 @@ extension ApolloCodegenConfiguration.SchemaTypesFileOutput { var isInModule: Bool { switch moduleType { case .embeddedInTarget: return false - case .swiftPackageManager, .other: return true + case .swiftPackageManager, .swiftPackage, .other: return true } } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift index eea457385..552c74afd 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/ConfigurationValidation.swift @@ -34,11 +34,11 @@ extension ApolloCodegen.ConfigurationContext { } if case .swiftPackage = self.output.testMocks, - self.output.schemaTypes.moduleType != .swiftPackageManager() { + self.output.schemaTypes.moduleType != .swiftPackage() { throw ApolloCodegen.Error.testMocksInvalidSwiftPackageConfiguration } - if case .swiftPackageManager = self.output.schemaTypes.moduleType, + if case .swiftPackage = self.output.schemaTypes.moduleType, self.options.cocoapodsCompatibleImportStatements == true { throw ApolloCodegen.Error.invalidConfiguration(message: """ cocoapodsCompatibleImportStatements cannot be set to 'true' when the output schema types \ diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift index c7a57b5fc..0e8f33499 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift @@ -112,7 +112,7 @@ enum FileTarget: Equatable { forConfig config: ApolloCodegen.ConfigurationContext ) -> String { var moduleSubpath: String = "/" - if config.output.schemaTypes.moduleType == .swiftPackageManager() { + if config.output.schemaTypes.moduleType == .swiftPackage() { moduleSubpath += "Sources/" } if config.output.operations.isInModule { @@ -132,7 +132,7 @@ enum FileTarget: Equatable { switch config.output.operations { case .inSchemaModule: var url = URL(fileURLWithPath: config.output.schemaTypes.path, relativeTo: config.rootURL) - if config.output.schemaTypes.moduleType == .swiftPackageManager() { + if config.output.schemaTypes.moduleType == .swiftPackage() { url = url.appendingPathComponent("Sources") } @@ -167,7 +167,7 @@ enum FileTarget: Equatable { switch config.output.operations { case .inSchemaModule: var url = URL(fileURLWithPath: config.output.schemaTypes.path, relativeTo: config.rootURL) - if config.output.schemaTypes.moduleType == .swiftPackageManager() { + if config.output.schemaTypes.moduleType == .swiftPackage() { url = url.appendingPathComponent("Sources") } if !operation.isLocalCacheMutation { diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift index 797b37e23..d1e11d693 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift @@ -20,12 +20,19 @@ struct SchemaModuleFileGenerator { let errors: [ApolloCodegen.NonFatalError] switch config.output.schemaTypes.moduleType { - case .swiftPackageManager(let version): + case .swiftPackageManager: filePath = pathURL.appendingPathComponent("Package.swift").path (rendered, errors) = SwiftPackageManagerModuleTemplate( testMockConfig: config.output.testMocks, config: config, - version: version + dependencyType: .default + ).render() + case .swiftPackage(let dependencyType): + filePath = pathURL.appendingPathComponent("Package.swift").path + (rendered, errors) = SwiftPackageManagerModuleTemplate( + testMockConfig: config.output.testMocks, + config: config, + dependencyType: dependencyType ).render() case .embeddedInTarget: diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 0db58a04b..1c422f264 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -11,7 +11,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { let config: ApolloCodegen.ConfigurationContext - let version: ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion + let dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType func renderHeaderTemplate( nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder @@ -44,7 +44,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { """}) ], dependencies: [ - \(version.dependencyString), + \(dependencyType.dependencyString), ], targets: [ .target( @@ -84,7 +84,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { } } -fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ApolloPackageVersion { +fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType { var dependencyString: TemplateString { switch self { case .default: diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift index fd0118c72..c25f9d42b 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift @@ -250,6 +250,7 @@ extension TemplateRenderer { return ApolloCodegenConfiguration.AccessModifier.internal.swiftString case (.swiftPackageManager, _), + (.swiftPackage, _), (.other, _): return ApolloCodegenConfiguration.AccessModifier.public.swiftString } @@ -378,7 +379,7 @@ fileprivate extension ApolloCodegenConfiguration { var schemaModuleName: String { switch output.schemaTypes.moduleType { case let .embeddedInTarget(targetName, _): return targetName - case .swiftPackageManager, .other: return schemaNamespace.firstUppercased + case .swiftPackageManager, .swiftPackage, .other: return schemaNamespace.firstUppercased } } } From 5f2bc7b7a7690f983e40baf80ca7c787e113ffea Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:28:57 -0500 Subject: [PATCH 04/10] Addressing feedback --- ...olloCodegenConfigurationCodableTests.swift | 20 ++++----- ...iftPackageManagerModuleTemplateTests.swift | 42 +++++++++++++++---- .../ApolloCodegenConfiguration.swift | 14 +++---- .../SchemaModuleFileGenerator.swift | 13 ++---- .../SwiftPackageManagerModuleTemplate.swift | 21 ++++++++-- 5 files changed, 72 insertions(+), 38 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index 1fc023e52..6c535e9b1 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1315,7 +1315,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "default" : { } @@ -1507,7 +1507,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "default" : { } @@ -1638,7 +1638,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(dependencyType: .default) + moduleType: .swiftPackage(apolloSDKVersion: .default) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1699,7 +1699,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "default" : { } @@ -1739,7 +1739,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(dependencyType: .branch(name: "branchName")) + moduleType: .swiftPackage(apolloSDKVersion: .branch(name: "branchName")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1800,7 +1800,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "branch" : { "name" : "branchName" } @@ -1840,7 +1840,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(dependencyType: .commit(hash: "hash")) + moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: "hash")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1901,7 +1901,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "commit" : { "hash" : "hash" } @@ -1941,7 +1941,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(dependencyType: .local(path: "path")) + moduleType: .swiftPackage(apolloSDKVersion: .local(path: "path")) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -2002,7 +2002,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "dependencyType" : { + "apolloSDKVersion" : { "local" : { "path" : "path" } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index 8b53fa87e..5b47856a4 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -14,13 +14,11 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { private func buildSubject( testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput = .none, - config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule"), - dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType = .default + config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule") ) { subject = .init( testMockConfig: testMockConfig, - config: .init(config: config), - dependencyType: dependencyType + config: .init(config: config) ) } @@ -152,7 +150,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesDefaultVersionDependency() { // given - buildSubject(dependencyType: .default) + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .default) + )) + )) let expected = """ dependencies: [ @@ -169,7 +174,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesBranchVersionDependency() { // given let branchName = "testBranch" - buildSubject(dependencyType: .branch(name: branchName)) + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .branch(name: branchName)) + )) + )) let expected = """ dependencies: [ @@ -186,7 +198,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesCommitVersionDependency() { // given let hash = "testHash" - buildSubject(dependencyType: .commit(hash: hash)) + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: hash)) + )) + )) let expected = """ dependencies: [ @@ -203,7 +222,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { func test__packageDescription__generatesLocalVersionDependency() { // given let path = "localPath" - buildSubject(dependencyType: .local(path: path)) + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .local(path: path)) + )) + )) let expected = """ dependencies: [ diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index d55b28f0a..e530fdbf6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -268,7 +268,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { moduleType: ModuleType ) { self.path = path - self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(dependencyType: .default) : moduleType + self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKVersion: .default) : moduleType } /// Compatible dependency manager automation. @@ -283,12 +283,12 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { case embeddedInTarget(name: String, accessModifier: AccessModifier = .internal) /// Generates a `Package.swift` file that is suitable for linking the generated schema types /// files to your project using Swift Package Manager. - @available(*, deprecated, message: "Use .swiftPackage(dependencyType:) case instead.") + /// Attention: This case has been deprecated, use .swiftPackage(apolloSDKVersion:) case instead. case swiftPackageManager /// Generates a `Package.swift` file that is suitable for linking then generated schema types /// files to your project using Swift Package Manager. Uses the `dependencyType` associated /// value to determine how to setup the dependency on `apollo-ios`. - case swiftPackage(dependencyType: ApolloDependencyType = .default) + case swiftPackage(apolloSDKVersion: ApolloSDKVersion = .default) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the /// module you will create in the `schemaNamespace` property as this will be used in `import` @@ -326,7 +326,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: - self = .swiftPackage(dependencyType: .default) + self = .swiftPackage(apolloSDKVersion: .default) case .swiftPackage: let nestedContainer = try container.nestedContainer( @@ -334,15 +334,15 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { forKey: .swiftPackage ) - let dependencyType = try nestedContainer.decodeIfPresent(ApolloDependencyType.self, forKey: .dependencyType) ?? .default - self = .swiftPackage(dependencyType: dependencyType) + let apolloSDKVersion = try nestedContainer.decodeIfPresent(ApolloSDKVersion.self, forKey: .apolloSDKVersion) ?? .default + self = .swiftPackage(apolloSDKVersion: apolloSDKVersion) case .other: self = .other } } - public enum ApolloDependencyType: Codable, Equatable { + public enum ApolloSDKVersion: Codable, Equatable { case `default` case branch(name: String) case commit(hash: String) diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift index d1e11d693..ca524e5b6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift @@ -20,19 +20,12 @@ struct SchemaModuleFileGenerator { let errors: [ApolloCodegen.NonFatalError] switch config.output.schemaTypes.moduleType { - case .swiftPackageManager: + case .swiftPackageManager, + .swiftPackage(_): filePath = pathURL.appendingPathComponent("Package.swift").path (rendered, errors) = SwiftPackageManagerModuleTemplate( testMockConfig: config.output.testMocks, - config: config, - dependencyType: .default - ).render() - case .swiftPackage(let dependencyType): - filePath = pathURL.appendingPathComponent("Package.swift").path - (rendered, errors) = SwiftPackageManagerModuleTemplate( - testMockConfig: config.output.testMocks, - config: config, - dependencyType: dependencyType + config: config ).render() case .embeddedInTarget: diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 1c422f264..4574de8b8 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -11,7 +11,22 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { let config: ApolloCodegen.ConfigurationContext - let dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType + let apolloSDKVersion: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion + + init( + testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput, + config: ApolloCodegen.ConfigurationContext + ) { + self.testMockConfig = testMockConfig + self.config = config + + switch config.config.output.schemaTypes.moduleType { + case .swiftPackage(let apolloSDKVersion): + self.apolloSDKVersion = apolloSDKVersion + default: + self.apolloSDKVersion = .default + } + } func renderHeaderTemplate( nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder @@ -44,7 +59,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { """}) ], dependencies: [ - \(dependencyType.dependencyString), + \(apolloSDKVersion.dependencyString), ], targets: [ .target( @@ -84,7 +99,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { } } -fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType { +fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion { var dependencyString: TemplateString { switch self { case .default: From f8e9713fb01c149170f6bcf7e53f6115947db465 Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:03:34 -0500 Subject: [PATCH 05/10] Adding custom package type case --- .../ApolloCodegenConfiguration.swift | 18 ++++++++++++++++++ .../SwiftPackageManagerModuleTemplate.swift | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index e530fdbf6..ed2025742 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -346,8 +346,16 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { case `default` case branch(name: String) case commit(hash: String) + case custom(url: String, dependencyType: DependencyType, value: String) case local(path: String) + public enum DependencyType: String, Codable, Equatable { + case branch = "branch" + case exact = "exact" + case from = "from" + case revision = "revision" + } + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) @@ -378,6 +386,16 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { let hash = try nestedContainer.decode(String.self, forKey: .hash) self = .commit(hash: hash) + case .custom: + let nestedContainer = try container.nestedContainer( + keyedBy: CustomCodingKeys.self, + forKey: .custom + ) + + let url = try nestedContainer.decode(String.self, forKey: .url) + let dependencyType = try nestedContainer.decode(DependencyType.self, forKey: .dependencyType) + let value = try nestedContainer.decode(String.self, forKey: .value) + self = .custom(url: url, dependencyType: dependencyType, value: value) case .local: let nestedContainer = try container.nestedContainer( keyedBy: LocalCodingKeys.self, diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 4574de8b8..2cd73749c 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -114,6 +114,10 @@ fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleTyp return """ .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)") """ + case .custom(let url, let dependencyType, let value): + return """ + .package(url: "\(url)", \(dependencyType.rawValue): "\(value)") + """ case .local(let path): return """ .package(path: "\(path)") From 38a8700f8ce62cd08ffb7653bf6f5b1c8d3a5f5d Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:25:02 -0500 Subject: [PATCH 06/10] Change case name and add tests --- ...olloCodegenConfigurationCodableTests.swift | 420 ++++++++++++++++++ ...iftPackageManagerModuleTemplateTests.swift | 100 +++++ .../ApolloCodegenConfiguration.swift | 29 +- .../SwiftPackageManagerModuleTemplate.swift | 4 +- 4 files changed, 541 insertions(+), 12 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index 6c535e9b1..a2d9d18f6 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -2029,4 +2029,424 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { expect(actualStruct).to(equal(decodedStruct)) } + func test__codableSPMModuleType_withForkAndExactVersion() throws { + let url = "myFork" + let version = "1.2.3" + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .exactVersion, value: version)) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "apolloSDKVersion" : { + "fork" : { + "dependencyType" : "exactVersion", + "url" : "\(url)", + "value" : "\(version)" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withForkAndFromVersion() throws { + let url = "myFork" + let version = "1.2.3" + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .fromVersion, value: version)) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "apolloSDKVersion" : { + "fork" : { + "dependencyType" : "fromVersion", + "url" : "\(url)", + "value" : "\(version)" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withForkAndBranchName() throws { + let url = "myFork" + let branchName = "myBranch" + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .branchName, value: branchName)) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "apolloSDKVersion" : { + "fork" : { + "dependencyType" : "branchName", + "url" : "\(url)", + "value" : "\(branchName)" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + + func test__codableSPMModuleType_withForkAndCommitHash() throws { + let url = "myFork" + let commitHash = "myHash" + var decodedStruct: ApolloCodegenConfiguration { + .init( + schemaNamespace: "SerializedSchema", + input: .init( + schemaPath: "/path/to/schema.graphqls", + operationSearchPaths: [ + "/search/path/**/*.graphql" + ] + ), + output: .init( + schemaTypes: .init( + path: "/output/path", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .commitHash, value: commitHash)) + ), + operations: .absolute(path: "/absolute/path", accessModifier: .internal) + ) + ) + } + + var encodedJSON: String { + """ + { + "experimentalFeatures" : { + "fieldMerging" : [ + "all" + ], + "legacySafelistingCompatibleOperations" : false + }, + "input" : { + "operationSearchPaths" : [ + "/search/path/**/*.graphql" + ], + "schemaSearchPaths" : [ + "/path/to/schema.graphqls" + ] + }, + "options" : { + "additionalInflectionRules" : [ + + ], + "cocoapodsCompatibleImportStatements" : false, + "conversionStrategies" : { + "enumCases" : "camelCase", + "fieldAccessors" : "idiomatic", + "inputObjects" : "camelCase" + }, + "deprecatedEnumCases" : "include", + "markOperationDefinitionsAsFinal" : false, + "operationDocumentFormat" : [ + "definition" + ], + "pruneGeneratedFiles" : true, + "schemaCustomization" : { + "customTypeNames" : { + + } + }, + "schemaDocumentation" : "include", + "selectionSetInitializers" : { + + }, + "warningsOnDeprecatedUsage" : "include" + }, + "output" : { + "operations" : { + "absolute" : { + "accessModifier" : "internal", + "path" : "/absolute/path" + } + }, + "schemaTypes" : { + "moduleType" : { + "swiftPackage" : { + "apolloSDKVersion" : { + "fork" : { + "dependencyType" : "commitHash", + "url" : "\(url)", + "value" : "\(commitHash)" + } + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + expect(actualJSON).to(equalLineByLine(encodedJSON)) + + let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) + expect(actualStruct).to(equal(decodedStruct)) + } + } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index 5b47856a4..68679ade0 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -242,6 +242,106 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { // then expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) } + + func test__packageDescription__generatesForkVersionDependencyWithExactVersion() { + // given + let url = "myFork" + let version = "1.2.3" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .exactVersion, value: version)) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "\(url)", exact: "\(version)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesForkVersionDependencyWithFromVersion() { + // given + let url = "myFork" + let version = "1.2.3" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .fromVersion, value: version)) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "\(url)", from: "\(version)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesForkVersionDependencyWithBranchName() { + // given + let url = "myFork" + let branchName = "myBranch" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .branchName, value: branchName)) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "\(url)", branch: "\(branchName)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesForkVersionDependencyWithCommitHash() { + // given + let url = "myFork" + let commitHash = "myHash" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .commitHash, value: commitHash)) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "\(url)", revision: "\(commitHash)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } func test__packageDescription__givenTestMockConfigNone_withLowercaseSchemaName_generatesTargetWithCapitalizedName() { // given diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index ed2025742..4806080e5 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -286,7 +286,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { /// Attention: This case has been deprecated, use .swiftPackage(apolloSDKVersion:) case instead. case swiftPackageManager /// Generates a `Package.swift` file that is suitable for linking then generated schema types - /// files to your project using Swift Package Manager. Uses the `dependencyType` associated + /// files to your project using Swift Package Manager. Uses the `apolloSDKVersion` associated /// value to determine how to setup the dependency on `apollo-ios`. case swiftPackage(apolloSDKVersion: ApolloSDKVersion = .default) /// No module will be created for the generated types and you are required to create the @@ -346,14 +346,23 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { case `default` case branch(name: String) case commit(hash: String) - case custom(url: String, dependencyType: DependencyType, value: String) + case fork(url: String, dependencyType: DependencyType, value: String) case local(path: String) public enum DependencyType: String, Codable, Equatable { - case branch = "branch" - case exact = "exact" - case from = "from" - case revision = "revision" + case branchName + case commitHash + case exactVersion + case fromVersion + + public var propertyString: String { + switch self { + case .branchName: return "branch" + case .commitHash: return "revision" + case .exactVersion: return "exact" + case .fromVersion: return "from" + } + } } public init(from decoder: any Decoder) throws { @@ -386,16 +395,16 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { let hash = try nestedContainer.decode(String.self, forKey: .hash) self = .commit(hash: hash) - case .custom: + case .fork: let nestedContainer = try container.nestedContainer( - keyedBy: CustomCodingKeys.self, - forKey: .custom + keyedBy: ForkCodingKeys.self, + forKey: .fork ) let url = try nestedContainer.decode(String.self, forKey: .url) let dependencyType = try nestedContainer.decode(DependencyType.self, forKey: .dependencyType) let value = try nestedContainer.decode(String.self, forKey: .value) - self = .custom(url: url, dependencyType: dependencyType, value: value) + self = .fork(url: url, dependencyType: dependencyType, value: value) case .local: let nestedContainer = try container.nestedContainer( keyedBy: LocalCodingKeys.self, diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 2cd73749c..534d01174 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -114,9 +114,9 @@ fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleTyp return """ .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)") """ - case .custom(let url, let dependencyType, let value): + case .fork(let url, let dependencyType, let value): return """ - .package(url: "\(url)", \(dependencyType.rawValue): "\(value)") + .package(url: "\(url)", \(dependencyType.propertyString): "\(value)") """ case .local(let path): return """ From d4fa49f5e50ad023191acd3302aef20d560c965c Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:30:27 -0500 Subject: [PATCH 07/10] Addressing feedback --- ...olloCodegenConfigurationCodableTests.swift | 242 ++++++------------ ...iftPackageManagerModuleTemplateTests.swift | 94 ++----- .../ApolloCodegenConfiguration.swift | 144 ++++++----- .../SwiftPackageManagerModuleTemplate.swift | 28 +- 4 files changed, 198 insertions(+), 310 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index a2d9d18f6..bf3113b31 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1315,10 +1315,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "default" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "default" : { - } + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -1507,10 +1510,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "default" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "default" : { - } + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -1638,7 +1644,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .default) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency()) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1699,10 +1705,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "default" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "default" : { - } + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -1739,7 +1748,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .branch(name: "branchName")) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .branch(name: "branchName") + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1800,10 +1811,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "branch" : { - "name" : "branchName" - } + "apolloSDKDependency" : { + "sdkVersion" : { + "branch" : { + "name" : "branchName" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -1840,7 +1854,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: "hash")) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .commit(hash: "hash") + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -1901,10 +1917,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "commit" : { - "hash" : "hash" - } + "apolloSDKDependency" : { + "sdkVersion" : { + "commit" : { + "hash" : "hash" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -1928,7 +1947,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { expect(actualStruct).to(equal(decodedStruct)) } - func test__codableSPMModuleType_withLocalPathVersion() throws { + func test__codableSPMModuleType_withExactVersion() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -1941,7 +1960,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .local(path: "path")) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .exact(version: "1.2.3") + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -2002,10 +2023,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "local" : { - "path" : "path" - } + "apolloSDKDependency" : { + "sdkVersion" : { + "exact" : { + "version" : "1.2.3" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -2029,9 +2053,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { expect(actualStruct).to(equal(decodedStruct)) } - func test__codableSPMModuleType_withForkAndExactVersion() throws { - let url = "myFork" - let version = "1.2.3" + func test__codableSPMModuleType_withFromVersion() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -2044,7 +2066,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .exactVersion, value: version)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .from(version: "1.2.3") + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -2105,12 +2129,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "fork" : { - "dependencyType" : "exactVersion", - "url" : "\(url)", - "value" : "\(version)" - } + "apolloSDKDependency" : { + "sdkVersion" : { + "from" : { + "version" : "1.2.3" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -2134,9 +2159,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { expect(actualStruct).to(equal(decodedStruct)) } - func test__codableSPMModuleType_withForkAndFromVersion() throws { - let url = "myFork" - let version = "1.2.3" + func test__codableSPMModuleType_withLocalPathVersion() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -2149,7 +2172,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .fromVersion, value: version)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .local(path: "path") + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -2210,12 +2235,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "fork" : { - "dependencyType" : "fromVersion", - "url" : "\(url)", - "value" : "\(version)" - } + "apolloSDKDependency" : { + "sdkVersion" : { + "local" : { + "path" : "path" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" } } }, @@ -2239,9 +2265,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { expect(actualStruct).to(equal(decodedStruct)) } - func test__codableSPMModuleType_withForkAndBranchName() throws { - let url = "myFork" - let branchName = "myBranch" + func test__codableSPMModuleType_withCustomURL() throws { var decodedStruct: ApolloCodegenConfiguration { .init( schemaNamespace: "SerializedSchema", @@ -2254,7 +2278,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .branchName, value: branchName)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + url: "www.myurl.com" + )) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) @@ -2315,117 +2341,13 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "schemaTypes" : { "moduleType" : { "swiftPackage" : { - "apolloSDKVersion" : { - "fork" : { - "dependencyType" : "branchName", - "url" : "\(url)", - "value" : "\(branchName)" - } - } - } - }, - "path" : "/output/path" - }, - "testMocks" : { - "none" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "default" : { - } - } - }, - "schemaNamespace" : "SerializedSchema" - } - """ - } - - let actualJSON = try testJSONEncoder.encode(decodedStruct).asString - expect(actualJSON).to(equalLineByLine(encodedJSON)) - - let actualStruct = try JSONDecoder().decode(ApolloCodegenConfiguration.self, from: encodedJSON.asData) - expect(actualStruct).to(equal(decodedStruct)) - } - - func test__codableSPMModuleType_withForkAndCommitHash() throws { - let url = "myFork" - let commitHash = "myHash" - var decodedStruct: ApolloCodegenConfiguration { - .init( - schemaNamespace: "SerializedSchema", - input: .init( - schemaPath: "/path/to/schema.graphqls", - operationSearchPaths: [ - "/search/path/**/*.graphql" - ] - ), - output: .init( - schemaTypes: .init( - path: "/output/path", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .commitHash, value: commitHash)) - ), - operations: .absolute(path: "/absolute/path", accessModifier: .internal) - ) - ) - } - - var encodedJSON: String { - """ - { - "experimentalFeatures" : { - "fieldMerging" : [ - "all" - ], - "legacySafelistingCompatibleOperations" : false - }, - "input" : { - "operationSearchPaths" : [ - "/search/path/**/*.graphql" - ], - "schemaSearchPaths" : [ - "/path/to/schema.graphqls" - ] - }, - "options" : { - "additionalInflectionRules" : [ - - ], - "cocoapodsCompatibleImportStatements" : false, - "conversionStrategies" : { - "enumCases" : "camelCase", - "fieldAccessors" : "idiomatic", - "inputObjects" : "camelCase" - }, - "deprecatedEnumCases" : "include", - "markOperationDefinitionsAsFinal" : false, - "operationDocumentFormat" : [ - "definition" - ], - "pruneGeneratedFiles" : true, - "schemaCustomization" : { - "customTypeNames" : { - - } - }, - "schemaDocumentation" : "include", - "selectionSetInitializers" : { - - }, - "warningsOnDeprecatedUsage" : "include" - }, - "output" : { - "operations" : { - "absolute" : { - "accessModifier" : "internal", - "path" : "/absolute/path" - } - }, - "schemaTypes" : { - "moduleType" : { - "swiftPackage" : { - "apolloSDKVersion" : { - "fork" : { - "dependencyType" : "commitHash", - "url" : "\(url)", - "value" : "\(commitHash)" - } + } + }, + "url" : "www.myurl.com" } } }, diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index 68679ade0..200d49156 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -155,13 +155,13 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .default) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency()) )) )) let expected = """ dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", exact: "\(ApolloCodegenLib.Constants.CodegenVersion)"), + .package(url: "https://github.com/apollographql/apollo-ios", exact: "\(ApolloCodegenLib.Constants.CodegenVersion)"), ], """ // when @@ -179,13 +179,15 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .branch(name: branchName)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .branch(name: branchName) + )) )) )) let expected = """ dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", branch: "\(branchName)"), + .package(url: "https://github.com/apollographql/apollo-ios", branch: "\(branchName)"), ], """ // when @@ -203,13 +205,15 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: hash)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .commit(hash: hash) + )) )) )) let expected = """ dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)"), + .package(url: "https://github.com/apollographql/apollo-ios", revision: "\(hash)"), ], """ // when @@ -219,46 +223,23 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) } - func test__packageDescription__generatesLocalVersionDependency() { - // given - let path = "localPath" - buildSubject(config: .mock( - schemaNamespace: "TestModule", - output: .init( - schemaTypes: .init( - path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .local(path: path)) - )) - )) - - let expected = """ - dependencies: [ - .package(path: "\(path)"), - ], - """ - // when - let actual = renderSubject() - - // then - expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) - } - - func test__packageDescription__generatesForkVersionDependencyWithExactVersion() { + func test__packageDescription__generatesExactVersionDependency() { // given - let url = "myFork" let version = "1.2.3" buildSubject(config: .mock( schemaNamespace: "TestModule", output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .exactVersion, value: version)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .exact(version: version) + )) )) )) let expected = """ dependencies: [ - .package(url: "\(url)", exact: "\(version)"), + .package(url: "https://github.com/apollographql/apollo-ios", exact: "\(version)"), ], """ // when @@ -268,22 +249,23 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) } - func test__packageDescription__generatesForkVersionDependencyWithFromVersion() { + func test__packageDescription__generatesFromVersionDependency() { // given - let url = "myFork" let version = "1.2.3" buildSubject(config: .mock( schemaNamespace: "TestModule", output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .fromVersion, value: version)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .from(version: version) + )) )) )) let expected = """ dependencies: [ - .package(url: "\(url)", from: "\(version)"), + .package(url: "https://github.com/apollographql/apollo-ios", from: "\(version)"), ], """ // when @@ -293,47 +275,23 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) } - func test__packageDescription__generatesForkVersionDependencyWithBranchName() { - // given - let url = "myFork" - let branchName = "myBranch" - buildSubject(config: .mock( - schemaNamespace: "TestModule", - output: .init( - schemaTypes: .init( - path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .branchName, value: branchName)) - )) - )) - - let expected = """ - dependencies: [ - .package(url: "\(url)", branch: "\(branchName)"), - ], - """ - // when - let actual = renderSubject() - - // then - expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) - } - - func test__packageDescription__generatesForkVersionDependencyWithCommitHash() { + func test__packageDescription__generatesLocalVersionDependency() { // given - let url = "myFork" - let commitHash = "myHash" + let path = "localPath" buildSubject(config: .mock( schemaNamespace: "TestModule", output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKVersion: .fork(url: url, dependencyType: .commitHash, value: commitHash)) + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .local(path: path) + )) )) )) let expected = """ dependencies: [ - .package(url: "\(url)", revision: "\(commitHash)"), + .package(path: "\(path)"), ], """ // when diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index 4806080e5..96b202a6a 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -268,7 +268,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { moduleType: ModuleType ) { self.path = path - self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKVersion: .default) : moduleType + self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKDependency: ModuleType.ApolloSDKDependency()) : moduleType } /// Compatible dependency manager automation. @@ -288,7 +288,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { /// Generates a `Package.swift` file that is suitable for linking then generated schema types /// files to your project using Swift Package Manager. Uses the `apolloSDKVersion` associated /// value to determine how to setup the dependency on `apollo-ios`. - case swiftPackage(apolloSDKVersion: ApolloSDKVersion = .default) + case swiftPackage(apolloSDKDependency: ApolloSDKDependency = ApolloSDKDependency()) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the /// module you will create in the `schemaNamespace` property as this will be used in `import` @@ -326,7 +326,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: - self = .swiftPackage(apolloSDKVersion: .default) + self = .swiftPackage(apolloSDKDependency: ApolloSDKDependency()) case .swiftPackage: let nestedContainer = try container.nestedContainer( @@ -334,85 +334,89 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { forKey: .swiftPackage ) - let apolloSDKVersion = try nestedContainer.decodeIfPresent(ApolloSDKVersion.self, forKey: .apolloSDKVersion) ?? .default - self = .swiftPackage(apolloSDKVersion: apolloSDKVersion) + let apolloSDKDependency = try nestedContainer.decodeIfPresent(ApolloSDKDependency.self, forKey: .apolloSDKDependency) ?? ApolloSDKDependency() + self = .swiftPackage(apolloSDKDependency: apolloSDKDependency) case .other: self = .other } } - public enum ApolloSDKVersion: Codable, Equatable { - case `default` - case branch(name: String) - case commit(hash: String) - case fork(url: String, dependencyType: DependencyType, value: String) - case local(path: String) + public struct ApolloSDKDependency: Codable, Equatable { + let url: String + let sdkVersion: SDKVersion - public enum DependencyType: String, Codable, Equatable { - case branchName - case commitHash - case exactVersion - case fromVersion - - public var propertyString: String { - switch self { - case .branchName: return "branch" - case .commitHash: return "revision" - case .exactVersion: return "exact" - case .fromVersion: return "from" - } - } + public init( + url: String = "https://github.com/apollographql/apollo-ios", + sdkVersion: SDKVersion = .default + ) { + self.url = url + self.sdkVersion = sdkVersion } - public init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - guard let key = container.allKeys.first else { - throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( - codingPath: container.codingPath, - debugDescription: "Invalid number of keys found, expected one.", - underlyingError: nil - )) - } + public enum SDKVersion: Codable, Equatable { + case `default` + case branch(name: String) + case commit(hash: String) + case exact(version: String) + case from(version: String) + case local(path: String) - switch key { - case .default: - self = .default - case .branch: - let nestedContainer = try container.nestedContainer( - keyedBy: BranchCodingKeys.self, - forKey: .branch - ) + public init(from decoder: any Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) - let name = try nestedContainer.decode(String.self, forKey: .name) - self = .branch(name: name) - case .commit: - let nestedContainer = try container.nestedContainer( - keyedBy: CommitCodingKeys.self, - forKey: .commit - ) - - let hash = try nestedContainer.decode(String.self, forKey: .hash) - self = .commit(hash: hash) - case .fork: - let nestedContainer = try container.nestedContainer( - keyedBy: ForkCodingKeys.self, - forKey: .fork - ) - - let url = try nestedContainer.decode(String.self, forKey: .url) - let dependencyType = try nestedContainer.decode(DependencyType.self, forKey: .dependencyType) - let value = try nestedContainer.decode(String.self, forKey: .value) - self = .fork(url: url, dependencyType: dependencyType, value: value) - case .local: - let nestedContainer = try container.nestedContainer( - keyedBy: LocalCodingKeys.self, - forKey: .local - ) + guard let key = container.allKeys.first else { + throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( + codingPath: container.codingPath, + debugDescription: "Invalid number of keys found, expected one.", + underlyingError: nil + )) + } - let path = try nestedContainer.decode(String.self, forKey: .path) - self = .local(path: path) + switch key { + case .default: + self = .default + case .branch: + let nestedContainer = try container.nestedContainer( + keyedBy: BranchCodingKeys.self, + forKey: .branch + ) + + let name = try nestedContainer.decode(String.self, forKey: .name) + self = .branch(name: name) + case .commit: + let nestedContainer = try container.nestedContainer( + keyedBy: CommitCodingKeys.self, + forKey: .commit + ) + + let hash = try nestedContainer.decode(String.self, forKey: .hash) + self = .commit(hash: hash) + case .exact: + let nestedContainer = try container.nestedContainer( + keyedBy: ExactCodingKeys.self, + forKey: .exact + ) + + let version = try nestedContainer.decode(String.self, forKey: .version) + self = .exact(version: version) + case .from: + let nestedContainer = try container.nestedContainer( + keyedBy: FromCodingKeys.self, + forKey: .from + ) + + let version = try nestedContainer.decode(String.self, forKey: .version) + self = .from(version: version) + case .local: + let nestedContainer = try container.nestedContainer( + keyedBy: LocalCodingKeys.self, + forKey: .local + ) + + let path = try nestedContainer.decode(String.self, forKey: .path) + self = .local(path: path) + } } } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 534d01174..953f35661 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -11,7 +11,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { let config: ApolloCodegen.ConfigurationContext - let apolloSDKVersion: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion + let apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency init( testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput, @@ -21,10 +21,10 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { self.config = config switch config.config.output.schemaTypes.moduleType { - case .swiftPackage(let apolloSDKVersion): - self.apolloSDKVersion = apolloSDKVersion + case .swiftPackage(let apolloSDKDependency): + self.apolloSDKDependency = apolloSDKDependency default: - self.apolloSDKVersion = .default + self.apolloSDKDependency = ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency() } } @@ -59,7 +59,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { """}) ], dependencies: [ - \(apolloSDKVersion.dependencyString), + \(apolloSDKDependency.dependencyString), ], targets: [ .target( @@ -99,24 +99,28 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { } } -fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion { +fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency { var dependencyString: TemplateString { - switch self { + switch self.sdkVersion { case .default: return """ - .package(url: "https://github.com/apollographql/apollo-ios.git", exact: "\(Constants.CodegenVersion)") + .package(url: "\(self.url)", exact: "\(Constants.CodegenVersion)") """ case .branch(let name): return """ - .package(url: "https://github.com/apollographql/apollo-ios.git", branch: "\(name)") + .package(url: "\(self.url)", branch: "\(name)") """ case .commit(let hash): return """ - .package(url: "https://github.com/apollographql/apollo-ios.git", revision: "\(hash)") + .package(url: "\(self.url)", revision: "\(hash)") """ - case .fork(let url, let dependencyType, let value): + case .exact(let version): return """ - .package(url: "\(url)", \(dependencyType.propertyString): "\(value)") + .package(url: "\(self.url)", exact: "\(version)") + """ + case .from(let version): + return """ + .package(url: "\(self.url)", from: "\(version)") """ case .local(let path): return """ From 7be0e0c50b3341d11a1b9b1f51251bb8c4e3578c Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:17:15 -0500 Subject: [PATCH 08/10] Custom codable for SDKVersion enum --- ...olloCodegenConfigurationCodableTests.swift | 24 +--- .../ApolloCodegenConfiguration.swift | 113 +++++++++++++++++- 2 files changed, 115 insertions(+), 22 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index bf3113b31..7ba4d88d3 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1316,11 +1316,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackage" : { "apolloSDKDependency" : { - "sdkVersion" : { - "default" : { - - } - }, + "sdkVersion" : "default", "url" : "https://github.com/apollographql/apollo-ios" } } @@ -1511,11 +1507,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackage" : { "apolloSDKDependency" : { - "sdkVersion" : { - "default" : { - - } - }, + "sdkVersion" : "default", "url" : "https://github.com/apollographql/apollo-ios" } } @@ -1706,11 +1698,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackage" : { "apolloSDKDependency" : { - "sdkVersion" : { - "default" : { - - } - }, + "sdkVersion" : "default", "url" : "https://github.com/apollographql/apollo-ios" } } @@ -2342,11 +2330,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { "moduleType" : { "swiftPackage" : { "apolloSDKDependency" : { - "sdkVersion" : { - "default" : { - - } - }, + "sdkVersion" : "default", "url" : "www.myurl.com" } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index 96b202a6a..e969c1968 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -286,8 +286,8 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { /// Attention: This case has been deprecated, use .swiftPackage(apolloSDKVersion:) case instead. case swiftPackageManager /// Generates a `Package.swift` file that is suitable for linking then generated schema types - /// files to your project using Swift Package Manager. Uses the `apolloSDKVersion` associated - /// value to determine how to setup the dependency on `apollo-ios`. + /// files to your project using Swift Package Manager. Uses the `apolloSDKDependency` + /// to determine how to setup the dependency on `apollo-ios`. case swiftPackage(apolloSDKDependency: ApolloSDKDependency = ApolloSDKDependency()) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the @@ -342,8 +342,12 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { } } + /// Configuation for apollo-ios dependency in SPM modules public struct ApolloSDKDependency: Codable, Equatable { + /// URL for the SPM package dependency, not used for local dependencies. + /// Defaults to 'https://github.com/apollographql/apollo-ios'. let url: String + /// Type of SPM dependency to use. let sdkVersion: SDKVersion public init( @@ -354,14 +358,101 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self.sdkVersion = sdkVersion } + enum CodingKeys: CodingKey, CaseIterable { + case url + case sdkVersion + } + + public func encode(to encoder: any Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(self.url, forKey: .url) + + switch self.sdkVersion { + case .default: + try container.encode(self.sdkVersion.stringValue, forKey: .sdkVersion) + default: + try container.encode(self.sdkVersion, forKey: .sdkVersion) + } + } + + public init(from decoder: any Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + try throwIfContainsUnexpectedKey( + container: values, + type: Self.self, + decoder: decoder + ) + + url = try values.decode(String.self, forKey: .url) + + if let version = try? values.decodeIfPresent(SDKVersion.self, forKey: .sdkVersion) { + sdkVersion = version + } else if let versionString = try? values.decodeIfPresent(String.self, forKey: .sdkVersion) { + let version = try SDKVersion(fromString: versionString) + sdkVersion = version + } else { + throw DecodingError.typeMismatch(Self.self, DecodingError.Context.init( + codingPath: values.codingPath, + debugDescription: "No valid 'sdkVersion' provided.", + underlyingError: nil + )) + } + } + + /// Type of SPM dependency public enum SDKVersion: Codable, Equatable { + /// Configures SPM dependency to use the exact version of apollo-ios + /// that matches the code generation library version currently in use. + /// Results in a dependency that looks like: + /// '.package(url: "https://github.com/apollographql/apollo-ios.git", exact: "{version}")' case `default` + /// Configures SPM dependency to use the given branch name + /// for the apollo-ios dependency. + /// Results in a dependency that looks like: + /// '.package(url: "...", branch: "{name}")' case branch(name: String) + /// Configures SPM dependency to use the given commit hash + /// for the apollo-ios dependency. + /// Results in a dependency that looks like: + /// '.package(url: "...", revision: "{hash}")' case commit(hash: String) + /// Configures SPM dependency to use the given exact version + /// for the apollo-ios dependency. + /// Results in a dependency that looks like: + /// '.package(url: "...", exact: "{version}")' case exact(version: String) + /// Configures SPM dependency to use a version + /// starting at the given version for the apollo-ios dependency. + /// Results in a dependency that looks like: + /// '.package(url: "...", from: "{version}")' case from(version: String) + /// Configures SPM dependency to use a local + /// path for the apollo-ios dependency. + /// Results in a dependency that looks like: + /// '.package(path: "{path}")' case local(path: String) + public var stringValue: String { + switch self { + case .default: return "default" + case .branch(_): return "branch" + case .commit(_): return "commit" + case .exact(_): return "exact" + case .from(_): return "from" + case .local(_): return "local" + } + } + + public init(fromString str: String) throws { + switch str { + case Self.default.stringValue: + self = .default + default: + throw ApolloConfigurationError.invalidValueForKey(key: "sdkVersion", value: str) + } + } + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) @@ -1269,6 +1360,24 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { operationManifest: operationManifest ?? Default.operationManifest ) } + +} + +// MARK: Errors + +extension ApolloCodegenConfiguration { + public enum ApolloConfigurationError: Error, LocalizedError { + case invalidValueForKey(key: String, value: String) + + public var errorDescription: String? { + switch self { + case .invalidValueForKey(let key, let value): + return """ + Invalid value '\(value)' provided for key '\(key)'. + """ + } + } + } } // MARK: - Helpers From d2e9dcf106fdfb564e736d308aaf4510bf7199ab Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:21:01 -0500 Subject: [PATCH 09/10] Documentation --- ...olloCodegenConfigurationCodableTests.swift | 2 +- ...iftPackageManagerModuleTemplateTests.swift | 2 +- .../ApolloCodegenConfiguration.swift | 8 ++- .../SwiftPackageManagerModuleTemplate.swift | 2 +- .../code-generation/codegen-configuration.mdx | 61 +++++++++++++++++-- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index 7ba4d88d3..9e0b4e4eb 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1636,7 +1636,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { output: .init( schemaTypes: .init( path: "/output/path", - moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency()) + moduleType: .swiftPackage(apolloSDKDependency: .default) ), operations: .absolute(path: "/absolute/path", accessModifier: .internal) ) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift index 200d49156..6e086c9ca 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -155,7 +155,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { output: .init( schemaTypes: .init( path: "path/", - moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency()) + moduleType: .swiftPackage(apolloSDKDependency: .default) )) )) diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index e969c1968..cb5d9f2d6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift @@ -268,7 +268,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { moduleType: ModuleType ) { self.path = path - self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKDependency: ModuleType.ApolloSDKDependency()) : moduleType + self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKDependency: .default) : moduleType } /// Compatible dependency manager automation. @@ -288,7 +288,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { /// Generates a `Package.swift` file that is suitable for linking then generated schema types /// files to your project using Swift Package Manager. Uses the `apolloSDKDependency` /// to determine how to setup the dependency on `apollo-ios`. - case swiftPackage(apolloSDKDependency: ApolloSDKDependency = ApolloSDKDependency()) + case swiftPackage(apolloSDKDependency: ApolloSDKDependency = .default) /// No module will be created for the generated types and you are required to create the /// module to support your preferred dependency manager. You must specify the name of the /// module you will create in the `schemaNamespace` property as this will be used in `import` @@ -326,7 +326,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: - self = .swiftPackage(apolloSDKDependency: ApolloSDKDependency()) + self = .swiftPackage(apolloSDKDependency: .default) case .swiftPackage: let nestedContainer = try container.nestedContainer( @@ -350,6 +350,8 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { /// Type of SPM dependency to use. let sdkVersion: SDKVersion + public static let `default` = ApolloSDKDependency() + public init( url: String = "https://github.com/apollographql/apollo-ios", sdkVersion: SDKVersion = .default diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 953f35661..c544e1dfd 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -24,7 +24,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { case .swiftPackage(let apolloSDKDependency): self.apolloSDKDependency = apolloSDKDependency default: - self.apolloSDKDependency = ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency() + self.apolloSDKDependency = .default } } diff --git a/docs/source/code-generation/codegen-configuration.mdx b/docs/source/code-generation/codegen-configuration.mdx index 967a0a02d..35fc6268c 100644 --- a/docs/source/code-generation/codegen-configuration.mdx +++ b/docs/source/code-generation/codegen-configuration.mdx @@ -106,7 +106,7 @@ The properties to configure `output` are: "output": { "schemaTypes": { "moduleType": { - "swiftPackageManager": {} + "swiftPackage": {} }, "path": "./generated/schema/" }, @@ -125,7 +125,7 @@ let configuration = ApolloCodegenConfiguration( output: ApolloCodegenConfiguration.FileOutput( schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput( path: "./generated/schema/", - moduleType: .swiftPackageManager + moduleType: .swiftPackage() ) operations: .inSchemaModule, testMocks: .none @@ -156,7 +156,7 @@ Use the [`ModuleType`](https://www.apollographql.com/docs/ios/docc/documentation For single target applications, [`embeddedInTarget(name:)`](#embedded-in-target) can be used. -For multi-module projects, it is recommended that the schema types be created in a separate module to help with separation of concerns. If using Swift Package Manager, the `swiftPackageManager` option can help automate module creation. +For multi-module projects, it is recommended that the schema types be created in a separate module to help with separation of concerns. If using Swift Package Manager, the `swiftPackage` option can help automate module creation. > **Note:** This option must be set correctly for your project structure or generated code will fail to compile. @@ -165,7 +165,8 @@ The possible values for `moduleType` are: | Value | Description | | ----- | ----------- | | [`embeddedInTarget(name:accessModifier:)`](#embedded-in-target) | Indicates that you would like to include the generated module directly in your application target. | -| [`swiftPackageManager`](#swift-package-manager) | Creates a schema module as an SPM package that can be included in your project. | +| [`swiftPackageManager`](#swift-package-manager) | Creates a schema module as an SPM package that can be included in your project. Note: This option has been deprecated in favor of the new [`swiftPackage`](#swift-package) option. | +| [`swiftPackage`](#swift-package) | Creates a schema module as an SPM package that can be included in your project and allows for customization of the `apollo-ios` dependency of the pacakge. | | [`other`](#other-schema-module-types) | Indicates that you would like to manually define a schema module using a third party package manager (such as Cocoapods). | #### Embedded in target @@ -257,11 +258,59 @@ let configuration = ApolloCodegenConfiguration( +#### Swift package + +**[`ModuleType.swiftPackage(apolloSDKDependency: ApolloSDKDependency)`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration/schematypesfileoutput/moduletype-swift.enum/swiftpackage)** + +This option automates the creation of an SPM package for your schema types. This generates a `Package.swift` file that is suitable for linking the generated schema types files to your project using Swift Package Manager. + +The `apolloSDKDependency` paramter allows you to customize the `apollo-ios` dependency of your SPM package by providing a url and SDK version. The `url` parameter allows you to customize the location of the `apollo-ios` dependency used by the generated SPM package, and has a default value that points to the main [`apollo-ios`](https://github.com/apollographql/apollo-ios) repository. The `sdkVersion` parameter allows you to set the version of the `apollo-ios` dependency to use. The default value of this is the `default` case, which uses an exact version of `apollo-ios` matching the code generation version in use which is the recommended way of handling this. The other provided options allow flexibility for doing things such as testing experimental branches, or using local versions for testing. + +The schema types will be contained in a stand-alone module with the [`schemaNamespace`](#schema-namespace) provided. Other targets in your application that contain generated operation models must have a dependency on this target. + +For multi-module projects using Swift Package Manager, this is the recommended configuration option. + +> **Including schema types in your own `Package.swift` file:** +> +> This option generates an SPM package with its own `Package.swift` file. This is ideal if you want to share your schema module across multiple projects or using Xcode's Package Dependency GUI. +> +> If you would like to include your schema module as a target in your own `Package.swift` file, you can define a target with the name and path of the generated files in your `Package.swift` file. + + + +```json title="CLI Configuration JSON" +"output": { + "schemaTypes": { + "moduleType": { + "swiftPackage": { + "apolloSDKDependency" : {} + } + }, + "path": "./generated/schema/" + } +} +``` + +```swift title="Swift Codegen Setup" +let configuration = ApolloCodegenConfiguration( + // Other properties not shown + output: ApolloCodegenConfiguration.FileOutput( + schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput( + path: "./generated/schema/", + moduleType: .swiftPackage(apolloSDKDependency: .default) + ) + ... + ) +) +``` + + + #### Other schema module types **[`ModuleType.other`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration/schematypesfileoutput/moduletype-swift.enum/other)** -This value should be used when you would like to define a schema module using another package management system (such as CocoaPods), or you want more control over the generated package than what [`ModuleType.swiftPackageManager`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration/schematypesfileoutput/moduletype-swift.enum/swiftpackagemanager) allows, or manually creating your own targets or modules in another way. +This value should be used when you would like to define a schema module using another package management system (such as CocoaPods), or you want more control over the generated package than what [`ModuleType.swiftPackage`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration/schematypesfileoutput/moduletype-swift.enum/swiftpackage) allows, or manually creating your own targets or modules in another way. `ModuleType.other` indicates to the Code Generation Engine that your schema types will be contained in their own target, rather than embedded in your application target. This affects the `import` statements in your generated operation definition files. @@ -376,7 +425,7 @@ This option generates test mock files and defines a target in the schema modules The name of the test mock target can be specified with the `targetName` parameter. If no `targetName` is provided, the target name defaults to `"${schemaNamespace}TestMocks"`. -> **Note:** Using this option requires your [`output.schemaTypes.moduleType`](#module-type) to be [`.swiftPackageManager`](#swift-package-manager). If this option is provided without the `.swiftPackageManager` module type, code generation will fail. +> **Note:** Using this option requires your [`output.schemaTypes.moduleType`](#module-type) to be [`.swiftPackage`](#swift-package). If this option is provided without the `.swiftPackage` module type, code generation will fail. #### Absolute test mocks output From bb90255266ea9b6da65140096224327cf741729b Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:34:24 -0500 Subject: [PATCH 10/10] Addressing docs feedback --- docs/source/code-generation/codegen-configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/code-generation/codegen-configuration.mdx b/docs/source/code-generation/codegen-configuration.mdx index 35fc6268c..f2e40fb70 100644 --- a/docs/source/code-generation/codegen-configuration.mdx +++ b/docs/source/code-generation/codegen-configuration.mdx @@ -264,7 +264,7 @@ let configuration = ApolloCodegenConfiguration( This option automates the creation of an SPM package for your schema types. This generates a `Package.swift` file that is suitable for linking the generated schema types files to your project using Swift Package Manager. -The `apolloSDKDependency` paramter allows you to customize the `apollo-ios` dependency of your SPM package by providing a url and SDK version. The `url` parameter allows you to customize the location of the `apollo-ios` dependency used by the generated SPM package, and has a default value that points to the main [`apollo-ios`](https://github.com/apollographql/apollo-ios) repository. The `sdkVersion` parameter allows you to set the version of the `apollo-ios` dependency to use. The default value of this is the `default` case, which uses an exact version of `apollo-ios` matching the code generation version in use which is the recommended way of handling this. The other provided options allow flexibility for doing things such as testing experimental branches, or using local versions for testing. +The `apolloSDKDependency` paramter allows you to customize the `apollo-ios` dependency of your SPM package by providing a url and SDK version. The `url` parameter allows you to customize the location of the `apollo-ios` dependency used by the generated SPM package, and has a default value that points to the main [`apollo-ios`](https://github.com/apollographql/apollo-ios) repository. The `sdkVersion` parameter allows you to set the version of the `apollo-ios` dependency to use. The default value is the `default` case, which uses an exact version of `apollo-ios` matching the code generation version in use. This is the recommended configuration. The other provided options allow flexibility for doing things such as testing experimental branches, or using local versions for testing. The schema types will be contained in a stand-alone module with the [`schemaNamespace`](#schema-namespace) provided. Other targets in your application that contain generated operation models must have a dependency on this target.