Skip to content

Commit

Permalink
Refactor to reduce duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari committed Jan 28, 2025
1 parent 2884a78 commit c21c683
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import GraphQLCompiler

extension GraphQLCompositeType {
var isIdentifiable: Bool {
switch(self) {
case let interface as GraphQLInterfaceType:
return interface.keyFields == ["id"]

case let object as GraphQLObjectType:
return object.keyFields == ["id"]

default:
return false
}
}
}
13 changes: 2 additions & 11 deletions apollo-ios-codegen/Sources/IR/IR+ComputedSelectionSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ public struct ComputedSelectionSet {
guard direct?.fields["id"] != nil || merged.fields["id"] != nil else {
return false
}
if let type = typeInfo.parentType as? GraphQLObjectType,
type.keyFields == ["id"] {
return true
}

if let type = typeInfo.parentType as? GraphQLInterfaceType,
type.keyFields == ["id"] {
return true
}

return false

return typeInfo.parentType.isIdentifiable
}

// MARK: Dynamic Member Subscript
Expand Down
9 changes: 1 addition & 8 deletions apollo-ios-codegen/Sources/IR/IR+NamedFragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public class NamedFragment: Definition, Hashable, CustomDebugStringConvertible {
return field.name == "id"
}) else { return false }

switch(type) {
case let interface as GraphQLInterfaceType:
return interface.keyFields == ["id"]
case let object as GraphQLObjectType:
return object.keyFields == ["id"]
default:
return false
}
return type.isIdentifiable
}

init(
Expand Down

0 comments on commit c21c683

Please sign in to comment.