From 2f7737977b453cff2bb9d9174fabd278c66f2051 Mon Sep 17 00:00:00 2001 From: Anthony Miller Date: Thu, 25 May 2023 14:05:17 -0700 Subject: [PATCH] Fix Fulfilled fragment references not being fully qualified Additional error noted in closed ticket 2949 https://github.com/apollographql/apollo-ios/issues/2949#issuecomment-1544221268 --- .../Templates/SelectionSetTemplate.swift | 12 +++------ ...ectionSetTemplate_Initializers_Tests.swift | 26 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift index a50b005a91..422499b7b8 100644 --- a/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift +++ b/Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift @@ -484,13 +484,10 @@ struct SelectionSetTemplate { while next.next != nil { defer { next = next.next.unsafelyUnwrapped } - let selectionSetName = SelectionSetNameGenerator.generatedSelectionSetName( - from: selectionSet.scopePath.head, - to: next, - withFieldPath: selectionSet.entity.fieldPath.head, - removingFirst: selectionSet.scopePath.head.value.type.isRootFieldType, - pluralizer: config.pluralizer - ) + let selectionSetName = fullyQualifiedGeneratedSelectionSetName( + for: selectionSet.typeInfo, + to: next + ) fulfilledFragments.append(selectionSetName) } @@ -546,7 +543,6 @@ struct SelectionSetTemplate { from: typeInfo.scopePath.head, to: toNode, withFieldPath: typeInfo.entity.fieldPath.head, - removingFirst: false, pluralizer: config.pluralizer ) } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift index 6aff8375f5..1250b0bdfd 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/SelectionSet/SelectionSetTemplate_Initializers_Tests.swift @@ -365,8 +365,8 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), - ObjectIdentifier(AllAnimal.AsAnimalUnion.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.AsAnimalUnion.self) ] )) } @@ -430,8 +430,8 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), - ObjectIdentifier(AllAnimal.AsPet.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.AsPet.self) ] )) } @@ -1116,7 +1116,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self) ] )) } @@ -1378,7 +1378,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), ObjectIdentifier(AnimalDetails.self) ] )) @@ -1455,7 +1455,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), ObjectIdentifier(AnimalDetails.self) ] )) @@ -1574,7 +1574,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self) ] )) } @@ -1633,7 +1633,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self) ] )) } @@ -1694,8 +1694,8 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), - ObjectIdentifier(AllAnimal.IfA.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.IfA.self) ] )) } @@ -1756,7 +1756,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.IfA.Friend.self) + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.IfA.Friend.self) ] )) } @@ -1834,7 +1834,7 @@ class SelectionSetTemplate_Initializers_Tests: XCTestCase { ], fulfilledFragments: [ ObjectIdentifier(Self.self), - ObjectIdentifier(AllAnimal.self), + ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self), ObjectIdentifier(AnimalDetails.self) ] ))