Skip to content

Commit 9ea6b05

Browse files
Use shippableCountriesExpanded instead of simpleShippingRulesExpanded
1 parent cff4892 commit 9ea6b05

File tree

10 files changed

+51
-221
lines changed

10 files changed

+51
-221
lines changed

GraphAPI/GraphAPITestMocks/Project+Mock.graphql.swift

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GraphAPI/Sources/Fragments/SimpleShippingRuleLocationFragment.graphql.swift

Lines changed: 0 additions & 43 deletions
This file was deleted.

GraphAPI/Sources/Operations/Queries/ShippableLocationsForProjectQuery.graphql.swift

Lines changed: 41 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GraphAPI/Sources/Schema/SchemaMetadata.graphql.swift

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Kickstarter.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,6 @@
35473547
E1A310212D270C610062646C /* BuildPaymentPlanQueryTestData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildPaymentPlanQueryTestData.swift; sourceTree = "<group>"; };
35483548
E1A310252D2840680062646C /* PledgeOverTimeUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgeOverTimeUseCase.swift; sourceTree = "<group>"; };
35493549
E1A310272D2845CB0062646C /* PledgeOverTimeUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgeOverTimeUseCaseTests.swift; sourceTree = "<group>"; };
3550-
E1A530372EDE2F97000D8CC3 /* SimpleShippingRuleLocationFragment.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = SimpleShippingRuleLocationFragment.graphql; sourceTree = "<group>"; };
35513550
E1B33F502E538157008903BA /* GraphAPI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = GraphAPI; sourceTree = "<group>"; };
35523551
E1B813C62BC851CB00DF33CF /* FetchMyBackedProjectsQueryRequestForTests.graphql_test */ = {isa = PBXFileReference; lastKnownFileType = text; path = FetchMyBackedProjectsQueryRequestForTests.graphql_test; sourceTree = "<group>"; };
35533552
E1B813C82BC851E100DF33CF /* FetchMyBackedProjectsQuery.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FetchMyBackedProjectsQuery.json; sourceTree = "<group>"; };
@@ -7677,7 +7676,6 @@
76777676
E190EB322E29944E006A6DB6 /* ProjectPamphletMainCellPropertiesFragment.graphql */,
76787677
E190EB332E29944E006A6DB6 /* RewardFragment.graphql */,
76797678
E190EB342E29944E006A6DB6 /* ShippingRuleFragment.graphql */,
7680-
E1A530372EDE2F97000D8CC3 /* SimpleShippingRuleLocationFragment.graphql */,
76817679
E190EB352E29944E006A6DB6 /* UserEmailFragment.graphql */,
76827680
E190EB362E29944E006A6DB6 /* UserFeaturesFragment.graphql */,
76837681
E190EB372E29944E006A6DB6 /* UserFragment.graphql */,

KsApi/models/graphql/adapters/Location+LocationFragment.swift

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@ extension Location {
1616
)
1717
}
1818

19-
static func location(from rule: GraphAPI.SimpleShippingRuleLocationFragment?) -> Location? {
20-
guard let rule = rule,
21-
let name = rule.locationName,
22-
let graphId = rule.locationId,
23-
let id = decompose(id: graphId)
24-
else {
25-
return nil
26-
}
27-
28-
return Location(
29-
country: rule.country,
30-
displayableName: name,
31-
id: id,
32-
localizedName: name,
33-
name: name
34-
)
35-
}
36-
3719
public static func locations(from data: GraphAPI.DefaultLocationsQuery.Data) -> [Location] {
3820
guard let nodes = data.locations?.nodes else {
3921
return []
@@ -57,37 +39,9 @@ extension Location {
5739
}
5840

5941
public static func locations(from data: GraphAPI.ShippableLocationsForProjectQuery.Data) -> [Location] {
60-
let allLocations = allLocations(from: data)
61-
return self.flattenAndDedupeLocations(from: allLocations)
62-
}
63-
64-
static func allLocations(from data: GraphAPI.ShippableLocationsForProjectQuery.Data) -> [[Location]] {
65-
return data.project?.rewards?.nodes?.compactMap { reward in
66-
reward?.simpleShippingRulesExpanded.compactMap { rule -> Location? in
67-
Location.location(from: rule?.fragments.simpleShippingRuleLocationFragment)
68-
}
42+
return data.project?.shippableCountriesExpanded.compactMap { node in
43+
let fragment = node.fragments.locationFragment
44+
return KsApi.Location.location(from: fragment)
6945
} ?? []
7046
}
71-
72-
static func flattenAndDedupeLocations(from rewardLocations: [[Location]]) -> [Location] {
73-
// Flatten the list of locations from all rewards into one list
74-
let locations = rewardLocations.reduce(into: []) { partialResults, location in
75-
partialResults += location
76-
}
77-
78-
// ...and then filter out any duplicates
79-
var filteredLocations: [Location] = []
80-
var seenLocationIds = Set<Int>()
81-
82-
for location in locations {
83-
if seenLocationIds.contains(location.id) {
84-
continue
85-
}
86-
87-
filteredLocations.append(location)
88-
seenLocationIds.insert(location.id)
89-
}
90-
91-
return filteredLocations
92-
}
9347
}

KsApi/models/graphql/adapters/Location+LocationFragmentTests.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,4 @@ final class Location_LocationFragmentTests: XCTestCase {
1515

1616
XCTAssertNotNil(Location.location(from: locationFragment))
1717
}
18-
19-
func testSimpleShippingRule() {
20-
let simpleShippingRuleFragment = GraphAPI.SimpleShippingRuleLocationFragment(
21-
locationId: "TG9jYXRpb24tMjM0MjQ3NzU=",
22-
locationName: "Canada",
23-
country: "CA"
24-
)
25-
26-
XCTAssertNotNil(Location.location(from: simpleShippingRuleFragment))
27-
}
28-
29-
func testFlattenAndDedupeLocations() {
30-
let allRewardLocations: [[Location]] = [
31-
[Location.usa],
32-
[Location.usa, Location.australia],
33-
[Location.australia, Location.canada]
34-
]
35-
36-
let flattened = Location.flattenAndDedupeLocations(from: allRewardLocations)
37-
XCTAssertEqual(flattened, [Location.usa, Location.australia, Location.canada])
38-
}
3918
}

graphql/fragments/SimpleShippingRuleLocationFragment.graphql

Lines changed: 0 additions & 5 deletions
This file was deleted.

graphql/graphql-schema.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
query ShippableLocationsForProject($id: Int!) {
22
project(pid: $id) {
3-
rewards {
4-
nodes {
5-
simpleShippingRulesExpanded {
6-
...SimpleShippingRuleLocationFragment
7-
}
8-
}
3+
shippableCountriesExpanded {
4+
...LocationFragment
95
}
106
}
117
}

0 commit comments

Comments
 (0)