Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen EntitySelectionTree + MergedSelections Refactor + Perf Improvments #152

Merged
merged 38 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67555a5
Refactor EntitySelectionTree to merge in references to merged named f…
AnthonyMDev Oct 31, 2023
d6a31e5
WIP
AnthonyMDev Oct 31, 2023
5770081
WIP: Make merged selections builder
AnthonyMDev Oct 31, 2023
a59d374
Refactoring SelectionSet model and initializer usages
AnthonyMDev Oct 31, 2023
754b9e9
Add build function to MergedSelections.Builder
AnthonyMDev Oct 31, 2023
991d4b4
Merge branch 'main' into entity-selection-tree-merge-fragment-ref
AnthonyMDev Nov 14, 2023
ff9a98c
Refactoring SelectionSetTemplate to use new IR structure
AnthonyMDev Nov 14, 2023
92e31fa
WIP: Refactor to use typealias for referenced Selection Sets
AnthonyMDev Nov 15, 2023
86086c0
TEMP: Comment out type conflict validation
AnthonyMDev Nov 15, 2023
2968927
Rename ComputedSelections -> ComputedSelectionSet
AnthonyMDev Nov 15, 2023
d593207
Make TemplateString take an optional TemplateString
AnthonyMDev Nov 17, 2023
9591649
WIP: Creating IRTestWrappers
AnthonyMDev Nov 17, 2023
f3ee3d5
Refactor EntityStorage to attach to definition
AnthonyMDev Nov 20, 2023
7a02ee6
Refactor MergedSelections.Builder to ComputedSelectionSet.Builder
AnthonyMDev Nov 20, 2023
67d6027
Finish implementing IRTestWrapper functionality
AnthonyMDev Nov 20, 2023
f283dc0
WIP: Refactoring tests
AnthonyMDev Nov 20, 2023
fadf702
More test fixes
AnthonyMDev Nov 20, 2023
ec5c318
Add debug description to test wrappers
AnthonyMDev Nov 21, 2023
15a7f06
Fix fragment merging bug in entity selection tree
AnthonyMDev Nov 21, 2023
f7511ff
Fix root field builder scope condition bug
AnthonyMDev Nov 21, 2023
7672da3
More test clean up
AnthonyMDev Nov 21, 2023
31710c2
Merge remote-tracking branch 'origin/main' into entity-selection-tree…
AnthonyMDev Nov 28, 2023
8b3a140
Rename render(childEntity:)
AnthonyMDev Nov 29, 2023
0ce8731
WIP: Updating tests
AnthonyMDev Nov 29, 2023
add3d37
Skip broken validation tests temporarialy
AnthonyMDev Dec 6, 2023
3123fd7
WIP: IRTestWrapper improvements
AnthonyMDev Dec 6, 2023
9baa44b
Merge remote-tracking branch 'origin/main' into entity-selection-tree…
AnthonyMDev Dec 6, 2023
e1db84f
Cleanup
AnthonyMDev Dec 6, 2023
c40f212
Fix nested Selection Set typealias for direct parent
AnthonyMDev Dec 8, 2023
1b7526c
Merge branch 'main' into entity-selection-tree-merge-fragment-ref
AnthonyMDev Dec 8, 2023
e6c622c
Merge branch 'main' into entity-selection-tree-merge-fragment-ref
AnthonyMDev Dec 16, 2023
6337310
Merge remote-tracking branch 'origin/main' into entity-selection-tree…
AnthonyMDev Dec 18, 2023
dfcda81
Updated documentation
AnthonyMDev Dec 18, 2023
e2d5c96
Codegen Vaildation - Handle Non Fatal Errors (#202)
AnthonyMDev Dec 20, 2023
b51bb5a
Fix SwiftScripts (remove CCN)
AnthonyMDev Dec 20, 2023
1ff40a4
Fix bug adding extra whitespace
AnthonyMDev Dec 20, 2023
f2113fd
Re-run SwiftScripts Codegen
AnthonyMDev Dec 20, 2023
4afc607
Merge branch 'main' into entity-selection-tree-merge-fragment-ref
AnthonyMDev Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ extension IRBuilder {
return .mock(compilationResult: compilationResult)
}

public static func mock(
public static func mock(
compilationResult: CompilationResult
) -> IRBuilder {
return IRBuilder(compilationResult: compilationResult)
return IRBuilder(compilationResult: compilationResult)
}

}
Expand All @@ -63,24 +63,31 @@ extension IR.NamedFragment {
location: .init(source: .namedFragment(definition), fieldPath: nil),
rootTypePath: LinkedList(type)
)
let typeInfo = SelectionSet.TypeInfo(
entity: rootEntity,
scopePath: [
.descriptor(
forType: type,
inclusionConditions: nil,
givenAllTypesInSchema: .init([type], schemaRootTypes: .mock())
)
]
)
let rootEntityField = IR.EntityField.init(
rootField,
inclusionConditions: nil,
selectionSet: .init(
entity: rootEntity,
scopePath: LinkedList(
.descriptor(
forType: type,
inclusionConditions: nil,
givenAllTypesInSchema: .init([type], schemaRootTypes: .mock())
))))
typeInfo: typeInfo,
selections: DirectSelections()
)
)

