From 16111934e18144cd0d8cae865ac023efea171786 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Wed, 18 Sep 2024 10:29:27 -0700 Subject: [PATCH] fix: Removes local cache mutation type condition setter (#485) --- ...onSetTemplate_LocalCacheMutation_Tests.swift | 17 +++++++---------- .../Templates/SelectionSetTemplate.swift | 11 +---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift index 1a1430a81..50d22d7d1 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_LocalCacheMutation_Tests.swift @@ -139,7 +139,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { let actual = subject.test_render(childEntity: allAnimals.computed) // then - expect(actual).to(equalLineByLine(expected, atLine: 18, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } // MARK: - Accessor Tests @@ -263,7 +263,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { expect(actual).to(equalLineByLine(expected, atLine: 12, ignoringExtraLines: true)) } - func test__render_inlineFragmentAccessors__rendersAccessorWithGetterAndSetter() async throws { + func test__render_inlineFragmentAccessors__rendersAccessorWithGetterOnly() async throws { // given schemaSDL = """ type Query { @@ -290,10 +290,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { """ let expected = """ - public var asDog: AsDog? { - get { _asInlineFragment() } - set { if let newData = newValue?.__data._data { __data._data = newData }} - } + public var asDog: AsDog? { _asInlineFragment() } """ // when @@ -391,7 +388,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { let actual = subject.test_render(childEntity: allAnimals.computed) // then - expect(actual).to(equalLineByLine(expected, atLine: 21, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 18, ignoringExtraLines: true)) } // MARK: - Casing Tests @@ -435,7 +432,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { public struct AsDog: Myschema.MutableInlineFragment { """ - expect(actual).to(equalLineByLine(expected, atLine: 18, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } func test__casingForMutableInlineFragment__givenUppercasedSchemaName_generatesUppercasedNamespace() async throws { @@ -477,7 +474,7 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { public struct AsDog: MYSCHEMA.MutableInlineFragment { """ - expect(actual).to(equalLineByLine(expected, atLine: 18, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } func test__casingForMutableInlineFragment__givenCapitalizedSchemaName_generatesCapitalizedNamespace() async throws { @@ -519,6 +516,6 @@ class SelectionSetTemplate_LocalCacheMutationTests: XCTestCase { public struct AsDog: MySchema.MutableInlineFragment { """ - expect(actual).to(equalLineByLine(expected, atLine: 18, ignoringExtraLines: true)) + expect(actual).to(equalLineByLine(expected, atLine: 15, ignoringExtraLines: true)) } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift index fd91d5104..aed458cb4 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift @@ -478,16 +478,7 @@ struct SelectionSetTemplate { let typeName = inlineFragment.renderedTypeName return """ - \(renderAccessControl())var \(typeName.firstLowercased): \(typeName)? {\ - \(if: isMutable, - """ - - get { _asInlineFragment() } - set { if let newData = newValue?.__data._data { __data._data = newData }} - } - """, - else: " _asInlineFragment() }" - ) + \(renderAccessControl())var \(typeName.firstLowercased): \(typeName)? { _asInlineFragment() } """ }