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

tests: Add merged selection deferred test case #153

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions Tests/ApolloCodegenTests/CodeGenIR/IRRootFieldBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6702,6 +6702,88 @@ class IRRootFieldBuilderTests: XCTestCase {
))
}

func test__deferredFragments__givenDeferredNamedFragmentWithMatchingDeferredTypeCase_buildsInlineFragmentWithMergedFragmentSelection() async throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}

interface Animal {
id: String
species: String
}

type Pet implements Animal {
id: String
species: String
}
"""

document = """
query TestOperation($a: Boolean) {
allAnimals {
__typename
...AnimalFragment @defer(label: "root")
... on Pet {
id
}
}
}

fragment AnimalFragment on Animal {
species
}
"""

// when
try await buildSubjectRootField()

// then
let Interface_Animal = try XCTUnwrap(schema[interface: "Animal"])
let Fragment_AnimalFragment = try XCTUnwrap(ir.compilationResult[fragment: "AnimalFragment"])
let Object_Pet = try XCTUnwrap(schema[object: "Pet"])

let allAnimals = self.subject[field: "allAnimals"]
let animalFragment = try await ir.builtFragmentStorage
.getFragmentIfBuilt(named: "AnimalFragment").xctUnwrapped()
let allAnimals_asPet = allAnimals?[as: "Pet"]

expect(allAnimals?.selectionSet).to(shallowlyMatch(
SelectionSetMatcher(
parentType: Interface_Animal,
directSelections: [
.inlineFragment(parentType: Object_Pet),
.deferred(Fragment_AnimalFragment, label: "root"),
]
)
))

expect(animalFragment.rootField.selectionSet).to(shallowlyMatch(
SelectionSetMatcher(
parentType: Interface_Animal,
directSelections: [
.field("species", type: .string()),
]
)
))

expect(allAnimals_asPet).to(shallowlyMatch(
SelectionSetMatcher(
parentType: Object_Pet,
directSelections: [
.field("id", type: .string()),
],
mergedSelections: [
.deferred(Fragment_AnimalFragment, label: "root"),
],
mergedSources: [
try .mock(allAnimals),
]
)
))
}

// MARK: Deferred Fragments - Named Fragments (with @include/@skip)

func test__deferredFragments__givenBothDeferAndIncludeDirectives_onSameNamedFragment_buildsNestedDeferredNamedFragment() async throws {
Expand Down
2 changes: 1 addition & 1 deletion apollo-ios/Sources/Apollo/GraphQLResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension GraphQLResult {

private func convert(value: Any) -> Any {
var val: Any = value
if let value = value as? ApolloAPI.DataDict {
if let value = value as? DataDict {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BobaFetters I had to make this change to get the cocoapods codegen test configuration project to pass. The change makes sense but how have other PRs been building, including the one that included this change originally?

Copy link
Member Author

@calvincestari calvincestari Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the Codegen Test Configurations job was skipped in that PR. We'll need to revise the logic that turns that on/off.

val = value._data
} else if let value = value as? CustomScalarType {
val = value._jsonValue
Expand Down
Loading