return IR.NamedFragment(
definition: definition,
rootField: rootEntityField,
referencedFragments: [],
containsDeferredFragment: false,
entities: [rootEntity.location: rootEntity]
entityStorage: .init(rootEntity: rootEntity),
containsDeferredFragment: false
)
}
}
Expand All @@ -93,23 +100,30 @@ extension IR.Operation {
containsDeferredFragment: Bool = false
) -> IR.Operation {
let definition = definition ?? .mock()
let typeInfo = SelectionSet.TypeInfo(
entity: .init(
location: .init(source: .operation(definition), fieldPath: nil),
rootTypePath: [.mock()]
),
scopePath: [.descriptor(
forType: .mock(),
inclusionConditions: nil,
givenAllTypesInSchema: .init([], schemaRootTypes: .mock()))
]
)
let rootField = IR.EntityField(
.mock(),
inclusionConditions: nil,
selectionSet: .init(
typeInfo: typeInfo,
selections: DirectSelections()
)
)
return IR.Operation.init(
definition: definition,
rootField: .init(
.mock(),
inclusionConditions: nil,
selectionSet: .init(
entity: .init(
location: .init(source: .operation(definition), fieldPath: nil),
rootTypePath: [.mock()]
),
scopePath: [.descriptor(
forType: .mock(),
inclusionConditions: nil,
givenAllTypesInSchema: .init([], schemaRootTypes: .mock()))
])
),
rootField: rootField,
referencedFragments: referencedFragments,
entityStorage: .init(rootEntity: rootField.entity),
containsDeferredFragment: containsDeferredFragment
)
}
Expand Down
65 changes: 65 additions & 0 deletions Tests/ApolloCodegenInternalTestHelpers/IRBuilderTestWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@testable import ApolloCodegenLib
@testable import IR
import GraphQLCompiler
import OrderedCollections
import Utilities

/// This class wraps an `IRBuilder` for so that the built definitions are wrapped in
/// `IRTestWrapper` instances.
///
/// These wrappers are used to make testing `ComputedSelectionSet` easier.
@dynamicMemberLookup
public class IRBuilderTestWrapper {
public let irBuilder: IRBuilder

public private(set) lazy var builtFragmentStorage : BuiltFragmentStorage = {
BuiltFragmentStorage(self.irBuilder.builtFragmentStorage)
}()

public init(_ irBuilder: IRBuilder) {
self.irBuilder = irBuilder
}

public func build(
operation operationDefinition: CompilationResult.OperationDefinition
) async -> IRTestWrapper<IR.Operation> {
let operation = await irBuilder.build(operation: operationDefinition)
return IRTestWrapper(
irObject: operation,
computedSelectionSetCache: .init(entityStorage: operation.entityStorage)
)
}

public func build(
fragment fragmentDefinition: CompilationResult.FragmentDefinition
) async -> IRTestWrapper<IR.NamedFragment> {
let fragment = await irBuilder.build(fragment: fragmentDefinition)
return IRTestWrapper(
irObject: fragment,
computedSelectionSetCache: .init(entityStorage: fragment.entityStorage)
)
}

public subscript<T>(dynamicMember keyPath: KeyPath<IRBuilder, T>) -> T {
irBuilder[keyPath: keyPath]
}

public class BuiltFragmentStorage {
private var wrappedStorage: IRBuilder.BuiltFragmentStorage

fileprivate init(_ wrappedStorage: IRBuilder.BuiltFragmentStorage) {
self.wrappedStorage = wrappedStorage
}

public func getFragmentIfBuilt(named name: String) async -> IRTestWrapper<NamedFragment>? {
guard let fragment = await wrappedStorage.getFragmentIfBuilt(named: name) else {
return nil
}

return IRTestWrapper(
irObject: fragment,
computedSelectionSetCache: .init(entityStorage: fragment.entityStorage)
)
}
}
}