From 416a9e67da40ee0bd2dd150cf327ef4ac9e2ce9e Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 17:38:16 -0700 Subject: [PATCH 01/12] Escape double quotes in @available attribute --- .../TemplateString+AvailabilityDeprecated.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift index 51f72e99c0..7aa3f4ee65 100644 --- a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift +++ b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift @@ -6,7 +6,7 @@ extension TemplateString.StringInterpolation { ) { guard config.options.warningsOnDeprecatedUsage == .include, - let deprecationReason = deprecationReason + let deprecationReason = deprecationReason?.escapedDoubleQuotes() else { removeLineIfEmpty() return @@ -28,3 +28,9 @@ extension TemplateString.StringInterpolation { } } } + +fileprivate extension String { + func escapedDoubleQuotes() -> String { + replacingOccurrences(of: "\"", with: "\\\"") + } +} From f91161c0ed0129f9e79034f12fc7e3838ecbe9ca Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 17:38:45 -0700 Subject: [PATCH 02/12] Add tests for escaping double quotes in @available attribute --- Apollo.xcodeproj/project.pbxproj | 4 + ...plateString_DeprecationMessage_Tests.swift | 90 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index 5de1650958..dc7dc6c389 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -709,6 +709,7 @@ E608A52B280905C2001BE656 /* WSProtocolTestsBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = E608A528280905C2001BE656 /* WSProtocolTestsBase.swift */; }; E608A52D280905E9001BE656 /* SubscriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E608A52C280905E9001BE656 /* SubscriptionTests.swift */; }; E60AE2EE27E3FC6C003C093A /* TemplateRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E60AE2ED27E3FC6C003C093A /* TemplateRenderer.swift */; }; + E60F457A29E4CFB800E60A04 /* TemplateString_DeprecationMessage_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E60F457929E4CFB800E60A04 /* TemplateString_DeprecationMessage_Tests.swift */; }; E610D8D7278EA2390023E495 /* EnumFileGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E610D8D6278EA2390023E495 /* EnumFileGenerator.swift */; }; E610D8D9278EA2560023E495 /* EnumFileGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E610D8D8278EA2560023E495 /* EnumFileGeneratorTests.swift */; }; E610D8DB278EB0900023E495 /* InterfaceFileGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E610D8DA278EB0900023E495 /* InterfaceFileGenerator.swift */; }; @@ -1878,6 +1879,7 @@ E608A528280905C2001BE656 /* WSProtocolTestsBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WSProtocolTestsBase.swift; sourceTree = ""; }; E608A52C280905E9001BE656 /* SubscriptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionTests.swift; sourceTree = ""; }; E60AE2ED27E3FC6C003C093A /* TemplateRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateRenderer.swift; sourceTree = ""; }; + E60F457929E4CFB800E60A04 /* TemplateString_DeprecationMessage_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateString_DeprecationMessage_Tests.swift; sourceTree = ""; }; E610D8D6278EA2390023E495 /* EnumFileGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumFileGenerator.swift; sourceTree = ""; }; E610D8D8278EA2560023E495 /* EnumFileGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumFileGeneratorTests.swift; sourceTree = ""; }; E610D8DA278EB0900023E495 /* InterfaceFileGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceFileGenerator.swift; sourceTree = ""; }; @@ -2949,6 +2951,7 @@ DE9CEAF2282C6AC300959AF9 /* TemplateRenderer_TestMockFile_Tests.swift */, E64F7EB927A085D90059C021 /* UnionTemplateTests.swift */, DED5B358286CEA0900AE6BFF /* TemplateString_Documentation_Tests.swift */, + E60F457929E4CFB800E60A04 /* TemplateString_DeprecationMessage_Tests.swift */, ); path = Templates; sourceTree = ""; @@ -5097,6 +5100,7 @@ E6D90D0D278FFE35009CAC5D /* SchemaMetadataFileGeneratorTests.swift in Sources */, E6B42D0B27A4746800A3BD58 /* SchemaModuleFileGeneratorTests.swift in Sources */, 9B68F0552416B33300E97318 /* LineByLineComparison.swift in Sources */, + E60F457A29E4CFB800E60A04 /* TemplateString_DeprecationMessage_Tests.swift in Sources */, DE09066F27A4713F00211300 /* OperationDefinitionTemplateTests.swift in Sources */, DE09F9C6270269F800795949 /* OperationDefinitionTemplate_DocumentType_Tests.swift in Sources */, 9B4751AD2575B5070001FB87 /* PluralizerTests.swift in Sources */, diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift new file mode 100644 index 0000000000..96d0c0a9dd --- /dev/null +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -0,0 +1,90 @@ +import XCTest +import Nimble +@testable import ApolloCodegenLib + +final class TemplateString_DeprecationMessage_Tests: XCTestCase { + + let config = ApolloCodegen.ConfigurationContext(config: .mock( + options: .init( + warningsOnDeprecatedUsage: .include + ) + )) + + // MARK: - Swift @available Attribute Tests + + func test__availableAttribute__givenSingleLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "not supported, use \"another thing\" instead.", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "not supported, use \"another thing\" instead.") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenMultiLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "not supported\nuse \"another thing\" instead.", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: """ + not supported + use \"another thing\" instead. + """) + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + // MARK: SDL-to-Generation Test + // + // These tests ensure that when given double quotes in SDL the generation of Swift code along with + // all attributes and warnings are generated as expected. + + func test__render__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let schemaSDL = #""" + type Query { + animal: Animal + } + + type Animal { + genus: String @deprecated(reason: "not supported, use \"species\" instead.") + species: String + } + """# + + let document = """ + query GetAnimal { + animal { + genus + } + } + """ + + let ir = try IR.mock(schema: schemaSDL, document: document) + let operation = ir.build(operation: try XCTUnwrap(ir.compilationResult[operation: "GetAnimal"])) + let subject = SelectionSetTemplate(generateInitializers: true, config: config) + + let expected = #""" + @available(*, deprecated, message: "not supported, use \"species\" instead.") + """# + + // then + let actual = subject.render(for: operation) + + expect(actual).to(equalLineByLine(expected, atLine: 37, ignoringExtraLines: true)) + } + +} From c7499652ddde0d16129702357d6dea815366b086 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 18:22:26 -0700 Subject: [PATCH 03/12] Add input field SDL test --- ...plateString_DeprecationMessage_Tests.swift | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index 96d0c0a9dd..51fb1ab86a 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -49,10 +49,11 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: SDL-to-Generation Test // - // These tests ensure that when given double quotes in SDL the generation of Swift code along with - // all attributes and warnings are generated as expected. + // These tests ensure that when given double quotes in SDL the generation of Swift code works as + // expected from frontend parsing all the way to rendering of warnings and attributes. There is + // a test here for all the places that the GraphQL schema supports the @deprecated directive. - func test__render__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__field__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let schemaSDL = #""" type Query { @@ -87,4 +88,43 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 37, ignoringExtraLines: true)) } + func test__inputField_givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let schemaSDL = #""" + type Query { + animal(filter: Filter): Animal + } + + type Animal { + name: String + } + + input Filter { + genus: String @deprecated(reason: "not supported, use \"species\" instead.") + } + """# + + let document = """ + query GetAnimal($filter: Filter) { + animal(filter: $filter) { + name + } + } + """ + + let ir = try IR.mock(schema: schemaSDL, document: document) + let inputObject = ir.schema.referencedTypes.inputObjects[0] + + let subject = InputObjectTemplate(graphqlInputObject: inputObject, config: config) + + let expected = #""" + @available(*, deprecated, message: "not supported, use \"species\" instead.") + """# + + // then + let actual = subject.render() + + expect(actual).to(equalLineByLine(expected, atLine: 23, ignoringExtraLines: true)) + } + } From f245d4a820f4394ec5bb4df8aee09d84c3f1916a Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 18:34:42 -0700 Subject: [PATCH 04/12] Add SDL test for enum comment --- ...plateString_DeprecationMessage_Tests.swift | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index 51fb1ab86a..c0dc878e4b 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -50,8 +50,9 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: SDL-to-Generation Test // // These tests ensure that when given double quotes in SDL the generation of Swift code works as - // expected from frontend parsing all the way to rendering of warnings and attributes. There is - // a test here for all the places that the GraphQL schema supports the @deprecated directive. + // expected from frontend parsing all the way to rendering of attributes, comments andwarnings. + // There is a test here for all the places that the GraphQL schema supports the @deprecated + // directive. func test__field__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given @@ -127,4 +128,47 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 23, ignoringExtraLines: true)) } + func test__enum__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldNotEscapeDoubleQuotes() throws { + // given + let schemaSDL = #""" + type Query { + animal: Animal + } + + type Animal { + name: String + size: Size + } + + enum Size { + tiny @deprecated(reason: "not supported, use \"small\" instead.") + small + large + } + """# + + let document = """ + query GetAnimal { + animal { + name + size + } + } + """ + + let ir = try IR.mock(schema: schemaSDL, document: document) + let `enum` = ir.schema.referencedTypes.enums[0] + + let subject = EnumTemplate(graphqlEnum: `enum`, config: config) + + let expected = #""" + /// **Deprecated**: not supported, use "small" instead. + """# + + // then + let actual = subject.render() + + expect(actual).to(equalLineByLine(expected, atLine: 8, ignoringExtraLines: true)) + } + } From a551b59b44b0a4da7c6fe7b85839edf89fbf748a Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 22:37:10 -0700 Subject: [PATCH 05/12] Refactor #warning message into extension --- ...emplateString+AvailabilityDeprecated.swift | 25 +++++++++--- .../Templates/SelectionSetTemplate.swift | 3 +- ...plateString_DeprecationMessage_Tests.swift | 38 +++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift index 7aa3f4ee65..6e274a5fdd 100644 --- a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift +++ b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift @@ -6,27 +6,40 @@ extension TemplateString.StringInterpolation { ) { guard config.options.warningsOnDeprecatedUsage == .include, - let deprecationReason = deprecationReason?.escapedDoubleQuotes() + let escapedDeprecationReason = deprecationReason?.escapedDoubleQuotes() else { removeLineIfEmpty() return } - let deprecationReasonLines = deprecationReason - .split(separator: "\n", omittingEmptySubsequences: false) + if escapedDeprecationReason.firstIndex(of: "\n") != nil { + let splitReasonLines = escapedDeprecationReason + .split(separator: "\n", omittingEmptySubsequences: false) - if deprecationReasonLines.count > 1 { appendInterpolation(""" @available(*, deprecated, message: \"\"\" - \(deprecationReasonLines.joinedAsLines(withIndent: " ")) + \(splitReasonLines.joinedAsLines(withIndent: " ")) \"\"\") """) } else { appendInterpolation(""" - @available(*, deprecated, message: \"\(deprecationReason)\") + @available(*, deprecated, message: \"\(escapedDeprecationReason)\") """) } } + + mutating func appendInterpolation( + field: String, + argument: String, + warningReason: String + ) { + let escapedWarningReason = warningReason.escapedDoubleQuotes() + + appendInterpolation(""" + #warning("Argument '\(argument)' of field '\(field)' is deprecated. \ + Reason: '\(escapedWarningReason)'") + """) + } } fileprivate extension String { diff --git a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift index 416d64d7ca..04ed6eddac 100644 --- a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift @@ -187,8 +187,7 @@ struct SelectionSetTemplate { return """ \(if: deprecatedArguments != nil && !deprecatedArguments.unsafelyUnwrapped.isEmpty, """ \(deprecatedArguments.unsafelyUnwrapped.map { """ - #warning("Argument '\($0.arg)' of field '\($0.field)' is deprecated. \ - Reason: '\($0.reason)'") + \(field: $0.field, argument: $0.arg, warningReason: $0.reason) """}) """) \(selectionsTemplate) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index c0dc878e4b..a588a3ea25 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -171,4 +171,42 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 8, ignoringExtraLines: true)) } + func test__argument__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let schemaSDL = #""" + type Query { + animal: Animal + } + + type Animal { + species: String + predators(genus: String @deprecated(reason: "not supported, use \"species\" instead."), species: String): Animal + } + """# + + let document = """ + query GetAnimal($genus: String) { + animal { + species + predators(genus: $genus) { + species + } + } + } + """ + + let ir = try IR.mock(schema: schemaSDL, document: document) + let operation = ir.build(operation: try XCTUnwrap(ir.compilationResult[operation: "GetAnimal"])) + let subject = SelectionSetTemplate(generateInitializers: true, config: config) + + let expected = #""" + #warning("Argument 'genus' of field 'predators' is deprecated. Reason: 'not supported, use \"species\" instead.'") + """# + + // then + let actual = subject.render(for: operation) + + expect(actual).to(equalLineByLine(expected, atLine: 32, ignoringExtraLines: true)) + } + } From bd40ba43dffa5e5eb913736e15c2c664da2bf6a8 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Mon, 10 Apr 2023 22:44:17 -0700 Subject: [PATCH 06/12] Add test for #warning directive --- ...mplateString_DeprecationMessage_Tests.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index a588a3ea25..e849b725b6 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -47,6 +47,24 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected)) } + // MARK: Swift #warning Directive Tests + + func test__warningDirective__givenSingleLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "not supported, use \"another thing\" instead.") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'not supported, use \"another thing\" instead.'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + // MARK: SDL-to-Generation Test // // These tests ensure that when given double quotes in SDL the generation of Swift code works as From 5705fb86400092b42bddbd45fafcbf8366f04f6f Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 11 Apr 2023 14:58:09 -0700 Subject: [PATCH 07/12] Remove newline processing in deprecation messages --- ...emplateString+AvailabilityDeprecated.swift | 17 +--- .../SelectionSetTemplateTests.swift | 94 ------------------- ...plateString_DeprecationMessage_Tests.swift | 23 +---- 3 files changed, 5 insertions(+), 129 deletions(-) diff --git a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift index 6e274a5fdd..bb0e201f87 100644 --- a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift +++ b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift @@ -12,20 +12,9 @@ extension TemplateString.StringInterpolation { return } - if escapedDeprecationReason.firstIndex(of: "\n") != nil { - let splitReasonLines = escapedDeprecationReason - .split(separator: "\n", omittingEmptySubsequences: false) - - appendInterpolation(""" - @available(*, deprecated, message: \"\"\" - \(splitReasonLines.joinedAsLines(withIndent: " ")) - \"\"\") - """) - } else { - appendInterpolation(""" - @available(*, deprecated, message: \"\(escapedDeprecationReason)\") - """) - } + appendInterpolation(""" + @available(*, deprecated, message: \"\(escapedDeprecationReason)\") + """) } mutating func appendInterpolation( diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift index 8ed41db470..f8389ddf85 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift @@ -5982,100 +5982,6 @@ class SelectionSetTemplateTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 14, ignoringExtraLines: true)) } - - func test__render_fieldAccessors__givenWarningsOnDeprecatedUsage_include_hasDeprecatedField_withMultilineDocumentation_shouldGenerateWarningBelowDocumentationWithMultilineLiteral() throws { - // given - schemaSDL = """ - type Query { - allAnimals: [Animal!] - } - - type Animal { - "This field is a string." - string: String! @deprecated(reason: "Cause I\\nsaid so!") - } - """ // Escaping the backslash is required to allow the frontend to parse correctly this string. - // Removing the escape leads to a "unterminated string literal" error when parsing the schema. - - document = """ - query TestOperation { - allAnimals { - string - } - } - """ - - let expected = #""" - /// This field is a string. - @available(*, deprecated, message: """ - Cause I - said so! - """) - public var string: String { __data["string"] } - """# - - // when - try buildSubjectAndOperation( - schemaDocumentation: .include, - warningsOnDeprecatedUsage: .include - ) - let allAnimals = try XCTUnwrap( - operation[field: "query"]?[field: "allAnimals"] as? IR.EntityField - ) - - let actual = subject.render(field: allAnimals) - - // then - expect(actual).to(equalLineByLine(expected, atLine: 14, ignoringExtraLines: true)) - } - - func test__render_fieldAccessors__givenWarningsOnDeprecatedUsage_include_hasDeprecatedField_withMultilineDocumentation_includingEmptyLine_shouldGenerateWarningBelowDocumentationWithMultilineLiteral() throws { - // given - schemaSDL = """ - type Query { - allAnimals: [Animal!] - } - - type Animal { - "This field is a string." - string: String! @deprecated(reason: "Cause I\\n\\nsaid so!") - } - """ // Escaping the backslash is required to allow the frontend to parse correctly this string. - // Removing the escape leads to a "unterminated string literal" error when parsing the schema. - - document = """ - query TestOperation { - allAnimals { - string - } - } - """ - - let expected = #""" - /// This field is a string. - @available(*, deprecated, message: """ - Cause I - - said so! - """) - public var string: String { __data["string"] } - """# - - // when - try buildSubjectAndOperation( - schemaDocumentation: .include, - warningsOnDeprecatedUsage: .include - ) - let allAnimals = try XCTUnwrap( - operation[field: "query"]?[field: "allAnimals"] as? IR.EntityField - ) - - let actual = subject.render(field: allAnimals) - - // then - expect(actual).to(equalLineByLine(expected, atLine: 14, ignoringExtraLines: true)) - } - func test__render_fieldAccessors__givenWarningsOnDeprecatedUsage_exclude_hasDeprecatedField_shouldNotGenerateWarning() throws { // given schemaSDL = """ diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index e849b725b6..6213668fc1 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -12,7 +12,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: - Swift @available Attribute Tests - func test__availableAttribute__givenSingleLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__availableAttribute__givenDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let subject = TemplateString(""" \(deprecationReason: "not supported, use \"another thing\" instead.", config: config) @@ -28,28 +28,9 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected)) } - func test__availableAttribute__givenMultiLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { - // given - let subject = TemplateString(""" - \(deprecationReason: "not supported\nuse \"another thing\" instead.", config: config) - """) - - let expected = #""" - @available(*, deprecated, message: """ - not supported - use \"another thing\" instead. - """) - """# - - // then - let actual = subject.description - - expect(actual).to(equalLineByLine(expected)) - } - // MARK: Swift #warning Directive Tests - func test__warningDirective__givenSingleLineDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__warningDirective__givenDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let subject = TemplateString(""" \(field: "fieldOne", argument: "argOne", warningReason: "not supported, use \"another thing\" instead.") From 2b82ffcc9b68340cbe92af446fe1d782082ca602 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 11 Apr 2023 22:36:58 -0700 Subject: [PATCH 08/12] Refactor escaping logic to handle all Swift String special characters --- ...emplateString+AvailabilityDeprecated.swift | 33 ++- ...plateString_DeprecationMessage_Tests.swift | 229 ++++++++++++++++-- 2 files changed, 238 insertions(+), 24 deletions(-) diff --git a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift index bb0e201f87..db2409fa94 100644 --- a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift +++ b/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift @@ -6,7 +6,7 @@ extension TemplateString.StringInterpolation { ) { guard config.options.warningsOnDeprecatedUsage == .include, - let escapedDeprecationReason = deprecationReason?.escapedDoubleQuotes() + let escapedDeprecationReason = deprecationReason?.escapedSwiftStringSpecialCharacters() else { removeLineIfEmpty() return @@ -22,7 +22,7 @@ extension TemplateString.StringInterpolation { argument: String, warningReason: String ) { - let escapedWarningReason = warningReason.escapedDoubleQuotes() + let escapedWarningReason = warningReason.escapedSwiftStringSpecialCharacters() appendInterpolation(""" #warning("Argument '\(argument)' of field '\(field)' is deprecated. \ @@ -31,8 +31,31 @@ extension TemplateString.StringInterpolation { } } -fileprivate extension String { - func escapedDoubleQuotes() -> String { - replacingOccurrences(of: "\"", with: "\\\"") +extension String { + /// Replaces specific escaped characters so they are written into the rendered deprecation + /// message as escaped characters to be correctly rendered to the user in an Xcode warning + /// (e.g., `\"` becomes `\\\"`). + /// + /// String literals can include the following special characters: `\0` (null character), + /// `\\` (backslash), `\t` (horizontal tab), `\n` (line feed), `\r` (carriage return), + /// `\"` (double quotation mark) and `\'` (single quotation mark). + func escapedSwiftStringSpecialCharacters() -> String { + var escapedString = String() + escapedString.reserveCapacity(self.count) + + forEach { character in + switch (character) { + case "\0": escapedString.append(#"\0"#) + case "\\": escapedString.append(#"\\"#) + case "\t": escapedString.append(#"\t"#) + case "\n": escapedString.append(#"\n"#) + case "\r": escapedString.append(#"\r"#) + case "\"": escapedString.append(#"\""#) + case "\'": escapedString.append(#"\'"#) + default: escapedString.append(character) + } + } + + return escapedString } } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index 6213668fc1..f126fbcb7e 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -12,14 +12,110 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: - Swift @available Attribute Tests - func test__availableAttribute__givenDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__availableAttribute__givenDeprecationMessageWithNullCharacter_shouldEscapeNullCharacter() throws { // given let subject = TemplateString(""" - \(deprecationReason: "not supported, use \"another thing\" instead.", config: config) + \(deprecationReason: "message with \0 (escaped null character)", config: config) """) let expected = #""" - @available(*, deprecated, message: "not supported, use \"another thing\" instead.") + @available(*, deprecated, message: "message with \0 (escaped null character)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithBackslash_shouldEscapeBackslash() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \\ (escaped backslash)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \\ (escaped backslash)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithHorizontalTab_shouldEscapeHorizontalTab() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \t (escaped horizontal tab)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \t (escaped horizontal tab)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithLineFeed_shouldEscapeLineFeed() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \n (escaped line feed)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \n (escaped line feed)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithCarriageReturn_shouldEscapeCarriageReturn() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \r (escaped carriage return)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \r (escaped carriage return)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithDoubleQuote_shouldEscapeDoubleQuote() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \" (escaped double quote)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \" (escaped double quote)") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__availableAttribute__givenDeprecationMessageWithSingleQuote_shouldEscapeSingleQuote() throws { + // given + let subject = TemplateString(""" + \(deprecationReason: "message with \' (escaped single quote)", config: config) + """) + + let expected = #""" + @available(*, deprecated, message: "message with \' (escaped single quote)") """# // then @@ -30,14 +126,110 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: Swift #warning Directive Tests - func test__warningDirective__givenDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__warningDirective__givenDeprecationMessageWithNullCharacter_shouldEscapeNullCharacter() throws { // given let subject = TemplateString(""" - \(field: "fieldOne", argument: "argOne", warningReason: "not supported, use \"another thing\" instead.") + \(field: "fieldOne", argument: "argOne", warningReason: "message with \0 (escaped null character)") """) let expected = #""" - #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'not supported, use \"another thing\" instead.'") + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \0 (escaped null character)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithBackslash_shouldEscapeBackslash() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \\ (escaped backslash)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \\ (escaped backslash)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithHorizontalTab_shouldEscapeHorizontalTab() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \t (escaped horizontal tab)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \t (escaped horizontal tab)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithLineFeed_shouldEscapeLineFeed() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \n (escaped line feed)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \n (escaped line feed)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithCarriageReturn_shouldEscapeCarriageReturn() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \r (escaped carriage return)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \r (escaped carriage return)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithDoubleQuote_shouldEscapeDoubleQuote() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \" (escaped double quote)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \" (escaped double quote)'") + """# + + // then + let actual = subject.description + + expect(actual).to(equalLineByLine(expected)) + } + + func test__warningDirective__givenDeprecationMessageWithSingleQuote_shouldEscapeSingleQuote() throws { + // given + let subject = TemplateString(""" + \(field: "fieldOne", argument: "argOne", warningReason: "message with \' (escaped single quote)") + """) + + let expected = #""" + #warning("Argument 'argOne' of field 'fieldOne' is deprecated. Reason: 'message with \' (escaped single quote)'") """# // then @@ -53,7 +245,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // There is a test here for all the places that the GraphQL schema supports the @deprecated // directive. - func test__field__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__field__givenSDLDeprecationMessageWithDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let schemaSDL = #""" type Query { @@ -61,8 +253,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { } type Animal { - genus: String @deprecated(reason: "not supported, use \"species\" instead.") - species: String + genus: String @deprecated(reason: "message with all allowed escape characters: \\ and \" and \t and \n and \r.") } """# @@ -79,7 +270,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { let subject = SelectionSetTemplate(generateInitializers: true, config: config) let expected = #""" - @available(*, deprecated, message: "not supported, use \"species\" instead.") + @available(*, deprecated, message: "message with all allowed escape characters: \\ and \" and \t and \n and \r.") """# // then @@ -88,7 +279,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 37, ignoringExtraLines: true)) } - func test__inputField_givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__inputField_givenSDLDeprecationMessageWithDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let schemaSDL = #""" type Query { @@ -100,7 +291,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { } input Filter { - genus: String @deprecated(reason: "not supported, use \"species\" instead.") + genus: String @deprecated(reason: "message with all allowed escape characters: \\ and \" and \t and \n and \r.") } """# @@ -118,7 +309,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { let subject = InputObjectTemplate(graphqlInputObject: inputObject, config: config) let expected = #""" - @available(*, deprecated, message: "not supported, use \"species\" instead.") + @available(*, deprecated, message: "message with all allowed escape characters: \\ and \" and \t and \n and \r.") """# // then @@ -127,7 +318,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 23, ignoringExtraLines: true)) } - func test__enum__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldNotEscapeDoubleQuotes() throws { + func test__enum__givenSDLDeprecationMessageWithDoubleQuotes_shouldNotEscapeDoubleQuotes() throws { // given let schemaSDL = #""" type Query { @@ -140,7 +331,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { } enum Size { - tiny @deprecated(reason: "not supported, use \"small\" instead.") + tiny @deprecated(reason: "message with all allowed escape characters: \\ and \" and \t and \n and \r.") small large } @@ -161,7 +352,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { let subject = EnumTemplate(graphqlEnum: `enum`, config: config) let expected = #""" - /// **Deprecated**: not supported, use "small" instead. + /// **Deprecated**: message with all allowed escape characters: \\ and \" and \t and \n and \r. """# // then @@ -170,7 +361,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 8, ignoringExtraLines: true)) } - func test__argument__givenSDLDeprecationMessageWithInnerDoubleQuotes_shouldEscapeDoubleQuotes() throws { + func test__argument__givenSDLDeprecationMessageWithDoubleQuotes_shouldEscapeDoubleQuotes() throws { // given let schemaSDL = #""" type Query { @@ -179,7 +370,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { type Animal { species: String - predators(genus: String @deprecated(reason: "not supported, use \"species\" instead."), species: String): Animal + predators(genus: String @deprecated(reason: "message with all allowed escape characters: \\ and \" and \t and \n and \r."), species: String): Animal } """# @@ -199,7 +390,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { let subject = SelectionSetTemplate(generateInitializers: true, config: config) let expected = #""" - #warning("Argument 'genus' of field 'predators' is deprecated. Reason: 'not supported, use \"species\" instead.'") + #warning("Argument 'genus' of field 'predators' is deprecated. Reason: 'message with all allowed escape characters: \\ and \" and \t and \n and \r.'") """# // then From 3ad4de5d7b3867d61ec2cd25478b253e345b2245 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 11 Apr 2023 22:37:28 -0700 Subject: [PATCH 09/12] Escape comment in Enum template --- Sources/ApolloCodegenLib/Templates/EnumTemplate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift index c9dd02ba78..4d36abccac 100644 --- a/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/EnumTemplate.swift @@ -37,7 +37,7 @@ struct EnumTemplate: TemplateRenderer { \(if: shouldRenderDocumentation, "\(forceDocumentation: graphqlEnumValue.documentation)") \(ifLet: graphqlEnumValue.deprecationReason, { """ \(if: shouldRenderDocumentation, "///") - \(forceDocumentation: "**Deprecated**: \($0)") + \(forceDocumentation: "**Deprecated**: \($0.escapedSwiftStringSpecialCharacters())") """ }) \(caseDefinition(for: graphqlEnumValue)) """ From d466887a0eb7421235dfdd8395aba944371fc419 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Wed, 12 Apr 2023 12:26:36 -0700 Subject: [PATCH 10/12] Rename TemplateString extension file --- Apollo.xcodeproj/project.pbxproj | 8 ++++---- ...ated.swift => TemplateString+DeprecationMessage.swift} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename Sources/ApolloCodegenLib/{TemplateString+AvailabilityDeprecated.swift => TemplateString+DeprecationMessage.swift} (100%) diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index dc7dc6c389..57b7a22a5e 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 19E9F6AC26D58A9A003AB80E /* OperationMessageIdCreatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19E9F6AA26D58A92003AB80E /* OperationMessageIdCreatorTests.swift */; }; 19E9F6B526D6BF25003AB80E /* OperationMessageIdCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19E9F6A826D5867E003AB80E /* OperationMessageIdCreator.swift */; }; 2EE7FFD0276802E30035DC39 /* CacheKeyConstructionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE7FFCF276802E30035DC39 /* CacheKeyConstructionTests.swift */; }; - 534A754528EB21D6003291BE /* TemplateString+AvailabilityDeprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534A754428EB21D6003291BE /* TemplateString+AvailabilityDeprecated.swift */; }; + 534A754528EB21D6003291BE /* TemplateString+DeprecationMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534A754428EB21D6003291BE /* TemplateString+DeprecationMessage.swift */; }; 54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */; }; 5AC6CA4322AAF7B200B7C94D /* GraphQLHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */; }; 5BB2C0232380836100774170 /* VersionNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BB2C0222380836100774170 /* VersionNumberTests.swift */; }; @@ -1120,7 +1120,7 @@ 19E9F6A826D5867E003AB80E /* OperationMessageIdCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationMessageIdCreator.swift; sourceTree = ""; }; 19E9F6AA26D58A92003AB80E /* OperationMessageIdCreatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationMessageIdCreatorTests.swift; sourceTree = ""; }; 2EE7FFCF276802E30035DC39 /* CacheKeyConstructionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheKeyConstructionTests.swift; sourceTree = ""; }; - 534A754428EB21D6003291BE /* TemplateString+AvailabilityDeprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TemplateString+AvailabilityDeprecated.swift"; sourceTree = ""; }; + 534A754428EB21D6003291BE /* TemplateString+DeprecationMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TemplateString+DeprecationMessage.swift"; sourceTree = ""; }; 54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InMemoryNormalizedCache.swift; sourceTree = ""; }; 5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPMethod.swift; sourceTree = ""; }; 5BB2C0222380836100774170 /* VersionNumberTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionNumberTests.swift; sourceTree = ""; }; @@ -2511,7 +2511,7 @@ E674DB40274C0A9B009BB90E /* Glob.swift */, DE5FD600276923620033EE23 /* TemplateString.swift */, DED5B35A286CF16600AE6BFF /* TemplateString+CodegenConfiguration.swift */, - 534A754428EB21D6003291BE /* TemplateString+AvailabilityDeprecated.swift */, + 534A754428EB21D6003291BE /* TemplateString+DeprecationMessage.swift */, DE31A437276A78140020DC44 /* Templates */, E6E3BBDC276A8D6200E5218B /* FileGenerators */, ); @@ -4936,7 +4936,7 @@ E6B42D0927A472A700A3BD58 /* SwiftPackageManagerModuleTemplate.swift in Sources */, DE100B1A28872D0F00BE11C2 /* Documentation.docc in Sources */, E6D90D07278FA595009CAC5D /* InputObjectFileGenerator.swift in Sources */, - 534A754528EB21D6003291BE /* TemplateString+AvailabilityDeprecated.swift in Sources */, + 534A754528EB21D6003291BE /* TemplateString+DeprecationMessage.swift in Sources */, E64F7EB827A0854E0059C021 /* UnionTemplate.swift in Sources */, E60AE2EE27E3FC6C003C093A /* TemplateRenderer.swift in Sources */, 9BCA8C0926618226004FF2F6 /* UntypedGraphQLRequestBodyCreator.swift in Sources */, diff --git a/Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift b/Sources/ApolloCodegenLib/TemplateString+DeprecationMessage.swift similarity index 100% rename from Sources/ApolloCodegenLib/TemplateString+AvailabilityDeprecated.swift rename to Sources/ApolloCodegenLib/TemplateString+DeprecationMessage.swift From 7ac37dd653699842d2e959f8e773f20dba75024e Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Wed, 12 Apr 2023 12:28:20 -0700 Subject: [PATCH 11/12] Comment update --- .../Templates/TemplateString_DeprecationMessage_Tests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index f126fbcb7e..affa58336f 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -240,7 +240,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: SDL-to-Generation Test // - // These tests ensure that when given double quotes in SDL the generation of Swift code works as + // These tests ensure that when given escaped characters in SDL the generation of Swift code works as // expected from frontend parsing all the way to rendering of attributes, comments andwarnings. // There is a test here for all the places that the GraphQL schema supports the @deprecated // directive. From 5d78fe2a477b1fc816c387345f23d77ff197d01a Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Wed, 12 Apr 2023 12:28:45 -0700 Subject: [PATCH 12/12] Comment update --- .../Templates/TemplateString_DeprecationMessage_Tests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift index affa58336f..e013924a08 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/TemplateString_DeprecationMessage_Tests.swift @@ -241,7 +241,7 @@ final class TemplateString_DeprecationMessage_Tests: XCTestCase { // MARK: SDL-to-Generation Test // // These tests ensure that when given escaped characters in SDL the generation of Swift code works as - // expected from frontend parsing all the way to rendering of attributes, comments andwarnings. + // expected from frontend parsing all the way to rendering of attributes, comments and warnings. // There is a test here for all the places that the GraphQL schema supports the @deprecated // directive.