Skip to content

Commit 448717a

Browse files
Merge pull request #1437 from apollographql/rm/unused_type
Remove unused type
2 parents 2aa36bf + 9d4bffc commit 448717a

5 files changed

Lines changed: 60 additions & 137 deletions

File tree

Apollo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@
169169
9BD681402406F31A000874CB /* FlexibleDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD6813F2406F31A000874CB /* FlexibleDecoder.swift */; };
170170
9BD681422406F516000874CB /* ASTParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD681412406F516000874CB /* ASTParsingTests.swift */; };
171171
9BDE43D122C6655300FD7C7F /* Cancellable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43D022C6655200FD7C7F /* Cancellable.swift */; };
172-
9BDE43DD22C6705300FD7C7F /* GraphQLHTTPResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */; };
173172
9BDE43DF22C6708600FD7C7F /* GraphQLHTTPRequestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */; };
174173
9BDF201323FDC37600153E2B /* GitHubAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BDF200C23FDC37600153E2B /* GitHubAPI.h */; settings = {ATTRIBUTES = (Public, ); }; };
175174
9BDF201423FDC37600153E2B /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF201123FDC37600153E2B /* API.swift */; };
@@ -678,7 +677,6 @@
678677
9BD6813F2406F31A000874CB /* FlexibleDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexibleDecoder.swift; sourceTree = "<group>"; };
679678
9BD681412406F516000874CB /* ASTParsingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASTParsingTests.swift; sourceTree = "<group>"; };
680679
9BDE43D022C6655200FD7C7F /* Cancellable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cancellable.swift; sourceTree = "<group>"; };
681-
9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPResponseError.swift; sourceTree = "<group>"; };
682680
9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPRequestError.swift; sourceTree = "<group>"; };
683681
9BDF200C23FDC37600153E2B /* GitHubAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GitHubAPI.h; sourceTree = "<group>"; };
684682
9BDF200D23FDC37600153E2B /* operationIdsPath.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = operationIdsPath.json; sourceTree = "<group>"; };
@@ -1567,7 +1565,6 @@
15671565
9BF1A95022CA6E71005292C2 /* GraphQLGETTransformer.swift */,
15681566
5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */,
15691567
9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */,
1570-
9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */,
15711568
9FF90A5B1DDDEB100034C3B6 /* GraphQLResponse.swift */,
15721569
C377CCAA22D7992E00572E03 /* MultipartFormData.swift */,
15731570
9F69FFA81D42855900E000B1 /* NetworkTransport.swift */,
@@ -2471,7 +2468,6 @@
24712468
54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */,
24722469
9FC9A9C51E2D6CE70023C4D5 /* GraphQLSelectionSet.swift in Sources */,
24732470
9B260C01245A059700562176 /* CodableParsingInterceptor.swift in Sources */,
2474-
9BDE43DD22C6705300FD7C7F /* GraphQLHTTPResponseError.swift in Sources */,
24752471
9B554CC4247DC29A002F452A /* TaskData.swift in Sources */,
24762472
9B9BBAF524DB4F890021C30F /* AutomaticPersistedQueryInterceptor.swift in Sources */,
24772473
9BA1244A22D8A8EA00BF1D24 /* JSONSerialization+Sorting.swift in Sources */,

Sources/Apollo/GraphQLHTTPResponseError.swift

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

Sources/Apollo/TaskData.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// A wrapper for data about a particular task handled by `URLSessionClient`
34
public class TaskData {
45

56
public let rawCompletion: URLSessionClient.RawCompletion?

Tests/ApolloCacheDependentTests/StarWarsServerTests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,7 @@ class StarWarsServerTests: XCTestCase, CacheTesting {
356356

357357
completionHandler(data)
358358
case .failure(let error):
359-
if let responseError = error as? GraphQLHTTPResponseError {
360-
XCTFail("Response error: \(responseError.bodyDescription)")
361-
} else {
362-
XCTFail("Unexpected error: \(error)")
363-
}
359+
XCTFail("Unexpected error: \(error)")
364360
}
365361
}
366362

Tests/ApolloTests/ErrorGenerationTests.swift

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,36 @@
88

99
import Apollo
1010
import XCTest
11+
import StarWarsAPI
1112

