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

Expose GraphQLResultError Path String #2361

Merged
merged 3 commits into from Jul 12, 2022
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
4 changes: 4 additions & 0 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
DED46035261CEA660086EF63 /* ApolloTestSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F8A95781EC0FC1200304A2D /* ApolloTestSupport.framework */; };
DED46042261CEA8A0086EF63 /* TestServerURLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED45C172615308E0086EF63 /* TestServerURLs.swift */; };
DED46051261CEAD20086EF63 /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
E6057F8B287D7E24007D84EC /* ResponsePathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6057F8A287D7E24007D84EC /* ResponsePathTests.swift */; };
E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E616B6D026C3335600DB049E /* ExecutionTests.swift */; };
E61DD76526D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */; };
E63C03DF27BDDC3D00D675C6 /* SubscriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63C03DD27BDDC3400D675C6 /* SubscriptionTests.swift */; };
Expand Down Expand Up @@ -846,6 +847,7 @@
DED45FB1261CDE7D0086EF63 /* Apollo-PerformanceTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-PerformanceTestPlan.xctestplan"; sourceTree = "<group>"; };
DED45FB2261CDE980086EF63 /* Apollo-CITestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CITestPlan.xctestplan"; sourceTree = "<group>"; };
DED45FB3261CDEC60086EF63 /* Apollo-CodegenTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CodegenTestPlan.xctestplan"; sourceTree = "<group>"; };
E6057F8A287D7E24007D84EC /* ResponsePathTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponsePathTests.swift; sourceTree = "<group>"; };
E616B6D026C3335600DB049E /* ExecutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecutionTests.swift; sourceTree = "<group>"; };
E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLiteDotSwiftDatabaseBehaviorTests.swift; sourceTree = "<group>"; };
E63C03D327BDB55900D675C6 /* subscription.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = subscription.graphql; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1578,6 +1580,7 @@
E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */,
9B9BBB1A24DB75E60021C30F /* UploadRequestTests.swift */,
5BB2C0222380836100774170 /* VersionNumberTests.swift */,
E6057F8A287D7E24007D84EC /* ResponsePathTests.swift */,
);
path = ApolloTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2810,6 +2813,7 @@
9B64F6762354D219002D1BB5 /* URL+QueryDict.swift in Sources */,
9B2B66F42513FAFE00B53ABF /* CancellationHandlingInterceptor.swift in Sources */,
9BC139A624EDCAD900876D29 /* BlindRetryingTestInterceptor.swift in Sources */,
E6057F8B287D7E24007D84EC /* ResponsePathTests.swift in Sources */,
9B96500A24BE62B7003C29C0 /* RequestChainTests.swift in Sources */,
DED45DEA261B96B70086EF63 /* WatchQueryTests.swift in Sources */,
DED45E30261B972C0086EF63 /* CachePersistenceTests.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Apollo/GraphQLExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct GraphQLResolveInfo {
public struct GraphQLResultError: Error, LocalizedError {
let path: ResponsePath

public var pathString: String { path.description }

/// The error that occurred during parsing.
public let underlying: Error

Expand Down
38 changes: 38 additions & 0 deletions Tests/ApolloTests/ResponsePathTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import XCTest
@testable import Apollo
import Nimble

class ResponsePathTests: XCTestCase {

func test__initializer__givenArray_shouldRespectKeyCasing() {
let subject: ResponsePath = ["first", "Second", "Third"]

expect(subject.joined).to(equal("first.Second.Third"))
}

func test__joined__givenArray_shouldReturnJoinedKeysInOrder() {
let subject: ResponsePath = ["first", "second", "third"]

expect(subject.joined).to(equal("first.second.third"))
}

func test__joined__whenAppendKey_shouldIncludeAppendedKeyLast() {
var subject: ResponsePath = ["first", "second", "third"]
subject.append("fourth")

expect(subject.joined).to(equal("first.second.third.fourth"))
}

func test__joined__whenAddKey_shouldIncludeAddedKeyLast() {
let paths: ResponsePath = ["first", "second"]
let subject = paths + "third"

expect(subject.joined).to(equal("first.second.third"))
}

func test__description__givenArray_shouldEqualJoined() {
let subject: ResponsePath = ["first", "second", "third"]

expect(subject.description).to(equal(subject.joined))
}
}