From 1aed6ad2075f3a7e039e43a03623b265e0409795 Mon Sep 17 00:00:00 2001 From: Anthony Miller Date: Thu, 16 Sep 2021 17:43:25 -0700 Subject: [PATCH] Fix execution of Boolean Condition fields --- Sources/Apollo/GraphQLExecutor.swift | 12 +++++++-- Sources/ApolloTestSupport/MockOperation.swift | 26 +++++-------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Sources/Apollo/GraphQLExecutor.swift b/Sources/Apollo/GraphQLExecutor.swift index bbe9bea0dd..fc2019622e 100644 --- a/Sources/Apollo/GraphQLExecutor.swift +++ b/Sources/Apollo/GraphQLExecutor.swift @@ -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, diff --git a/Sources/ApolloTestSupport/MockOperation.swift b/Sources/ApolloTestSupport/MockOperation.swift index 628bde3d3c..580da4cf8a 100644 --- a/Sources/ApolloTestSupport/MockOperation.swift +++ b/Sources/ApolloTestSupport/MockOperation.swift @@ -70,32 +70,20 @@ open class AbstractMockSelectionSet: AnySelectionSet { self.data = data } - public subscript(dynamicMember key: String) -> T? { - data.data[key] as? T + public subscript(dynamicMember key: String) -> T? { + data[key] } - public subscript(dynamicMember key: String) -> T? { - data.data[key] as? T + public subscript(dynamicMember key: String) -> [T]? { + data[key] } - public subscript(dynamicMember key: String) -> [T]? { - data.data[key] as? [T] - } - - public subscript(dynamicMember key: String) -> [T]? { - data.data[key] as? [T] - } - - public subscript(dynamicMember key: String) -> [[T]]? { - data.data[key] as? [[T]] - } - - public subscript(dynamicMember key: String) -> [[T]]? { - data.data[key] as? [[T]] + public subscript(dynamicMember key: String) -> [[T]]? { + data[key] } public subscript(dynamicMember key: String) -> T? { - data.data[key] as? T + data[key] } }