diff --git a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift index aee606c90..9e0b4e4eb 100644 --- a/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift +++ b/Tests/ApolloCodegenTests/ApolloCodegenConfigurationCodableTests.swift @@ -1238,4 +1238,1121 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase { XCTAssertEqual(context.debugDescription, "Unrecognized keys found: contact_info, motto") } } + + // MARK: Module Type Tests + + 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" : { + "apolloSDKDependency" : { + "sdkVersion" : "default", + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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", + 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" : { + "swiftPackageManager" : { + + } + }, + "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" : { + "apolloSDKDependency" : { + "sdkVersion" : "default", + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "path" : "/output/path" + }, + "testMocks" : { + "none" : { + + } + } + }, + "schemaNamespace" : "SerializedSchema" + } + """ + } + + let actualJSON = try testJSONEncoder.encode(decodedStruct).asString + 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: .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" : { + + } + }, + "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_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: .swiftPackage(apolloSDKDependency: .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" : { + "swiftPackage" : { + "apolloSDKDependency" : { + "sdkVersion" : "default", + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_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: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .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" : { + "swiftPackage" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "branch" : { + "name" : "branchName" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_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: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .commit(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" : { + "swiftPackage" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "commit" : { + "hash" : "hash" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_withExactVersion() 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(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .exact(version: "1.2.3") + )) + ), + 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" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "exact" : { + "version" : "1.2.3" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_withFromVersion() 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(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .from(version: "1.2.3") + )) + ), + 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" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "from" : { + "version" : "1.2.3" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_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: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .local(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" : { + "swiftPackage" : { + "apolloSDKDependency" : { + "sdkVersion" : { + "local" : { + "path" : "path" + } + }, + "url" : "https://github.com/apollographql/apollo-ios" + } + } + }, + "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_withCustomURL() 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(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + url: "www.myurl.com" + )) + ), + 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" : { + "apolloSDKDependency" : { + "sdkVersion" : "default", + "url" : "www.myurl.com" + } + } + }, + "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/ApolloCodegenTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift index 9a58e9c02..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 32b74170a..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 f4fd41a06..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 5aeea32ec..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 f8826be32..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 4d0a61041..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 ff1ebbff7..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 8fc52f075..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 7bc49141c..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 db265d758..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 eecf31d2f..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 4bfb028cc..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 b4a957939..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 57b16366f..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 88d9b4c9f..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 34f09a246..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 769e25324..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 572ba8382..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 51223c2a4..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 50d22d7d1..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 d7962437b..6e086c9ca 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SwiftPackageManagerModuleTemplateTests.swift @@ -148,13 +148,150 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 13, ignoringExtraLines: true)) } - func test__packageDescription__generatesNoDependencies() { + func test__packageDescription__generatesDefaultVersionDependency() { // given - buildSubject() + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKDependency: .default) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios", 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(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .branch(name: branchName) + )) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios", 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(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .commit(hash: hash) + )) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios", revision: "\(hash)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesExactVersionDependency() { + // given + let version = "1.2.3" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .exact(version: version) + )) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios", exact: "\(version)"), + ], + """ + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 16, ignoringExtraLines: true)) + } + + func test__packageDescription__generatesFromVersionDependency() { + // given + let version = "1.2.3" + buildSubject(config: .mock( + schemaNamespace: "TestModule", + output: .init( + schemaTypes: .init( + path: "path/", + moduleType: .swiftPackage(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .from(version: version) + )) + )) + )) + + let expected = """ + dependencies: [ + .package(url: "https://github.com/apollographql/apollo-ios", from: "\(version)"), + ], + """ + // when + let actual = renderSubject() + + // then + 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(apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency( + sdkVersion: .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/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateRenderer_OperationFile_Tests.swift index 53006c621..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 3741a7e1c..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 74ddae70f..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 f805ccf5b..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 53207066e..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 b4ea26cc7..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 047adff77..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/ApolloCodegenConfiguration.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift similarity index 89% rename from apollo-ios-codegen/Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift rename to apollo-ios-codegen/Sources/ApolloCodegenLib/CodegenConfiguration/ApolloCodegenConfiguration.swift index df4de29c4..cb5d9f2d6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/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(apolloSDKDependency: .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. + /// 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 `apolloSDKDependency` + /// to determine how to setup the dependency on `apollo-ios`. + 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` @@ -321,12 +326,193 @@ public struct ApolloCodegenConfiguration: Codable, Equatable { self = .embeddedInTarget(name: name, accessModifier: accessModifier) case .swiftPackageManager: - self = .swiftPackageManager + self = .swiftPackage(apolloSDKDependency: .default) + + case .swiftPackage: + let nestedContainer = try container.nestedContainer( + keyedBy: SwiftPackageCodingKeys.self, + forKey: .swiftPackage + ) + + let apolloSDKDependency = try nestedContainer.decodeIfPresent(ApolloSDKDependency.self, forKey: .apolloSDKDependency) ?? ApolloSDKDependency() + self = .swiftPackage(apolloSDKDependency: apolloSDKDependency) case .other: self = .other } } + + /// 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 static let `default` = ApolloSDKDependency() + + public init( + url: String = "https://github.com/apollographql/apollo-ios", + sdkVersion: SDKVersion = .default + ) { + self.url = url + 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) + + 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 .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) + } + } + } + } } } @@ -1176,6 +1362,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 @@ -1185,7 +1389,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 f644df9c4..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/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/FileGenerator.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/FileGenerator.swift index beb58147f..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 f47dec6d6..ca524e5b6 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/SchemaModuleFileGenerator.swift @@ -20,7 +20,8 @@ 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, diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift index 7c3fa07dc..c544e1dfd 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SwiftPackageManagerModuleTemplate.swift @@ -10,6 +10,23 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { let target: TemplateTarget = .moduleFile let config: ApolloCodegen.ConfigurationContext + + let apolloSDKDependency: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency + + init( + testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput, + config: ApolloCodegen.ConfigurationContext + ) { + self.testMockConfig = testMockConfig + self.config = config + + switch config.config.output.schemaTypes.moduleType { + case .swiftPackage(let apolloSDKDependency): + self.apolloSDKDependency = apolloSDKDependency + default: + self.apolloSDKDependency = .default + } + } func renderHeaderTemplate( nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder @@ -42,7 +59,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { """}) ], dependencies: [ - .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"), + \(apolloSDKDependency.dependencyString), ], targets: [ .target( @@ -81,3 +98,34 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer { } } } + +fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKDependency { + var dependencyString: TemplateString { + switch self.sdkVersion { + case .default: + return """ + .package(url: "\(self.url)", exact: "\(Constants.CodegenVersion)") + """ + case .branch(let name): + return """ + .package(url: "\(self.url)", branch: "\(name)") + """ + case .commit(let hash): + return """ + .package(url: "\(self.url)", revision: "\(hash)") + """ + case .exact(let version): + return """ + .package(url: "\(self.url)", exact: "\(version)") + """ + case .from(let version): + return """ + .package(url: "\(self.url)", from: "\(version)") + """ + case .local(let path): + return """ + .package(path: "\(path)") + """ + } + } +} 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 } } } 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/docs/source/code-generation/codegen-configuration.mdx b/docs/source/code-generation/codegen-configuration.mdx index 967a0a02d..f2e40fb70 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 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. + +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 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"