From 88689900a092015d90cc5feea72cc4117925ef8b Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 10 Jan 2023 16:20:28 -0800 Subject: [PATCH 1/4] Allow _ as field accessor name --- .../Templates/RenderingHelpers/String+SwiftNameEscaping.swift | 3 ++- .../Frontend/DocumentParsingAndValidationTests.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift b/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift index 2ceeaa1b9a..98c059a1f4 100644 --- a/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift +++ b/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift @@ -38,7 +38,7 @@ extension String { enum SwiftKeywords { static let DisallowedFieldNames: Set = [ - "__data", "fragments", "_" + "__data", "fragments" ] static let DisallowedInputParameterNames: Set = [ @@ -133,6 +133,7 @@ enum SwiftKeywords { "throws", "true", "try", + "_", ] fileprivate static let InputParameterNamesToEscape: Set = FieldAccessorNamesToEscape diff --git a/Tests/ApolloCodegenTests/Frontend/DocumentParsingAndValidationTests.swift b/Tests/ApolloCodegenTests/Frontend/DocumentParsingAndValidationTests.swift index b9867645a0..11637b112e 100644 --- a/Tests/ApolloCodegenTests/Frontend/DocumentParsingAndValidationTests.swift +++ b/Tests/ApolloCodegenTests/Frontend/DocumentParsingAndValidationTests.swift @@ -191,7 +191,7 @@ class DocumentParsingAndValidationTests: XCTestCase { } func test__validateDocument__givenFieldNameDisallowed_throwsError() throws { - let disallowedFields = ["__data", "fragments", "Fragments", "_"] + let disallowedFields = ["__data", "fragments", "Fragments"] for field in disallowedFields { let schema = try codegenFrontend.loadSchema( From bceb2f1b838fa5a2c738a5c706b597ddd2754b09 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 10 Jan 2023 16:20:54 -0800 Subject: [PATCH 2/4] Allows _ as selection set name to be suffixed --- .../Templates/RenderingHelpers/String+SwiftNameEscaping.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift b/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift index 98c059a1f4..91a5d04a85 100644 --- a/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift +++ b/Sources/ApolloCodegenLib/Templates/RenderingHelpers/String+SwiftNameEscaping.swift @@ -66,7 +66,8 @@ enum SwiftKeywords { "Float", "Double", "ID", - "Type" + "Type", + "_", ] /// When an interface or union named "Actor" is used as the type for a field on a test mock, From 5e713b4729c6d57e104a8dce1c02e166da29e454 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 10 Jan 2023 20:55:58 -0800 Subject: [PATCH 3/4] Adds entity field test --- .../Templates/SelectionSet/SelectionSetTemplateTests.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift index 2dc7ad72d2..b8354ea6fe 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplateTests.swift @@ -975,6 +975,7 @@ class SelectionSetTemplateTests: XCTestCase { protocol: Animal! type: Animal! species: String! + _: Animal! } """ @@ -1029,6 +1030,9 @@ class SelectionSetTemplateTests: XCTestCase { type { species } + _ { + species + } } } """ @@ -1051,6 +1055,7 @@ class SelectionSetTemplateTests: XCTestCase { .field("any", Any_SelectionSet.self), .field("protocol", Protocol_SelectionSet.self), .field("type", Type_SelectionSet.self), + .field("_", __SelectionSet.self), ] } """ From d03579b8a9f751ff2889c416aef79c7325096616 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Tue, 10 Jan 2023 21:03:32 -0800 Subject: [PATCH 4/4] Adds test for input object field accessor --- .../Templates/InputObjectTemplateTests.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift index 99f28119eb..0b760602d5 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/InputObjectTemplateTests.swift @@ -1494,7 +1494,12 @@ class InputObjectTemplateTests: XCTestCase { "try", type: .nonNull(.string()), defaultValue: nil - ) + ), + GraphQLInputField.mock( + "_", + type: .nonNull(.string()), + defaultValue: nil + ), ] buildSubject(fields: fields, config: .mock(schemaName: "TestSchema")) @@ -1550,7 +1555,8 @@ class InputObjectTemplateTests: XCTestCase { `super`: String, `throws`: String, `true`: String, - `try`: String + `try`: String, + `_`: String ) { __data = InputDict([ "associatedtype": `associatedtype`, @@ -1602,7 +1608,8 @@ class InputObjectTemplateTests: XCTestCase { "super": `super`, "throws": `throws`, "true": `true`, - "try": `try` + "try": `try`, + "_": `_` ]) } @@ -1855,6 +1862,11 @@ class InputObjectTemplateTests: XCTestCase { get { __data["`try`"] } set { __data["`try`"] = newValue } } + + public var `_`: String { + get { __data["`_`"] } + set { __data["`_`"] = newValue } + } """ // when