From 6133fa44bb626036d15ddacc1a14fa4617d58972 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Thu, 9 Jun 2022 15:15:59 -0700 Subject: [PATCH 01/17] fix: Correctly add public modifier on schema objects when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 3 +- .../FileGenerators/ObjectFileGenerator.swift | 5 +- .../Templates/ObjectTemplate.swift | 6 +- .../Templates/TemplateRenderer.swift | 8 +++ .../MockApolloCodegenConfiguration.swift | 24 +++++--- .../ObjectFileGeneratorTests.swift | 6 +- .../Templates/ObjectTemplateTests.swift | 60 ++++++++++++++++++- 7 files changed, 98 insertions(+), 14 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index cd601fbd11..3d8b95a381 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -105,7 +105,8 @@ public class ApolloCodegen { for graphQLObject in ir.schema.referencedTypes.objects { try autoreleasepool { try ObjectFileGenerator( - graphqlObject: graphQLObject + graphqlObject: graphQLObject, + config: config ).generate( forConfig: config, fileManager: fileManager diff --git a/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift index 9d6ac7fdd5..57bbd5a111 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/ObjectFileGenerator.swift @@ -1,12 +1,15 @@ import Foundation +import ApolloUtils /// Generates a file containing the Swift representation of a [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects). struct ObjectFileGenerator: FileGenerator { /// Source GraphQL object. let graphqlObject: GraphQLObjectType + /// Shared codegen configuration. + let config: ReferenceWrapped var template: TemplateRenderer { - ObjectTemplate(graphqlObject: graphqlObject) + ObjectTemplate(graphqlObject: graphqlObject, config: config) } var target: FileTarget { .object } diff --git a/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift b/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift index 050f8daa1f..57b3e9260b 100644 --- a/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift @@ -1,17 +1,21 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects) /// into Swift code. struct ObjectTemplate: TemplateRenderer { /// IR representation of source [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects). let graphqlObject: GraphQLObjectType + /// Shared codegen configuration. + let config: ReferenceWrapped let target: TemplateTarget = .schemaFile var template: TemplateString { TemplateString( """ - public final class \(graphqlObject.name.firstUppercased): Object { + \(embeddedAccessControlModifier(config: config) ?? "")\ + final class \(graphqlObject.name.firstUppercased): Object { override public class var __typename: StaticString { \"\(graphqlObject.name.firstUppercased)\" } \(section: ImplementedInterfacesTemplate()) diff --git a/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift b/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift index fa3007f23b..86899bb199 100644 --- a/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift +++ b/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift @@ -111,6 +111,14 @@ extension TemplateRenderer { """ ).description } + + func embeddedAccessControlModifier( + config: ReferenceWrapped + ) -> String? { + guard config.output.schemaTypes.isInModule else { return nil } + + return "public " + } } extension TemplateString { diff --git a/Tests/ApolloCodegenInternalTestHelpers/MockApolloCodegenConfiguration.swift b/Tests/ApolloCodegenInternalTestHelpers/MockApolloCodegenConfiguration.swift index 6b411d4384..1e77705fac 100644 --- a/Tests/ApolloCodegenInternalTestHelpers/MockApolloCodegenConfiguration.swift +++ b/Tests/ApolloCodegenInternalTestHelpers/MockApolloCodegenConfiguration.swift @@ -3,9 +3,16 @@ extension ApolloCodegenConfiguration { public static func mock( schemaName: String = "MockSchemaTypes", - input: FileInput = .init(schemaPath: "MockSchemaPath", searchPaths: []), - output: FileOutput = .init(schemaTypes: .init(path: "MockSchemaTypes", - moduleType: .embeddedInTarget(name: "MockApplication"))), + input: FileInput = .init( + schemaPath: "MockSchemaPath", + searchPaths: [] + ), + output: FileOutput = .init( + schemaTypes: .init( + path: "MockSchemaTypes", + moduleType: .embeddedInTarget(name: "MockApplication") + ) + ), options: OutputOptions = .init() ) -> Self { .init(schemaName: schemaName, input: input, output: output, options: options) @@ -18,10 +25,13 @@ extension ApolloCodegenConfiguration { ) -> Self { .init( schemaName: schemaName, - input: .init(schemaPath: "schema.graphqls", - searchPaths: ["*.graphql"]), - output: .init(schemaTypes: .init(path: path, - moduleType: moduleType)) + input: .init( + schemaPath: "schema.graphqls", + searchPaths: ["*.graphql"] + ), + output: .init( + schemaTypes: .init(path: path, moduleType: moduleType) + ) ) } } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/ObjectFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/ObjectFileGeneratorTests.swift index 9f7c4aa844..14a661632a 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/ObjectFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/ObjectFileGeneratorTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class ObjectFileGeneratorTests: XCTestCase { let graphqlObject = GraphQLObjectType.mock("MockObject", fields: [:], interfaces: []) @@ -14,7 +15,10 @@ class ObjectFileGeneratorTests: XCTestCase { // MARK: Test Helpers private func buildSubject() { - subject = ObjectFileGenerator(graphqlObject: graphqlObject) + subject = ObjectFileGenerator( + graphqlObject: graphqlObject, + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift index babee72222..4e8989937d 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift @@ -2,6 +2,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib import ApolloCodegenInternalTestHelpers +import ApolloUtils class ObjectTemplateTests: XCTestCase { @@ -15,9 +16,14 @@ class ObjectTemplateTests: XCTestCase { // MARK: Helpers - private func buildSubject(name: String = "Dog", interfaces: [GraphQLInterfaceType] = []) { + private func buildSubject( + name: String = "Dog", + interfaces: [GraphQLInterfaceType] = [], + config: ApolloCodegenConfiguration = .mock() + ) { subject = ObjectTemplate( - graphqlObject: GraphQLObjectType.mock(name, interfaces: interfaces) + graphqlObject: GraphQLObjectType.mock(name, interfaces: interfaces), + config: ReferenceWrapped(value: config) ) } @@ -44,6 +50,22 @@ class ObjectTemplateTests: XCTestCase { // given buildSubject(name: "dog") + let expected = """ + final class Dog: Object { + override public class var __typename: StaticString { "Dog" } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_swiftPackageManager_generatesSwiftClassDefinition_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + let expected = """ public final class Dog: Object { override public class var __typename: StaticString { "Dog" } @@ -54,7 +76,39 @@ class ObjectTemplateTests: XCTestCase { // then expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) - } + } + + func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier_correctlyCased() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public final class Dog: Object { + override public class var __typename: StaticString { "Dog" } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier_correctlyCased() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + final class Dog: Object { + override public class var __typename: StaticString { "Dog" } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } // MARK: Metadata Tests From 69e311b62cb7c401a17088ba6d4c1d5e18d80df1 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Fri, 10 Jun 2022 13:16:52 -0700 Subject: [PATCH 02/17] fix: Correctly add public modifier on schema Interfaces when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 2 +- .../InterfaceFileGenerator.swift | 8 ++- .../Templates/InterfaceTemplate.swift | 6 +- .../InterfaceFileGeneratorTests.swift | 6 +- .../Templates/InterfaceTemplateTests.swift | 60 +++++++++++++++++-- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index 3d8b95a381..e0e49c1998 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -134,7 +134,7 @@ public class ApolloCodegen { for graphQLInterface in ir.schema.referencedTypes.interfaces { try autoreleasepool { - try InterfaceFileGenerator(graphqlInterface: graphQLInterface) + try InterfaceFileGenerator(graphqlInterface: graphQLInterface, config: config) .generate(forConfig: config, fileManager: fileManager) } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift index c16f8a6892..1532b7acf3 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/InterfaceFileGenerator.swift @@ -1,11 +1,17 @@ import Foundation +import ApolloUtils /// Generates a file containing the Swift representation of a [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces). struct InterfaceFileGenerator: FileGenerator { /// Source GraphQL interface. let graphqlInterface: GraphQLInterfaceType + /// Shared codegen configuration. + let config: ReferenceWrapped + + var template: TemplateRenderer { + InterfaceTemplate(graphqlInterface: graphqlInterface, config: config) + } - var template: TemplateRenderer { InterfaceTemplate(graphqlInterface: graphqlInterface) } var target: FileTarget { .interface } var fileName: String { "\(graphqlInterface.name).swift" } } diff --git a/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift b/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift index 0af3820079..0f5ef6f8e7 100644 --- a/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift @@ -1,17 +1,21 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces) /// into Swift code. struct InterfaceTemplate: TemplateRenderer { /// IR representation of source [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces). let graphqlInterface: GraphQLInterfaceType + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget = .schemaFile var template: TemplateString { TemplateString( """ - public final class \(graphqlInterface.name.firstUppercased): Interface { } + \(embeddedAccessControlModifier(config: config) ?? "")\ + final class \(graphqlInterface.name.firstUppercased): Interface { } """ ) } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InterfaceFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InterfaceFileGeneratorTests.swift index a83151ab2b..5a252c511f 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InterfaceFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InterfaceFileGeneratorTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class InterfaceFileGeneratorTests: XCTestCase { let graphqlInterface = GraphQLInterfaceType.mock("MockInterface", fields: [:], interfaces: []) @@ -14,7 +15,10 @@ class InterfaceFileGeneratorTests: XCTestCase { // MARK: Test Helpers private func buildSubject() { - subject = InterfaceFileGenerator(graphqlInterface: graphqlInterface) + subject = InterfaceFileGenerator( + graphqlInterface: graphqlInterface, + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift index 2853f2c169..8a7688662f 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift @@ -2,6 +2,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib import ApolloCodegenInternalTestHelpers +import ApolloUtils class InterfaceTemplateTests: XCTestCase { var subject: InterfaceTemplate! @@ -14,9 +15,13 @@ class InterfaceTemplateTests: XCTestCase { // MARK: Helpers - private func buildSubject() { + private func buildSubject( + name: String = "Dog", + config: ApolloCodegenConfiguration = .mock() + ) { subject = InterfaceTemplate( - graphqlInterface: GraphQLInterfaceType.mock("mockInterface", fields: [:], interfaces: []) + graphqlInterface: GraphQLInterfaceType.mock(name, fields: [:], interfaces: []), + config: ReferenceWrapped(value: config) ) } @@ -26,12 +31,12 @@ class InterfaceTemplateTests: XCTestCase { // MARK: Class Definition Tests - func test_render_givenSchemaInterface_generatesSwiftClassCorrectlyCased() throws { + func test_render_givenSchemaInterface_generatesSwiftClassDefinitionCorrectlyCased() throws { // given - buildSubject() + buildSubject(name: "aDog") let expected = """ - public final class MockInterface: Interface { } + final class ADog: Interface { } """ // when @@ -40,4 +45,49 @@ class InterfaceTemplateTests: XCTestCase { // then expect(actual).to(equalLineByLine(expected)) } + + func test_render_givenModuleType_swiftPackageManager_generatesSwiftClassDefinition_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + + let expected = """ + public final class Dog: Interface { } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier_correctlyCased() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public final class Dog: Interface { } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier_correctlyCased() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + final class Dog: Interface { } + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } } From a2f5663f5b0ab8f3759774316955e455c092bad5 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Fri, 10 Jun 2022 14:01:19 -0700 Subject: [PATCH 03/17] fix: Correctly add public modifier on schema CustomScalars when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 2 +- .../CustomScalarFileGenerator.swift | 8 +- .../Templates/CustomScalarTemplate.swift | 6 +- .../CustomScalarFileGeneratorTests.swift | 6 +- .../Templates/CustomScalarTemplateTests.swift | 80 +++++++++++++++---- .../Templates/InterfaceTemplateTests.swift | 4 +- 6 files changed, 87 insertions(+), 19 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index e0e49c1998..9b265709b4 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -171,7 +171,7 @@ public class ApolloCodegen { for graphQLScalar in ir.schema.referencedTypes.customScalars { try autoreleasepool { - try CustomScalarFileGenerator(graphqlScalar: graphQLScalar) + try CustomScalarFileGenerator(graphqlScalar: graphQLScalar, config: config) .generate(forConfig: config, fileManager: fileManager) } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift index 8a13728afd..13ca14ba75 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/CustomScalarFileGenerator.swift @@ -1,11 +1,17 @@ import Foundation +import ApolloUtils /// Generates a file containing the Swift representation of a [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars). struct CustomScalarFileGenerator: FileGenerator { /// Source GraphQL Custom Scalar.. let graphqlScalar: GraphQLScalarType + /// Shared codegen configuration. + let config: ReferenceWrapped + + var template: TemplateRenderer { + CustomScalarTemplate(graphqlScalar: graphqlScalar, config: config) + } - var template: TemplateRenderer { CustomScalarTemplate(graphqlScalar: graphqlScalar) } var target: FileTarget { .customScalar } var fileName: String { "\(graphqlScalar.name).swift" } var overwrite: Bool { false } diff --git a/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift b/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift index 4a6f7b66d7..c969a870d7 100644 --- a/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift @@ -1,10 +1,13 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars) /// into Swift code. struct CustomScalarTemplate: TemplateRenderer { /// IR representation of source [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars). let graphqlScalar: GraphQLScalarType + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget { .schemaFile } @@ -24,7 +27,8 @@ struct CustomScalarTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - public typealias \(graphqlScalar.name.firstUppercased) = String + \(embeddedAccessControlModifier(config: config) ?? "")\ + typealias \(graphqlScalar.name.firstUppercased) = String """ ) } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/CustomScalarFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/CustomScalarFileGeneratorTests.swift index 9556764134..c23404eeb6 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/CustomScalarFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/CustomScalarFileGeneratorTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class CustomScalarFileGeneratorTests: XCTestCase { let graphqlScalar = GraphQLScalarType.mock(name: "MockCustomScalar") @@ -14,7 +15,10 @@ class CustomScalarFileGeneratorTests: XCTestCase { // MARK: Test Helpers private func buildSubject() { - subject = CustomScalarFileGenerator(graphqlScalar: graphqlScalar) + subject = CustomScalarFileGenerator( + graphqlScalar: graphqlScalar, + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift index ec5316c4fb..d36f4d0f8b 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/CustomScalarTemplateTests.swift @@ -3,6 +3,7 @@ import Nimble @testable import ApolloCodegenLib import ApolloCodegenInternalTestHelpers import ApolloAPI +import ApolloUtils class CustomScalarTemplateTests: XCTestCase { var subject: CustomScalarTemplate! @@ -15,21 +16,29 @@ class CustomScalarTemplateTests: XCTestCase { super.tearDown() } + private func buildSubject( + name: String = "MyCustomScalar", + config: ApolloCodegenConfiguration = .mock() + ) { + subject = CustomScalarTemplate( + graphqlScalar: GraphQLScalarType.mock(name: name), + config: ReferenceWrapped(value: config) + ) + } + private func renderSubject() -> String { subject.template.description } - // MARK: Boilerplate Tests + // MARK: Casing Tests - func test__render__givenCustomScalar_shouldGeneratePublicTypealias() throws { + func test__render__givenCustomScalar_shouldGenerateTypealiasNameFirstUppercased() throws { // given - subject = CustomScalarTemplate( - graphqlScalar: GraphQLScalarType.mock(name: "myCustomScalar") - ) + buildSubject(name: "aCustomScalar") let expected = """ - public typealias MyCustomScalar = String - """ + typealias ACustomScalar = String + """ // when let rendered = renderSubject() @@ -38,17 +47,15 @@ class CustomScalarTemplateTests: XCTestCase { expect(rendered).to(equalLineByLine(expected)) } - // MARK: Casing Tests + // MARK: Typealias Definition Tests - func test__render__givenCustomScalar_shouldGenerateTypealiasNameFirstUppercased() throws { + func test__render__givenCustomScalar_shouldGenerateStringTypealias() throws { // given - subject = CustomScalarTemplate( - graphqlScalar: GraphQLScalarType.mock(name: "lowercasedScalar") - ) + buildSubject() let expected = """ - public typealias LowercasedScalar = String - """ + typealias MyCustomScalar = String + """ // when let rendered = renderSubject() @@ -56,4 +63,49 @@ class CustomScalarTemplateTests: XCTestCase { // then expect(rendered).to(equalLineByLine(expected)) } + + func test_render_givenModuleType_swiftPackageManager_generatesTypealias_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + + let expected = """ + public typealias MyCustomScalar = String + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesTypealias_withPublicModifier() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public typealias MyCustomScalar = String + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesTypealias_noPublicModifier() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + typealias MyCustomScalar = String + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift index 8a7688662f..3207c8b90d 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift @@ -29,7 +29,7 @@ class InterfaceTemplateTests: XCTestCase { subject.template.description } - // MARK: Class Definition Tests + // MARK: Casing Tests func test_render_givenSchemaInterface_generatesSwiftClassDefinitionCorrectlyCased() throws { // given @@ -46,6 +46,8 @@ class InterfaceTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected)) } + // MARK: Class Definition Tests + func test_render_givenModuleType_swiftPackageManager_generatesSwiftClassDefinition_withPublicModifier() { // given buildSubject(config: .mock(.swiftPackageManager)) From dded64b20a08b3b79205d3517327dd2c59cd4e54 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Fri, 10 Jun 2022 18:00:31 -0700 Subject: [PATCH 04/17] fix: Correctly add public modifier on schema Enums when required by module type --- .../FileGenerators/EnumFileGenerator.swift | 7 ++- .../Templates/EnumTemplate.swift | 7 +-- .../Templates/EnumTemplateTests.swift | 49 ++++++++++++++----- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift index 03df1dc697..5e56b8f16b 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/EnumFileGenerator.swift @@ -5,10 +5,13 @@ import ApolloUtils struct EnumFileGenerator: FileGenerator { /// Source GraphQL enum. let graphqlEnum: GraphQLEnumType - /// Shared codegen configuration + /// Shared codegen configuration. let config: ReferenceWrapped - var template: TemplateRenderer { EnumTemplate(graphqlEnum: graphqlEnum, config: config) } + var template: TemplateRenderer { + EnumTemplate(graphqlEnum: graphqlEnum, config: config) + } + var target: FileTarget { .enum } var fileName: String { "\(graphqlEnum.name).swift" } } diff --git a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift index 956e413115..c23db58bae 100644 --- a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift @@ -6,15 +6,16 @@ import ApolloUtils struct EnumTemplate: TemplateRenderer { /// IR representation of source [GraphQL Enum](https://spec.graphql.org/draft/#sec-Enums). let graphqlEnum: GraphQLEnumType - /// Shared codegen configuration - var config: ReferenceWrapped + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget { .schemaFile } var template: TemplateString { TemplateString( """ - public enum \(graphqlEnum.name.firstUppercased): String, EnumType { + \(embeddedAccessControlModifier(config: config) ?? "")\ + enum \(graphqlEnum.name.firstUppercased): String, EnumType { \(graphqlEnum.values.compactMap({ evaluateDeprecation(graphqlEnumValue: $0, config: config) }), separator: "\n") diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift index caf2e103a3..50851c16a2 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift @@ -22,7 +22,7 @@ class EnumTemplateTests: XCTestCase { /// - values: A tuple that combines the value name and optional deprecation reason. /// - config: Code generation configuration. private func buildSubject( - name: String = "testEnum", + name: String = "TestEnum", values: [(String, String?)] = [("ONE", nil), ("TWO", nil)], config: ApolloCodegenConfiguration = ApolloCodegenConfiguration.mock() ) { @@ -41,32 +41,59 @@ class EnumTemplateTests: XCTestCase { // MARK: Enum Tests - func test_render_givenSchemaEnum_generatesSwiftEnum() throws { + func test_render_givenModuleType_swiftPackageManager_generatesSwiftEnum_withPublicModifier() { // given - buildSubject() + buildSubject(config: .mock(.swiftPackageManager)) let expected = """ public enum TestEnum: String, EnumType { - case ONE - case TWO - } """ // when let actual = renderSubject() // then - expect(actual).to(equalLineByLine(expected)) + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesSwiftEnum_withPublicModifier() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public enum TestEnum: String, EnumType { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesSwiftEnum_noPublicModifier() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + enum TestEnum: String, EnumType { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } // MARK: Casing Tests func test_render_givenSchemaEnum_generatesSwiftEnumNameFirstUppercased() throws { // given - buildSubject(name: "testEnum") + buildSubject(name: "anEnum") let expected = """ - public enum TestEnum: String, EnumType { + enum AnEnum: String, EnumType { """ // when @@ -76,7 +103,7 @@ class EnumTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test_render_givenSchemaEnum_generatesSwiftEnumRespectingCase() throws { + func test_render_givenSchemaEnum_generatesSwiftEnumRespectingValueCasing() throws { // given buildSubject( name: "CasedEnum", @@ -88,7 +115,7 @@ class EnumTemplateTests: XCTestCase { ) let expected = """ - public enum CasedEnum: String, EnumType { + enum CasedEnum: String, EnumType { case lower case UPPER case Capitalized From 239121fa081f42e3f7a2ee8ee6ddcdfc439e40e4 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 10:28:06 -0700 Subject: [PATCH 05/17] fix: Correctly add public modifier on schema Unions when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 3 +- .../FileGenerators/UnionFileGenerator.swift | 6 +- .../Templates/UnionTemplate.swift | 6 +- .../UnionFileGeneratorTests.swift | 7 ++- .../Templates/UnionTemplateTests.swift | 55 ++++++++++++++++++- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index 9b265709b4..5a7a2b3703 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -143,7 +143,8 @@ public class ApolloCodegen { try autoreleasepool { try UnionFileGenerator( graphqlUnion: graphQLUnion, - schemaName: config.schemaName + schemaName: config.schemaName, + config: config ).generate( forConfig: config, fileManager: fileManager diff --git a/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift index 81ff1c0cf5..6059d59393 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/UnionFileGenerator.swift @@ -1,4 +1,5 @@ import Foundation +import ApolloUtils /// Generates a file containing the Swift representation of a [GraphQL Union](https://spec.graphql.org/draft/#sec-Unions). struct UnionFileGenerator: FileGenerator { @@ -6,10 +7,13 @@ struct UnionFileGenerator: FileGenerator { let graphqlUnion: GraphQLUnionType /// Schema name let schemaName: String + /// Shared codegen configuration. + let config: ReferenceWrapped var template: TemplateRenderer { UnionTemplate( moduleName: schemaName, - graphqlUnion: graphqlUnion + graphqlUnion: graphqlUnion, + config: config ) } var target: FileTarget { .union } var fileName: String { "\(graphqlUnion.name).swift" } diff --git a/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift b/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift index 8ffe89a98e..51708d5480 100644 --- a/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift @@ -1,4 +1,5 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Union](https://spec.graphql.org/draft/#sec-Unions) /// into Swift code. @@ -7,13 +8,16 @@ struct UnionTemplate: TemplateRenderer { let moduleName: String /// IR representation of source [GraphQL Union](https://spec.graphql.org/draft/#sec-Unions). let graphqlUnion: GraphQLUnionType + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget = .schemaFile var template: TemplateString { TemplateString( """ - public enum \(graphqlUnion.name.firstUppercased): Union { + \(embeddedAccessControlModifier(config: config) ?? "")\ + enum \(graphqlUnion.name.firstUppercased): Union { public static let possibleTypes: [Object.Type] = [ \(graphqlUnion.types.map({ type in "\(moduleName.firstUppercased).\(type.name.firstUppercased).self" diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/UnionFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/UnionFileGeneratorTests.swift index 63725631a1..fa5633bbb0 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/UnionFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/UnionFileGeneratorTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class UnionFileGeneratorTests: XCTestCase { let graphqlUnion = GraphQLUnionType.mock("MockUnion", types: []) @@ -14,7 +15,11 @@ class UnionFileGeneratorTests: XCTestCase { // MARK: Test Helpers private func buildSubject() { - subject = UnionFileGenerator(graphqlUnion: graphqlUnion, schemaName: "MockSchema") + subject = UnionFileGenerator( + graphqlUnion: graphqlUnion, + schemaName: "MockSchema", + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift index 056676455d..c2e13dde97 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/UnionTemplateTests.swift @@ -2,6 +2,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib import ApolloAPI +import ApolloUtils class UnionTemplateTests: XCTestCase { var subject: UnionTemplate! @@ -14,7 +15,9 @@ class UnionTemplateTests: XCTestCase { // MARK: Helpers - private func buildSubject() { + private func buildSubject( + config: ApolloCodegenConfiguration = .mock() + ) { subject = UnionTemplate( moduleName: "moduleAPI", graphqlUnion: GraphQLUnionType.mock( @@ -25,7 +28,8 @@ class UnionTemplateTests: XCTestCase { GraphQLObjectType.mock("rat"), GraphQLObjectType.mock("petRock") ] - ) + ), + config: ReferenceWrapped(value: config) ) } @@ -53,7 +57,7 @@ class UnionTemplateTests: XCTestCase { buildSubject() let expected = """ - public enum ClassroomPet: Union { + enum ClassroomPet: Union { """ // when @@ -82,4 +86,49 @@ class UnionTemplateTests: XCTestCase { // then expect(actual).to(equalLineByLine(expected, atLine: 2, ignoringExtraLines: true)) } + + func test_render_givenModuleType_swiftPackageManager_generatesSwiftEnum_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + + let expected = """ + public enum ClassroomPet: Union { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesSwiftEnum_withPublicModifier() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public enum ClassroomPet: Union { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesSwiftEnum_noPublicModifier() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + enum ClassroomPet: Union { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } } From 5472fe74cfb4f7e64352dc5d93f9944eafcbcb01 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 10:42:28 -0700 Subject: [PATCH 06/17] fix: Correctly add public modifier on schema InputObjects when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 10 ++- .../InputObjectFileGenerator.swift | 10 ++- .../Templates/InputObjectTemplate.swift | 8 ++- .../InputObjectFileGeneratorTests.swift | 7 +- .../Templates/InputObjectTemplateTests.swift | 67 ++++++++++++++++--- 5 files changed, 86 insertions(+), 16 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index 5a7a2b3703..a6637339ef 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -165,8 +165,14 @@ public class ApolloCodegen { for graphQLInputObject in ir.schema.referencedTypes.inputObjects { try autoreleasepool { - try InputObjectFileGenerator(graphqlInputObject: graphQLInputObject, schema: ir.schema) - .generate(forConfig: config, fileManager: fileManager) + try InputObjectFileGenerator( + graphqlInputObject: graphQLInputObject, + schema: ir.schema, + config: config + ).generate( + forConfig: config, + fileManager: fileManager + ) } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift index 8ea8bf9ace..dc902259ef 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/InputObjectFileGenerator.swift @@ -1,14 +1,18 @@ import Foundation +import ApolloUtils -/// Generates a file containing the Swift representation of a [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects). +/// Generates a file containing the Swift representation of a +/// [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects). struct InputObjectFileGenerator: FileGenerator { /// Source GraphQL input object. let graphqlInputObject: GraphQLInputObjectType - + /// IR representation of a GraphQL schema. let schema: IR.Schema + /// Shared codegen configuration. + let config: ReferenceWrapped var template: TemplateRenderer { - InputObjectTemplate(graphqlInputObject: graphqlInputObject, schema: schema) + InputObjectTemplate(graphqlInputObject: graphqlInputObject, schema: schema, config: config) } var target: FileTarget { .inputObject } var fileName: String { "\(graphqlInputObject.name).swift" } diff --git a/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift b/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift index d3dcc37e4f..68c3e4b5fc 100644 --- a/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift @@ -1,19 +1,23 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects) /// into Swift code. struct InputObjectTemplate: TemplateRenderer { /// IR representation of source [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects). let graphqlInputObject: GraphQLInputObjectType - + /// IR representation of a GraphQL schema. let schema: IR.Schema + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget = .schemaFile var template: TemplateString { TemplateString( """ - public struct \(graphqlInputObject.name.firstUppercased): InputObject { + \(embeddedAccessControlModifier(config: config) ?? "")\ + struct \(graphqlInputObject.name.firstUppercased): InputObject { public private(set) var data: InputDict public init(_ data: InputDict) { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InputObjectFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InputObjectFileGeneratorTests.swift index 802a0302a3..86bda8d2a9 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InputObjectFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/InputObjectFileGeneratorTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class InputObjectFileGeneratorTests: XCTestCase { let graphqlInputObject = GraphQLInputObjectType.mock("MockInputObject") @@ -15,7 +16,11 @@ class InputObjectFileGeneratorTests: XCTestCase { private func buildSubject() { let schema = IR.Schema(name: "TestSchema", referencedTypes: .init([])) - subject = InputObjectFileGenerator(graphqlInputObject: graphqlInputObject, schema: schema) + subject = InputObjectFileGenerator( + graphqlInputObject: graphqlInputObject, + schema: schema, + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift index b319c1b516..1e964191c6 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift @@ -1,6 +1,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib +import ApolloUtils class InputObjectTemplateTests: XCTestCase { var subject: InputObjectTemplate! @@ -14,11 +15,16 @@ class InputObjectTemplateTests: XCTestCase { super.tearDown() } - private func buildSubject(name: String = "MockInput", fields: [GraphQLInputField] = []) { + private func buildSubject( + name: String = "MockInput", + fields: [GraphQLInputField] = [], + config: ApolloCodegenConfiguration = .mock() + ) { let schema = IR.Schema(name: "TestSchema", referencedTypes: .init([])) subject = InputObjectTemplate( graphqlInputObject: GraphQLInputObjectType.mock(name, fields: fields), - schema: schema + schema: schema, + config: ReferenceWrapped(value: config) ) } @@ -26,9 +32,9 @@ class InputObjectTemplateTests: XCTestCase { subject.template.description } - // MARK: Boilerplate Tests + // MARK: Definition Tests - func test__render__generatesDefinitionWithInputDictVariableAndInitializer() throws { + func test__render__generatesInputObject_withInputDictVariableAndInitializer() throws { // given buildSubject( name: "mockInput", @@ -36,7 +42,7 @@ class InputObjectTemplateTests: XCTestCase { ) let expected = """ - public struct MockInput: InputObject { + struct MockInput: InputObject { public private(set) var data: InputDict public init(_ data: InputDict) { @@ -51,6 +57,51 @@ class InputObjectTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } + func test_render_givenModuleType_swiftPackageManager_generatesInputObject_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + + let expected = """ + public struct MockInput: InputObject { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesInputObject_withPublicModifier() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public struct MockInput: InputObject { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesInputObject_noPublicModifier() { + // given + buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + struct MockInput: InputObject { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + // MARK: Casing Tests func test__render__givenLowercasedInputObjectField__generatesCorrectlyCasedSwiftDefinition() throws { @@ -60,7 +111,7 @@ class InputObjectTemplateTests: XCTestCase { fields: [GraphQLInputField.mock("field", type: .scalar(.integer()), defaultValue: nil)] ) - let expected = "public struct MockInput: InputObject {" + let expected = "struct MockInput: InputObject {" // when let actual = renderSubject() @@ -76,7 +127,7 @@ class InputObjectTemplateTests: XCTestCase { fields: [GraphQLInputField.mock("field", type: .scalar(.integer()), defaultValue: nil)] ) - let expected = "public struct MOCKInput: InputObject {" + let expected = "struct MOCKInput: InputObject {" // when let actual = renderSubject() @@ -92,7 +143,7 @@ class InputObjectTemplateTests: XCTestCase { fields: [GraphQLInputField.mock("field", type: .scalar(.integer()), defaultValue: nil)] ) - let expected = "public struct MOcK_Input: InputObject {" + let expected = "struct MOcK_Input: InputObject {" // when let actual = renderSubject() From 0da925c3f7e179a64fc94957bb359ebc1e9240f5 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 11:03:01 -0700 Subject: [PATCH 07/17] fix: Correctly add public modifier on schema template definitions when required by module type --- .../Templates/SchemaTemplate.swift | 15 +++--- .../Templates/SchemaTemplateTests.swift | 54 ++++++++++++++----- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift index 910fb57a28..0df733c703 100644 --- a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift @@ -6,31 +6,32 @@ import ApolloUtils struct SchemaTemplate: TemplateRenderer { // IR representation of source GraphQL schema. let schema: IR.Schema - /// Shared codegen configuration. let config: ReferenceWrapped let schemaName: String - var target: TemplateTarget = .schemaFile - var template: TemplateString { embeddableTemplate } /// Swift code that can be embedded within a namespace. var embeddableTemplate: TemplateString { TemplateString( """ - public typealias ID = String + \(embeddedAccessControlModifier(config: config) ?? "")\ + typealias ID = String \(if: !config.output.schemaTypes.isInModule, TemplateString(""" - public typealias SelectionSet = \(schemaName)_SelectionSet + \(embeddedAccessControlModifier(config: config) ?? "")\ + typealias SelectionSet = \(schemaName)_SelectionSet - public typealias InlineFragment = \(schemaName)_InlineFragment + \(embeddedAccessControlModifier(config: config) ?? "")\ + typealias InlineFragment = \(schemaName)_InlineFragment """), else: protocolDefinition(prefix: nil, schemaName: schemaName)) - public enum Schema: SchemaConfiguration { + \(embeddedAccessControlModifier(config: config) ?? "")\ + enum Schema: SchemaConfiguration { public static func objectType(forTypename __typename: String) -> Object.Type? { switch __typename { \(schema.referencedTypes.objects.map { diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift index 34af446555..1e2a539700 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift @@ -36,12 +36,12 @@ class SchemaTemplateTests: XCTestCase { // MARK: Typealias & Protocol Tests - func test__render__givenModuleEmbeddedInTarget_shouldGenerateIDTypealias() { + func test__render__givenModuleEmbeddedInTarget_shouldGenerateIDTypealias_noPublicModifier() { // given buildSubject(config: .mock(.embeddedInTarget(name: "CustomTarget"))) let expected = """ - public typealias ID = String + typealias ID = String """ @@ -52,7 +52,7 @@ class SchemaTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test__render__givenModuleSwiftPackageManager_shouldGenerateIDTypealias() { + func test__render__givenModuleSwiftPackageManager_shouldGenerateIDTypealias_withPublicModifier() { // given buildSubject(config: .mock(.swiftPackageManager)) @@ -68,7 +68,7 @@ class SchemaTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test__render__givenModuleOther_shouldGenerateIDTypealias() { + func test__render__givenModuleOther_shouldGenerateIDTypealias_withPublicModifier() { // given buildSubject(config: .mock(.other)) @@ -84,7 +84,7 @@ class SchemaTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test__render__givenModuleEmbeddedInTarget_shouldGenerateDetachedProtocols_withTypealias_withCorrectCasing() { + func test__render__givenModuleEmbeddedInTarget_shouldGenerateDetachedProtocols_withTypealias_withCorrectCasing_noPublicModifier() { // given buildSubject( name: "aName", @@ -92,9 +92,9 @@ class SchemaTemplateTests: XCTestCase { ) let expectedTemplate = """ - public typealias SelectionSet = AName_SelectionSet + typealias SelectionSet = AName_SelectionSet - public typealias InlineFragment = AName_InlineFragment + typealias InlineFragment = AName_InlineFragment """ @@ -123,7 +123,7 @@ class SchemaTemplateTests: XCTestCase { .to(equalLineByLine(expectedDetached)) } - func test__render__givenModuleSwiftPackageManager_shouldGenerateEmbeddedProtocols_noTypealias_withCorrectCasing() { + func test__render__givenModuleSwiftPackageManager_shouldGenerateEmbeddedProtocols_noTypealias_withCorrectCasing_withPublicModifier() { // given buildSubject( name: "aName", @@ -155,7 +155,7 @@ class SchemaTemplateTests: XCTestCase { .to(beNil()) } - func test__render__givenModuleOther_shouldGenerateEmbeddedProtocols_noTypealias_withCorrectCasing() { + func test__render__givenModuleOther_shouldGenerateEmbeddedProtocols_noTypealias_withCorrectCasing_withPublicModifier() { // given buildSubject( name: "aName", @@ -189,12 +189,12 @@ class SchemaTemplateTests: XCTestCase { // MARK: Schema Tests - func test__render__generatesEnumDefinition() { + func test__render__givenModuleSwiftPackageManager_shouldGenerateEnumDefinition_noPublicModifier() { // given - buildSubject() + buildSubject(config: .mock(.embeddedInTarget(name: "MockTarget"))) let expected = """ - public enum Schema: SchemaConfiguration { + enum Schema: SchemaConfiguration { """ // when @@ -204,6 +204,36 @@ class SchemaTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 7, ignoringExtraLines: true)) } + func test__render__givenModuleSwiftPackageManager_shouldGenerateEnumDefinition_withPublicModifier() { + // given + buildSubject(config: .mock(.swiftPackageManager)) + + let expected = """ + public enum Schema: SchemaConfiguration { + """ + + // when + let actual = renderTemplate() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 9, ignoringExtraLines: true)) + } + + func test__render__givenModuleOther_shouldGenerateEnumDefinition_withPublicModifier() { + // given + buildSubject(config: .mock(.other)) + + let expected = """ + public enum Schema: SchemaConfiguration { + """ + + // when + let actual = renderTemplate() + + // then + expect(actual).to(equalLineByLine(expected, atLine: 9, ignoringExtraLines: true)) + } + func test__render__givenWithReferencedObjects_generatesObjectTypeFunctionCorrectlyCased() { // given buildSubject( From 276d9d91535654a2b7c58ae8736b3b01a42ef909 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 11:30:54 -0700 Subject: [PATCH 08/17] fix: Correctly add public modifier on schema Fragment definitions when required by module type --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 2 +- .../FragmentFileGenerator.swift | 9 ++- .../Templates/FragmentTemplate.swift | 6 +- .../FragmentFileGeneratorTests.swift | 7 ++- .../Templates/FragmentTemplateTests.swift | 60 +++++++++++++++++-- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index a6637339ef..9553cd2eab 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -89,7 +89,7 @@ public class ApolloCodegen { for fragment in compilationResult.fragments { try autoreleasepool { let irFragment = ir.build(fragment: fragment) - try FragmentFileGenerator(irFragment: irFragment, schema: ir.schema) + try FragmentFileGenerator(irFragment: irFragment, schema: ir.schema, config: config) .generate(forConfig: config, fileManager: fileManager) } } diff --git a/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift b/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift index dfaed88b00..44bae19dde 100644 --- a/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift +++ b/Sources/ApolloCodegenLib/FileGenerators/FragmentFileGenerator.swift @@ -1,4 +1,5 @@ import Foundation +import ApolloUtils /// Generates a file containing the Swift representation of a [GraphQL Fragment](https://spec.graphql.org/draft/#sec-Language.Fragments). struct FragmentFileGenerator: FileGenerator { @@ -6,8 +7,14 @@ struct FragmentFileGenerator: FileGenerator { let irFragment: IR.NamedFragment /// Source IR schema. let schema: IR.Schema + /// Shared codegen configuration. + let config: ReferenceWrapped - var template: TemplateRenderer { FragmentTemplate(fragment: irFragment, schema: schema) } + var template: TemplateRenderer { FragmentTemplate( + fragment: irFragment, + schema: schema, + config: config + ) } var target: FileTarget { .fragment(irFragment.definition) } var fileName: String { "\(irFragment.definition.name).swift" } } diff --git a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift index e93c1cac25..61fed4db28 100644 --- a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift @@ -1,4 +1,5 @@ import Foundation +import ApolloUtils /// Provides the format to convert a [GraphQL Fragment](https://spec.graphql.org/draft/#sec-Language.Fragments) /// into Swift code. @@ -7,13 +8,16 @@ struct FragmentTemplate: TemplateRenderer { let fragment: IR.NamedFragment /// IR representation of source GraphQL schema. let schema: IR.Schema + /// Shared codegen configuration. + let config: ReferenceWrapped var target: TemplateTarget { .operationFile } var template: TemplateString { TemplateString( """ - public struct \(fragment.name.firstUppercased): \(schema.name)\ + \(embeddedAccessControlModifier(config: config) ?? "")\ + struct \(fragment.name.firstUppercased): \(schema.name)\ .\(if: isMutable, "Mutable")SelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" \(fragment.definition.source) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FragmentFileGeneratorTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FragmentFileGeneratorTests.swift index 813a76984a..ee9ec0bf44 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FragmentFileGeneratorTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/FileGenerators/FragmentFileGeneratorTests.swift @@ -2,6 +2,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib import ApolloCodegenInternalTestHelpers +import ApolloUtils class FragmentFileGeneratorTests: XCTestCase { var irFragment: IR.NamedFragment! @@ -47,7 +48,11 @@ class FragmentFileGeneratorTests: XCTestCase { let ir = try IR.mock(schema: schemaSDL, document: operationDocument) irFragment = ir.build(fragment: ir.compilationResult.fragments[0]) - subject = FragmentFileGenerator(irFragment: irFragment, schema: ir.schema) + subject = FragmentFileGenerator( + irFragment: irFragment, + schema: ir.schema, + config: ReferenceWrapped(value: ApolloCodegenConfiguration.mock()) + ) } // MARK: Property Tests diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift index 3c3fefc5c3..727c736a19 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift @@ -2,6 +2,7 @@ import XCTest import Nimble @testable import ApolloCodegenLib import ApolloCodegenInternalTestHelpers +import ApolloUtils class FragmentTemplateTests: XCTestCase { @@ -43,13 +44,17 @@ class FragmentTemplateTests: XCTestCase { // MARK: - Helpers - private func buildSubjectAndFragment(named fragmentName: String = "TestFragment") throws { + private func buildSubjectAndFragment( + named fragmentName: String = "TestFragment", + config: ApolloCodegenConfiguration = .mock() + ) throws { ir = try .mock(schema: schemaSDL, document: document) let fragmentDefinition = try XCTUnwrap(ir.compilationResult[fragment: fragmentName]) fragment = ir.build(fragment: fragmentDefinition) subject = FragmentTemplate( fragment: fragment, - schema: ir.schema + schema: ir.schema, + config: ReferenceWrapped(value: config) ) } @@ -63,7 +68,7 @@ class FragmentTemplateTests: XCTestCase { // given let expected = """ - public struct TestFragment: TestSchema.SelectionSet, Fragment { + struct TestFragment: TestSchema.SelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" fragment TestFragment on Query { __typename @@ -88,6 +93,51 @@ class FragmentTemplateTests: XCTestCase { expect(String(actual.reversed())).to(equalLineByLine("}", ignoringExtraLines: true)) } + func test__render__givenModuleType_swiftPackageManager_generatesFragmentDefinition_withPublicModifier() throws { + // given + try buildSubjectAndFragment(config: .mock(.swiftPackageManager)) + + let expected = """ + public struct TestFragment: TestSchema.SelectionSet, Fragment { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test__render__givenModuleType_other_generatesFragmentDefinition_withPublicModifier() throws { + // given + try buildSubjectAndFragment(config: .mock(.other)) + + let expected = """ + public struct TestFragment: TestSchema.SelectionSet, Fragment { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test__render__givenModuleType_embeddedInTarget_generatesFragmentDefinition_noPublicModifier() throws { + // given + try buildSubjectAndFragment(config: .mock(.embeddedInTarget(name: "TestTarget"))) + + let expected = """ + struct TestFragment: TestSchema.SelectionSet, Fragment { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + func test__render__givenLowercaseFragment_generatesTitleCaseTypeName() throws { // given document = """ @@ -100,7 +150,7 @@ class FragmentTemplateTests: XCTestCase { let expected = """ - public struct TestFragment: TestSchema.SelectionSet, Fragment { + struct TestFragment: TestSchema.SelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" fragment testFragment on Query { """ @@ -133,7 +183,7 @@ class FragmentTemplateTests: XCTestCase { """ let expected = """ - public struct Test_Fragment: TestSchema.SelectionSet, Fragment { + struct Test_Fragment: TestSchema.SelectionSet, Fragment { """ // when From e8243f28c01655c77308c03ae31989ce6636af57 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 11:47:54 -0700 Subject: [PATCH 09/17] fix: Correctly add public modifier on schema operation definitions when required by module type --- .../Templates/OperationDefinitionTemplate.swift | 3 ++- .../Templates/OperationDefinitionTemplateTests.swift | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift b/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift index e6e7beeebf..54e19d678d 100644 --- a/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift @@ -36,7 +36,8 @@ struct OperationDefinitionTemplate: OperationTemplateRenderer { private func OperationDeclaration(_ operation: CompilationResult.OperationDefinition) -> TemplateString { return """ - public class \(operation.nameWithSuffix.firstUppercased): \(operation.operationType.renderedProtocolName) { + \(embeddedAccessControlModifier(config: config) ?? "")\ + class \(operation.nameWithSuffix.firstUppercased): \(operation.operationType.renderedProtocolName) { public static let operationName: String = "\(operation.name)" """ } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift index 81e9755102..1522c22d8b 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift @@ -70,7 +70,7 @@ class OperationDefinitionTemplateTests: XCTestCase { // given let expected = """ - public class TestOperationQuery: GraphQLQuery { + class TestOperationQuery: GraphQLQuery { public static let operationName: String = "TestOperation" """ @@ -95,7 +95,7 @@ class OperationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationQuery: GraphQLQuery { + class TestOperationQuery: GraphQLQuery { public static let operationName: String = "TestOperationQuery" """ @@ -134,7 +134,7 @@ class OperationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationQueryMutation: GraphQLMutation { + class TestOperationQueryMutation: GraphQLMutation { public static let operationName: String = "TestOperationQuery" """ @@ -173,7 +173,7 @@ class OperationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationMutation: GraphQLMutation { + class TestOperationMutation: GraphQLMutation { public static let operationName: String = "TestOperation" """ @@ -212,7 +212,7 @@ class OperationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationSubscription: GraphQLSubscription { + class TestOperationSubscription: GraphQLSubscription { public static let operationName: String = "TestOperation" """ @@ -386,7 +386,7 @@ class OperationDefinitionTemplateTests: XCTestCase { let expected = """ - public class LowercaseOperationQuery: GraphQLQuery { + class LowercaseOperationQuery: GraphQLQuery { public static let operationName: String = "lowercaseOperation" public static let document: DocumentType = .notPersisted( definition: .init( From e3957ff043279d11f66053e233901e09dac55cb5 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 15:11:08 -0700 Subject: [PATCH 10/17] refactor: Return empty string instead of requiring callers to use nil coalescing --- .../ApolloCodegenLib/Templates/CustomScalarTemplate.swift | 2 +- Sources/ApolloCodegenLib/Templates/EnumTemplate.swift | 2 +- Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift | 2 +- .../ApolloCodegenLib/Templates/InputObjectTemplate.swift | 2 +- .../ApolloCodegenLib/Templates/InterfaceTemplate.swift | 2 +- Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift | 2 +- .../Templates/OperationDefinitionTemplate.swift | 2 +- Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift | 8 ++++---- Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift | 4 ++-- Sources/ApolloCodegenLib/Templates/UnionTemplate.swift | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift b/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift index c969a870d7..a07bbedd59 100644 --- a/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/CustomScalarTemplate.swift @@ -27,7 +27,7 @@ struct CustomScalarTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ typealias \(graphqlScalar.name.firstUppercased) = String """ ) diff --git a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift index c23db58bae..82ce5adf8f 100644 --- a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift @@ -14,7 +14,7 @@ struct EnumTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ enum \(graphqlEnum.name.firstUppercased): String, EnumType { \(graphqlEnum.values.compactMap({ evaluateDeprecation(graphqlEnumValue: $0, config: config) diff --git a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift index 61fed4db28..54ba8f8a63 100644 --- a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift @@ -16,7 +16,7 @@ struct FragmentTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ struct \(fragment.name.firstUppercased): \(schema.name)\ .\(if: isMutable, "Mutable")SelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" diff --git a/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift b/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift index 68c3e4b5fc..304bd5c738 100644 --- a/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift @@ -16,7 +16,7 @@ struct InputObjectTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ struct \(graphqlInputObject.name.firstUppercased): InputObject { public private(set) var data: InputDict diff --git a/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift b/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift index 0f5ef6f8e7..40dfa7bafc 100644 --- a/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift @@ -14,7 +14,7 @@ struct InterfaceTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ final class \(graphqlInterface.name.firstUppercased): Interface { } """ ) diff --git a/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift b/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift index 57b3e9260b..f80f25bd99 100644 --- a/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift @@ -14,7 +14,7 @@ struct ObjectTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ final class \(graphqlObject.name.firstUppercased): Object { override public class var __typename: StaticString { \"\(graphqlObject.name.firstUppercased)\" } diff --git a/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift b/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift index 54e19d678d..a9762dc032 100644 --- a/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/OperationDefinitionTemplate.swift @@ -36,7 +36,7 @@ struct OperationDefinitionTemplate: OperationTemplateRenderer { private func OperationDeclaration(_ operation: CompilationResult.OperationDefinition) -> TemplateString { return """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ class \(operation.nameWithSuffix.firstUppercased): \(operation.operationType.renderedProtocolName) { public static let operationName: String = "\(operation.name)" """ diff --git a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift index 0df733c703..4c913359c8 100644 --- a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift @@ -17,20 +17,20 @@ struct SchemaTemplate: TemplateRenderer { var embeddableTemplate: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ typealias ID = String \(if: !config.output.schemaTypes.isInModule, TemplateString(""" - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ typealias SelectionSet = \(schemaName)_SelectionSet - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ typealias InlineFragment = \(schemaName)_InlineFragment """), else: protocolDefinition(prefix: nil, schemaName: schemaName)) - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ enum Schema: SchemaConfiguration { public static func objectType(forTypename __typename: String) -> Object.Type? { switch __typename { diff --git a/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift b/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift index 86899bb199..4ba64c6a61 100644 --- a/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift +++ b/Sources/ApolloCodegenLib/Templates/TemplateRenderer.swift @@ -114,8 +114,8 @@ extension TemplateRenderer { func embeddedAccessControlModifier( config: ReferenceWrapped - ) -> String? { - guard config.output.schemaTypes.isInModule else { return nil } + ) -> String { + guard config.output.schemaTypes.isInModule else { return "" } return "public " } diff --git a/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift b/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift index 51708d5480..9ee170b53b 100644 --- a/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/UnionTemplate.swift @@ -16,7 +16,7 @@ struct UnionTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config) ?? "")\ + \(embeddedAccessControlModifier(config: config))\ enum \(graphqlUnion.name.firstUppercased): Union { public static let possibleTypes: [Object.Type] = [ \(graphqlUnion.types.map({ type in From 594e641f2cee892b47c5d39d9c3c4fe342bfeaf6 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 15:20:53 -0700 Subject: [PATCH 11/17] chore: fix deprecation tests after rebase --- .../CodeGeneration/Templates/EnumTemplateTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift index 50851c16a2..9268e8fe00 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift @@ -143,7 +143,7 @@ class EnumTemplateTests: XCTestCase { ) let expected = """ - public enum TestEnum: String, EnumType { + enum TestEnum: String, EnumType { case ONE case TWO case THREE @@ -169,7 +169,7 @@ class EnumTemplateTests: XCTestCase { ) let expected = """ - public enum TestEnum: String, EnumType { + enum TestEnum: String, EnumType { case TWO } """ From 0415a3c3d2ee2f5de82e4db708d19ad762862444 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 13 Jun 2022 19:53:21 -0700 Subject: [PATCH 12/17] fix: Remove tab indents and fix newly added FragmentTemplateTest cases --- Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift | 2 +- .../CodeGeneration/Templates/FragmentTemplateTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift index 54ba8f8a63..8a4d7c7af9 100644 --- a/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift @@ -16,7 +16,7 @@ struct FragmentTemplate: TemplateRenderer { var template: TemplateString { TemplateString( """ - \(embeddedAccessControlModifier(config: config))\ + \(embeddedAccessControlModifier(config: config))\ struct \(fragment.name.firstUppercased): \(schema.name)\ .\(if: isMutable, "Mutable")SelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift index 727c736a19..9af8f428b3 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/FragmentTemplateTests.swift @@ -301,7 +301,7 @@ class FragmentTemplateTests: XCTestCase { let expected = """ - public struct TestFragment: TestSchema.MutableSelectionSet, Fragment { + struct TestFragment: TestSchema.MutableSelectionSet, Fragment { """ // when @@ -326,7 +326,7 @@ class FragmentTemplateTests: XCTestCase { let expected = """ - public struct TestFragment: TestSchema.MutableSelectionSet, Fragment { + struct TestFragment: TestSchema.MutableSelectionSet, Fragment { public static var fragmentDefinition: StaticString { ""\" fragment TestFragment on Query { __typename From d7c5b0bd9ca2be68ee2837d43b0828e754d35a71 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 14 Jun 2022 14:05:13 -0700 Subject: [PATCH 13/17] fix: Correctly add public modifier on schema local mutation definitions when required by module type --- ...LocalCacheMutationDefinitionTemplate.swift | 3 +- ...CacheMutationDefinitionTemplateTests.swift | 58 +++++++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/LocalCacheMutationDefinitionTemplate.swift b/Sources/ApolloCodegenLib/Templates/LocalCacheMutationDefinitionTemplate.swift index f541c94619..992f294bb1 100644 --- a/Sources/ApolloCodegenLib/Templates/LocalCacheMutationDefinitionTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/LocalCacheMutationDefinitionTemplate.swift @@ -14,7 +14,8 @@ struct LocalCacheMutationDefinitionTemplate: OperationTemplateRenderer { var template: TemplateString { TemplateString( """ - public class \(operation.definition.nameWithSuffix.firstUppercased): LocalCacheMutation { + \(embeddedAccessControlModifier(config: config))\ + class \(operation.definition.nameWithSuffix.firstUppercased): LocalCacheMutation { public static let operationType: GraphQLOperationType = .\(operation.definition.operationType.rawValue) \(section: VariableProperties(operation.definition.variables)) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift index 275bad9871..b1e6095e7e 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/LocalCacheMutationDefinitionTemplateTests.swift @@ -70,7 +70,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { // given let expected = """ - public class TestOperationLocalCacheMutation: LocalCacheMutation { + class TestOperationLocalCacheMutation: LocalCacheMutation { public static let operationType: GraphQLOperationType = .query """ @@ -106,7 +106,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { let expected = """ - public class LowercaseOperationLocalCacheMutation: LocalCacheMutation { + class LowercaseOperationLocalCacheMutation: LocalCacheMutation { public static let operationType: GraphQLOperationType = .query """ @@ -132,7 +132,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationLocalCacheMutation: LocalCacheMutation { + class TestOperationLocalCacheMutation: LocalCacheMutation { public static let operationType: GraphQLOperationType = .query """ @@ -172,7 +172,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationLocalCacheMutation: LocalCacheMutation { + class TestOperationLocalCacheMutation: LocalCacheMutation { public static let operationType: GraphQLOperationType = .mutation """ @@ -212,7 +212,7 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { let expected = """ - public class TestOperationLocalCacheMutation: LocalCacheMutation { + class TestOperationLocalCacheMutation: LocalCacheMutation { public static let operationType: GraphQLOperationType = .subscription """ @@ -243,6 +243,54 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 6, ignoringExtraLines: true)) } + func test_render_givenModuleType_swiftPackageManager_generatesClassDefinition_withPublicModifier() throws { + // given + config = .mock(.swiftPackageManager) + try buildSubjectAndOperation() + + let expected = """ + public class TestOperationLocalCacheMutation: LocalCacheMutation { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_other_generatesClassDefinition_withPublicModifier() throws { + // given + config = .mock(.other) + try buildSubjectAndOperation() + + let expected = """ + public class TestOperationLocalCacheMutation: LocalCacheMutation { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + + func test_render_givenModuleType_embeddedInTarget_generatesClassDefinition_noPublicModifier() throws { + // given + config = .mock(.embeddedInTarget(name: "MyOtherProject")) + try buildSubjectAndOperation() + + let expected = """ + class TestOperationLocalCacheMutation: LocalCacheMutation { + """ + + // when + let actual = renderSubject() + + // then + expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) + } + // MARK: - Variables func test__generate__givenQueryWithScalarVariable_generatesQueryOperationWithVariable() throws { From cec5adafb10ae04d2fe6f1fc078c9e3a6429d16b Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 14 Jun 2022 14:12:51 -0700 Subject: [PATCH 14/17] Add local cache mutation typealias definitions to embedded template for the schema --- .../Templates/SchemaTemplate.swift | 6 ++++++ .../Templates/SchemaTemplateTests.swift | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift index 4c913359c8..51cfbd79ee 100644 --- a/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SchemaTemplate.swift @@ -27,6 +27,12 @@ struct SchemaTemplate: TemplateRenderer { \(embeddedAccessControlModifier(config: config))\ typealias InlineFragment = \(schemaName)_InlineFragment + + \(embeddedAccessControlModifier(config: config))\ + typealias MutableSelectionSet = \(schemaName)_MutableSelectionSet + + \(embeddedAccessControlModifier(config: config))\ + typealias MutableInlineFragment = \(schemaName)_MutableInlineFragment """), else: protocolDefinition(prefix: nil, schemaName: schemaName)) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift index 1e2a539700..8653b860c9 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SchemaTemplateTests.swift @@ -96,6 +96,10 @@ class SchemaTemplateTests: XCTestCase { typealias InlineFragment = AName_InlineFragment + typealias MutableSelectionSet = AName_MutableSelectionSet + + typealias MutableInlineFragment = AName_MutableInlineFragment + """ let expectedDetached = """ @@ -201,7 +205,7 @@ class SchemaTemplateTests: XCTestCase { let actual = renderTemplate() // then - expect(actual).to(equalLineByLine(expected, atLine: 7, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 11, ignoringExtraLines: true)) } func test__render__givenModuleSwiftPackageManager_shouldGenerateEnumDefinition_withPublicModifier() { @@ -216,7 +220,7 @@ class SchemaTemplateTests: XCTestCase { let actual = renderTemplate() // then - expect(actual).to(equalLineByLine(expected, atLine: 9, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } func test__render__givenModuleOther_shouldGenerateEnumDefinition_withPublicModifier() { @@ -231,7 +235,7 @@ class SchemaTemplateTests: XCTestCase { let actual = renderTemplate() // then - expect(actual).to(equalLineByLine(expected, atLine: 9, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } func test__render__givenWithReferencedObjects_generatesObjectTypeFunctionCorrectlyCased() { @@ -261,7 +265,7 @@ class SchemaTemplateTests: XCTestCase { let actual = renderTemplate() // then - expect(actual).to(equalLineByLine(expected, atLine: 8)) + expect(actual).to(equalLineByLine(expected, atLine: 12)) } func test__render__givenWithReferencedOtherTypes_generatesObjectTypeNotIncludingNonObjectTypesFunction() { @@ -292,6 +296,6 @@ class SchemaTemplateTests: XCTestCase { let actual = renderTemplate() // then - expect(actual).to(equalLineByLine(expected, atLine: 8)) + expect(actual).to(equalLineByLine(expected, atLine: 12)) } } From ef4bc5bb6271d000067f0bc3cf7ebf1243b9fcee Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 14 Jun 2022 14:13:23 -0700 Subject: [PATCH 15/17] chore: Rename test file to match XCTestCase definition name --- Apollo.xcodeproj/project.pbxproj | 8 ++++---- ...ensionsTests.swift => FileManagerExtensionTests.swift} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename Tests/ApolloCodegenTests/{FileManagerExtensionsTests.swift => FileManagerExtensionTests.swift} (100%) diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index 29a9bcefb5..54bbe3cc5d 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -74,7 +74,7 @@ 9BAEEBF32346DDAD00808306 /* CodegenLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEBF22346DDAD00808306 /* CodegenLogger.swift */; }; 9BAEEBF72346F0A000808306 /* StaticString+Apollo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEBF62346F0A000808306 /* StaticString+Apollo.swift */; }; 9BAEEC01234BB8FD00808306 /* ApolloCodegenLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B7B6F47233C26D100F32205 /* ApolloCodegenLib.framework */; }; - 9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */; }; + 9BAEEC10234BB95B00808306 /* FileManagerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */; }; 9BAEEC17234C275600808306 /* ApolloSchemaPublicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */; }; 9BAEEC19234C297800808306 /* ApolloCodegenConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */; }; 9BC139A424EDCA6C00876D29 /* MaxRetryInterceptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BC139A224EDCA4400876D29 /* MaxRetryInterceptorTests.swift */; }; @@ -924,7 +924,7 @@ 9BAEEBF62346F0A000808306 /* StaticString+Apollo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StaticString+Apollo.swift"; sourceTree = ""; }; 9BAEEBFC234BB8FD00808306 /* ApolloCodegenTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ApolloCodegenTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9BAEEC0C234BB95B00808306 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionsTests.swift; sourceTree = ""; }; + 9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionTests.swift; sourceTree = ""; }; 9BAEEC11234BBA9200808306 /* CodegenTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodegenTestHelper.swift; sourceTree = ""; }; 9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaPublicTests.swift; sourceTree = ""; }; 9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenConfigurationTests.swift; sourceTree = ""; }; @@ -1867,7 +1867,7 @@ E61EF712275EC99A00191DA7 /* ApolloCodegenTests.swift */, 9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */, E6908E54282694630054682B /* ApolloCodegenConfigurationCodableTests.swift */, - 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */, + 9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */, 9B4751AC2575B5070001FB87 /* PluralizerTests.swift */, 9B8C3FB4248DA3E000707B13 /* URLExtensionsTests.swift */, 9BAEEC0C234BB95B00808306 /* Info.plist */, @@ -3926,7 +3926,7 @@ buildActionMask = 2147483647; files = ( E669352D2803EF67004E1FFC /* CustomScalarTemplateTests.swift in Sources */, - 9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */, + 9BAEEC10234BB95B00808306 /* FileManagerExtensionTests.swift in Sources */, E6D90D09278FA5C3009CAC5D /* InputObjectFileGeneratorTests.swift in Sources */, E674DB43274C0AD9009BB90E /* GlobTests.swift in Sources */, DE223C1C271F3288004A0148 /* AnimalKingdomIRCreationTests.swift in Sources */, diff --git a/Tests/ApolloCodegenTests/FileManagerExtensionsTests.swift b/Tests/ApolloCodegenTests/FileManagerExtensionTests.swift similarity index 100% rename from Tests/ApolloCodegenTests/FileManagerExtensionsTests.swift rename to Tests/ApolloCodegenTests/FileManagerExtensionTests.swift From 5eb0a7d4ad9cc77b32940e626cdcb3f1c662bcce Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 14 Jun 2022 14:16:58 -0700 Subject: [PATCH 16/17] tests: Update subject to use a lowercase name as the input --- .../CodeGeneration/Templates/EnumTemplateTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift index 9268e8fe00..ca0d1ac727 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/EnumTemplateTests.swift @@ -106,7 +106,7 @@ class EnumTemplateTests: XCTestCase { func test_render_givenSchemaEnum_generatesSwiftEnumRespectingValueCasing() throws { // given buildSubject( - name: "CasedEnum", + name: "casedEnum", values: [ ("lower", nil), ("UPPER", nil), From f71d41d7090b0c7ad83ae33530f0d303876610d7 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 14 Jun 2022 14:36:37 -0700 Subject: [PATCH 17/17] tests: Rename tests to remove mention of casing when the test does not fulfil that --- .../CodeGeneration/Templates/InterfaceTemplateTests.swift | 4 ++-- .../CodeGeneration/Templates/ObjectTemplateTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift index 3207c8b90d..16dd6a747c 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InterfaceTemplateTests.swift @@ -63,7 +63,7 @@ class InterfaceTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier_correctlyCased() { + func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier() { // given buildSubject(config: .mock(.other)) @@ -78,7 +78,7 @@ class InterfaceTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier_correctlyCased() { + func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier() { // given buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget"))) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift index 4e8989937d..b01c911ce9 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/ObjectTemplateTests.swift @@ -78,7 +78,7 @@ class ObjectTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier_correctlyCased() { + func test_render_givenModuleType_other_generatesSwiftClassDefinition_withPublicModifier() { // given buildSubject(config: .mock(.other)) @@ -94,7 +94,7 @@ class ObjectTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true)) } - func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier_correctlyCased() { + func test_render_givenModuleType_embeddedInTarget_generatesSwiftClassDefinition_noPublicModifier() { // given buildSubject(config: .mock(.embeddedInTarget(name: "TestTarget")))