Skip to content

Commit

Permalink
Merge branch 'main' into release/1.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift
  • Loading branch information
calvincestari committed Jun 14, 2023
2 parents 1ec00c8 + f64927c commit 9f48589
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 57 deletions.
52 changes: 40 additions & 12 deletions Sources/ApolloCodegenLib/Templates/SelectionSetTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -483,29 +483,27 @@ struct SelectionSetTemplate {
private func InitializerFulfilledFragments(
_ selectionSet: IR.SelectionSet
) -> TemplateString {
var fulfilledFragments: [String] = ["Self"]
var fulfilledFragments: OrderedSet<String> = []

var next = selectionSet.scopePath.last.value.scopePath.head
while next.next != nil {
defer { next = next.next.unsafelyUnwrapped }
var currentNode = Optional(selectionSet.scopePath.last.value.scopePath.head)
while let node = currentNode {
defer { currentNode = node.next }

let selectionSetName = SelectionSetNameGenerator.generatedSelectionSetName(
for: selectionSet,
to: next,
to: node,
format: .fullyQualified,
pluralizer: config.pluralizer
)

fulfilledFragments.append(selectionSetName)
}

let allFragments = IteratorSequence(selectionSet.selections.makeFragmentIterator())
for fragment in allFragments {
if let conditions = fragment.inclusionConditions,
!selectionSet.typeInfo.scope.matches(conditions) {
continue
}
fulfilledFragments.append(fragment.definition.name.asFragmentName)
for source in selectionSet.selections.merged.mergedSources {
fulfilledFragments
.append(contentsOf: source.generatedSelectionSetNamesOfFullfilledFragments(
pluralizer: config.pluralizer
))
}

return """
Expand Down Expand Up @@ -693,6 +691,34 @@ fileprivate extension IR.MergedSelections.MergedSource {
return selectionSetNameComponents.joined(separator: ".")
}

func generatedSelectionSetNamesOfFullfilledFragments(
pluralizer: Pluralizer
) -> [String] {
let entityRootNameInFragment = SelectionSetNameGenerator
.generatedSelectionSetName(
for: self,
to: typeInfo.scopePath.last.value.scopePath.head,
format: .fullyQualified,
pluralizer: pluralizer
)

var fulfilledFragments: [String] = [entityRootNameInFragment]

var selectionSetNameComponents: [String] = [entityRootNameInFragment]

var mergedFragmentEntityConditionPathNode = typeInfo.scopePath.last.value.scopePath.head
while let node = mergedFragmentEntityConditionPathNode.next {
defer {
mergedFragmentEntityConditionPathNode = node
}
selectionSetNameComponents.append(
SelectionSetNameGenerator.ConditionPath.path(for: node)
)
fulfilledFragments.append(selectionSetNameComponents.joined(separator: "."))
}
return fulfilledFragments
}

}

fileprivate struct SelectionSetNameGenerator {
Expand Down Expand Up @@ -722,11 +748,13 @@ fileprivate struct SelectionSetNameGenerator {

static func generatedSelectionSetName(
for mergedSource: IR.MergedSelections.MergedSource,
to toNode: LinkedList<IR.ScopeCondition>.Node? = nil,
format: Format,
pluralizer: Pluralizer
) -> String {
generatedSelectionSetName(
for: mergedSource.typeInfo,
to: toNode,
format: format,
pluralizer: pluralizer
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class FragmentTemplateTests: XCTestCase {
"species": species,
],
fulfilledFragments: [
ObjectIdentifier(Self.self)
ObjectIdentifier(TestFragment.self)
]
))
}
Expand Down Expand Up @@ -460,7 +460,7 @@ class FragmentTemplateTests: XCTestCase {
"species": species,
],
fulfilledFragments: [
ObjectIdentifier(Self.self)
ObjectIdentifier(TestFragment.self)
]
))
}
Expand Down Expand Up @@ -567,7 +567,7 @@ class FragmentTemplateTests: XCTestCase {
"species": species,
],
fulfilledFragments: [
ObjectIdentifier(Self.self)
ObjectIdentifier(TestFragment.self)
]
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class OperationDefinitionTemplateTests: XCTestCase {
"species": species,
],
fulfilledFragments: [
ObjectIdentifier(Self.self)
ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self)
]
))
}
Expand Down Expand Up @@ -381,7 +381,7 @@ class OperationDefinitionTemplateTests: XCTestCase {
"species": species,
],
fulfilledFragments: [
ObjectIdentifier(Self.self)
ObjectIdentifier(TestOperationQuery.Data.AllAnimal.self)
]
))
}
Expand Down
Loading

0 comments on commit 9f48589

Please sign in to comment.