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

[1/x] Refactor root field builder for deferred fragments #74

Merged
merged 41 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
942ce90
Adds @defer SelectionSetTemplate tests
calvincestari Sep 28, 2023
228fe32
Fix property name casing
calvincestari Sep 28, 2023
55b91a2
Refactor IsDeferred
calvincestari Oct 3, 2023
7aca041
Refactor building deferred inline fragment
calvincestari Oct 4, 2023
be2bb8c
Refactor inlineFragment selection logic
calvincestari Oct 6, 2023
bbb98d4
Build new ScopeCondition for inline fragments
calvincestari Oct 6, 2023
6788869
Add working tests for simple type case
calvincestari Oct 7, 2023
500da11
Remove defer from ScopeDescriptor
calvincestari Oct 9, 2023
c8e083b
Disable field merging for deferred fragments
calvincestari Oct 10, 2023
408ea80
Rename property
calvincestari Oct 11, 2023
eb32997
Add tests for deferred inline fragments
calvincestari Oct 11, 2023
53f936e
Remove selection set template deferred tests
calvincestari Oct 11, 2023
d6de41a
Remove nested fragment defer root field builder tests
calvincestari Oct 11, 2023
abd2964
Match naming
calvincestari Oct 11, 2023
a2e0129
Rename to singular from plural
calvincestari Oct 11, 2023
f15cd2f
Rename file to match type
calvincestari Oct 11, 2023
a15f21a
Skip defer selection set template tests
calvincestari Oct 11, 2023
b294e08
Add convenience defer condition property
calvincestari Oct 12, 2023
979eb78
Add direct selection matcher for deferred inline fragments
calvincestari Oct 12, 2023
ad5e8cc
Remove unneeded matcher
calvincestari Oct 13, 2023
64a88e4
[2/x] Refactor root field builder for deferred named fragments (#89)
calvincestari Oct 16, 2023
97226a0
More contextual parameter name
calvincestari Oct 16, 2023
a20ae7c
Dump defer condition in matcher failure output
calvincestari Oct 16, 2023
a1262e2
Additional named fragment test with mocking support
calvincestari Oct 16, 2023
d671de1
Another named fragment type case test
calvincestari Oct 16, 2023
3df12f2
Condense case logic
calvincestari Oct 16, 2023
49e18c3
Moves constants to the relevant type
calvincestari Oct 17, 2023
4e6e603
Refactored containsDeferredFragment logic
calvincestari Oct 17, 2023
b5c4be2
More inline fragment tests
calvincestari Oct 17, 2023
a95ef00
Removing duplicate DeferCondition type
calvincestari Oct 19, 2023
8b4ee15
Include defer condition in scope condition when merging selections
calvincestari Oct 20, 2023
e49b2e8
Disables deferred fragment merging
calvincestari Oct 22, 2023
5bda10d
Fixes deferred fragment logic for same type case condition
calvincestari Oct 22, 2023
29d404e
Test cleanup
calvincestari Oct 22, 2023
48535e9
Add missing convenience property
calvincestari Oct 22, 2023
50691e1
Test cleanup
calvincestari Oct 22, 2023
d596aa2
Adds nested defer inline fragment test
calvincestari Oct 23, 2023
7d2dd4a
Fix and test scope conditions with both include and defer
calvincestari Oct 23, 2023
614b114
Fix deferred named fragment merging
calvincestari Oct 24, 2023
2aa8c36
Additional tests + cleanup
calvincestari Oct 24, 2023
ae4ce88
Adds inline comment on scope condition behaviour
calvincestari Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tests/ApolloCodegenInternalTestHelpers/IR+Mocking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension IR.Operation {
public static func mock(
definition: CompilationResult.OperationDefinition? = nil,
referencedFragments: OrderedSet<IR.NamedFragment> = [],
hasDeferredFragments: Bool = false
containsDeferredFragment: Bool = false
) -> IR.Operation {
let definition = definition ?? .mock()
return IR.Operation.init(
Expand All @@ -116,7 +116,7 @@ extension IR.Operation {
])
),
referencedFragments: referencedFragments,
hasDeferredFragments: hasDeferredFragments
containsDeferredFragment: containsDeferredFragment
)
}

Expand Down
32 changes: 30 additions & 2 deletions Tests/ApolloCodegenInternalTestHelpers/MockIRSubscripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,25 @@ extension ScopeConditionalSubscriptAccessing {
return self[scope]
}

public subscript(
as typeCase: String? = nil,
deferred deferCondition: CompilationResult.DeferCondition? = nil
) -> IR.SelectionSet? {
guard let scope = self.scopeCondition(
type: typeCase,
conditions: nil,
deferCondition: deferCondition
) else {
return nil
}

return self[scope]
}

private func scopeCondition(
type typeCase: String?,
conditions conditionsResult: IR.InclusionConditions.Result?
conditions conditionsResult: IR.InclusionConditions.Result?,
deferCondition: CompilationResult.DeferCondition? = nil
) -> IR.ScopeCondition? {
let type: GraphQLCompositeType?
if let typeCase = typeCase {
Expand All @@ -70,7 +86,7 @@ extension ScopeConditionalSubscriptAccessing {
conditions = nil
}

return IR.ScopeCondition(type: type, conditions: conditions)
return IR.ScopeCondition(type: type, conditions: conditions, deferCondition: deferCondition)
}

}
Expand Down Expand Up @@ -145,6 +161,18 @@ extension IR.SelectionSet: ScopeConditionalSubscriptAccessing {
public subscript(fragment fragment: String) -> IR.NamedFragmentSpread? {
selections[fragment: fragment]
}

public subscript(
deferredAs label: String,
withVariable variable: String? = nil
) -> IR.SelectionSet? {
let scope = ScopeCondition(
type: self.parentType,
conditions: self.inclusionConditions,
deferCondition: CompilationResult.DeferCondition(label: label, variable: variable)
)
return selections[scope]
}
}

extension IR.SelectionSet.Selections: ScopeConditionalSubscriptAccessing {
Expand Down
Loading
Loading