1213
class ErrorGenerationTests: XCTestCase {
1314

14-
func testLocalizedStringFromErrorResponse() throws {
15+
private func checkExtensions(on error: GraphQLError,
16+
expectedDict: [String: Any?],
17+
file: StaticString = #filePath,
18+
line: UInt = #line) {
19+
XCTAssertEqual(error.extensions?.count,
20+
expectedDict.count,
21+
file: file,
22+
line: line)
23+
24+
for (key, expectedValue) in expectedDict {
25+
let actualValue = error.extensions?[key] as? String
26+
let stringExpectedValue = expectedValue as? String
27+
XCTAssertEqual(actualValue,
28+
stringExpectedValue,
29+
"Value for key \(key) did not match expected value \(String(describing: stringExpectedValue)), it was \(String(describing: actualValue))",
30+
file: file,
31+
line: line)
32+
}
33+
}
34+
35+
func testSingleErrorParsing() throws {
1536
let json = """
1637
{
38+
"data": {
39+
"hero": null
40+
},
1741
"errors": [
1842
{
1943
"message": "Invalid client auth token.",
@@ -25,24 +49,30 @@ class ErrorGenerationTests: XCTestCase {
2549
}
2650
"""
2751

28-
let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
29-
statusCode: 403,
30-
httpVersion: nil,
31-
headerFields: nil)!
32-
3352
let data = try XCTUnwrap(json.data(using: .utf8),
3453
"Couldn't create json data")
54+
let deserialized = try JSONSerializationFormat.deserialize(data: data)
55+
let jsonObject = try XCTUnwrap(deserialized as? JSONObject)
56+
let response = GraphQLResponse(operation: HeroNameQuery(), body: jsonObject)
57+
let result = try response.parseResultFast()
58+
XCTAssertNotNil(result.data)
59+
XCTAssertNil(result.data?.hero)
3560

36-
let httpResponseError = GraphQLHTTPResponseError(body: data,
37-
response: response,
38-
kind: .errorResponse)
39-
XCTAssertEqual(httpResponseError.graphQLErrors?.count, 1)
40-
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response: Invalid client auth token.")
61+
XCTAssertEqual(result.errors?.count, 1)
62+
let error = try XCTUnwrap(result.errors?.first)
63+
XCTAssertEqual(error.message, "Invalid client auth token.")
64+
65+
self.checkExtensions(on: error, expectedDict: [
66+
"code": "INTERNAL_SERVER_ERROR"
67+
])
4168
}
4269

4370
func testLocalizedStringFromErrorResponseWithMultipleErrors() throws {
4471
let json = """
4572
{
73+
"data": {
74+
"hero": null
75+
},
4676
"errors": [
4777
{
4878
"message": "Invalid client auth token.",
@@ -60,52 +90,27 @@ class ErrorGenerationTests: XCTestCase {
6090
}
6191
"""
6292

63-
let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
64-
statusCode: 403,
65-
httpVersion: nil,
66-
headerFields: nil)!
67-
6893
let data = try XCTUnwrap(json.data(using: .utf8),
6994
"Couldn't create json data")
95+
let deserialized = try JSONSerializationFormat.deserialize(data: data)
96+
let jsonObject = try XCTUnwrap(deserialized as? JSONObject)
97+
let response = GraphQLResponse(operation: HeroNameQuery(), body: jsonObject)
98+
let result = try response.parseResultFast()
99+
XCTAssertNotNil(result.data)
100+
XCTAssertNil(result.data?.hero)
70101

71-
let httpResponseError = GraphQLHTTPResponseError(body: data,
72-
response: response,
73-
kind: .errorResponse)
74-
XCTAssertEqual(httpResponseError.graphQLErrors?.count, 2)
75-
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response: Invalid client auth token.\nServer is having a sad.")
76-
}
77-
78-
func testLocalizedStringFromPlaintextResponse() throws {
79-
let text = "The server is having a sad."
80-
81-
let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
82-
statusCode: 500,
83-
httpVersion: nil,
84-
headerFields: nil)!
85-
86-
let data = try XCTUnwrap(text.data(using: .utf8),
87-
"Couldn't create text data")
88-
102+
let errors = try XCTUnwrap(result.errors)
89103

90-
let httpResponseError = GraphQLHTTPResponseError(body: data,
91-
response: response,
92-
kind: .errorResponse)
104+
XCTAssertEqual(errors.count, 2)
105+
XCTAssertEqual(errors.map { $0.message }, [
106+
"Invalid client auth token.",
107+
"Server is having a sad.",
108+
])
93109

94-
XCTAssertNil(httpResponseError.graphQLErrors)
95-
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response (500 internal server error): The server is having a sad.")
96-
}
97-
98-
func testLocalizedStringFromNullDataResponse() {
99-
let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
100-
statusCode: 500,
101-
httpVersion: nil,
102-
headerFields: nil)!
103-
104-
let httpResponseError = GraphQLHTTPResponseError(body: nil,
105-
response: response,
106-
kind: .errorResponse)
107-
108-
XCTAssertNil(httpResponseError.graphQLErrors)
109-
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response (500 internal server error): [Empty response body]")
110+
for error in errors {
111+
self.checkExtensions(on: error, expectedDict: [
112+
"code": "INTERNAL_SERVER_ERROR"
113+
])
114+
}
110115
}
111116
}

0 commit comments

Comments
 (0)