Skip to content

Commit

Permalink
Fix execution of Boolean Condition fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev committed Sep 21, 2021
1 parent ed20344 commit 1aed6ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
12 changes: 10 additions & 2 deletions Sources/Apollo/GraphQLExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,18 @@ final class GraphQLExecutor {
groupedFields.append(field: field, withInfo: info)

case let .booleanCondition(booleanCondition):
guard let value = info.variables?[booleanCondition.variableName] else {
#warning("""
TODO: Make sure there are unit tests for this.
1) Include with variable true
2) Include with variable false
3) Skip with variable true
4) Skip with variable false
""")
guard case let .scalar(boolValue as Bool) =
info.variables?[booleanCondition.variableName] else {
throw GraphQLError("Variable \(booleanCondition.variableName) was not provided.")
}
if value as? Bool == !booleanCondition.inverted {
if boolValue == !booleanCondition.inverted {
try groupFields(booleanCondition.selections,
forRuntimeType: runtimeType,
into: &groupedFields,
Expand Down
26 changes: 7 additions & 19 deletions Sources/ApolloTestSupport/MockOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,20 @@ open class AbstractMockSelectionSet: AnySelectionSet {
self.data = data
}

public subscript<T: ScalarType>(dynamicMember key: String) -> T? {
data.data[key] as? T
public subscript<T: AnyScalarType>(dynamicMember key: String) -> T? {
data[key]
}

public subscript<T: CustomScalarType>(dynamicMember key: String) -> T? {
data.data[key] as? T
public subscript<T: AnyScalarType>(dynamicMember key: String) -> [T]? {
data[key]
}

public subscript<T: ScalarType>(dynamicMember key: String) -> [T]? {
data.data[key] as? [T]
}

public subscript<T: CustomScalarType>(dynamicMember key: String) -> [T]? {
data.data[key] as? [T]
}

public subscript<T: ScalarType>(dynamicMember key: String) -> [[T]]? {
data.data[key] as? [[T]]
}

public subscript<T: CustomScalarType>(dynamicMember key: String) -> [[T]]? {
data.data[key] as? [[T]]
public subscript<T: AnyScalarType>(dynamicMember key: String) -> [[T]]? {
data[key]
}

public subscript<T: MockSelectionSet>(dynamicMember key: String) -> T? {
data.data[key] as? T
data[key]
}
}

Expand Down

0 comments on commit 1aed6ad

Please sign in to comment.