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

Remove unused type #1437

Merged
merged 3 commits into from
Oct 5, 2020
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: 0 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
9BD681402406F31A000874CB /* FlexibleDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD6813F2406F31A000874CB /* FlexibleDecoder.swift */; };
9BD681422406F516000874CB /* ASTParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD681412406F516000874CB /* ASTParsingTests.swift */; };
9BDE43D122C6655300FD7C7F /* Cancellable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43D022C6655200FD7C7F /* Cancellable.swift */; };
9BDE43DD22C6705300FD7C7F /* GraphQLHTTPResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */; };
9BDE43DF22C6708600FD7C7F /* GraphQLHTTPRequestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */; };
9BDF201323FDC37600153E2B /* GitHubAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BDF200C23FDC37600153E2B /* GitHubAPI.h */; settings = {ATTRIBUTES = (Public, ); }; };
9BDF201423FDC37600153E2B /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BDF201123FDC37600153E2B /* API.swift */; };
Expand Down Expand Up @@ -678,7 +677,6 @@
9BD6813F2406F31A000874CB /* FlexibleDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexibleDecoder.swift; sourceTree = "<group>"; };
9BD681412406F516000874CB /* ASTParsingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASTParsingTests.swift; sourceTree = "<group>"; };
9BDE43D022C6655200FD7C7F /* Cancellable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cancellable.swift; sourceTree = "<group>"; };
9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPResponseError.swift; sourceTree = "<group>"; };
9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPRequestError.swift; sourceTree = "<group>"; };
9BDF200C23FDC37600153E2B /* GitHubAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GitHubAPI.h; sourceTree = "<group>"; };
9BDF200D23FDC37600153E2B /* operationIdsPath.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = operationIdsPath.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1567,7 +1565,6 @@
9BF1A95022CA6E71005292C2 /* GraphQLGETTransformer.swift */,
5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */,
9BDE43DE22C6708600FD7C7F /* GraphQLHTTPRequestError.swift */,
9BDE43DC22C6705300FD7C7F /* GraphQLHTTPResponseError.swift */,
9FF90A5B1DDDEB100034C3B6 /* GraphQLResponse.swift */,
C377CCAA22D7992E00572E03 /* MultipartFormData.swift */,
9F69FFA81D42855900E000B1 /* NetworkTransport.swift */,
Expand Down Expand Up @@ -2471,7 +2468,6 @@
54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */,
9FC9A9C51E2D6CE70023C4D5 /* GraphQLSelectionSet.swift in Sources */,
9B260C01245A059700562176 /* CodableParsingInterceptor.swift in Sources */,
9BDE43DD22C6705300FD7C7F /* GraphQLHTTPResponseError.swift in Sources */,
9B554CC4247DC29A002F452A /* TaskData.swift in Sources */,
9B9BBAF524DB4F890021C30F /* AutomaticPersistedQueryInterceptor.swift in Sources */,
9BA1244A22D8A8EA00BF1D24 /* JSONSerialization+Sorting.swift in Sources */,
Expand Down
75 changes: 0 additions & 75 deletions Sources/Apollo/GraphQLHTTPResponseError.swift

This file was deleted.

1 change: 1 addition & 0 deletions Sources/Apollo/TaskData.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation

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

public let rawCompletion: URLSessionClient.RawCompletion?
Expand Down
6 changes: 1 addition & 5 deletions Tests/ApolloCacheDependentTests/StarWarsServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,7 @@ class StarWarsServerTests: XCTestCase, CacheTesting {

completionHandler(data)
case .failure(let error):
if let responseError = error as? GraphQLHTTPResponseError {
XCTFail("Response error: \(responseError.bodyDescription)")
} else {
XCTFail("Unexpected error: \(error)")
}
XCTFail("Unexpected error: \(error)")
}
}

Expand Down
111 changes: 58 additions & 53 deletions Tests/ApolloTests/ErrorGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@

import Apollo
import XCTest
import StarWarsAPI

class ErrorGenerationTests: XCTestCase {

func testLocalizedStringFromErrorResponse() throws {
private func checkExtensions(on error: GraphQLError,
expectedDict: [String: Any?],
file: StaticString = #filePath,
line: UInt = #line) {
XCTAssertEqual(error.extensions?.count,
expectedDict.count,
file: file,
line: line)

for (key, expectedValue) in expectedDict {
let actualValue = error.extensions?[key] as? String
let stringExpectedValue = expectedValue as? String
XCTAssertEqual(actualValue,
stringExpectedValue,
"Value for key \(key) did not match expected value \(String(describing: stringExpectedValue)), it was \(String(describing: actualValue))",
file: file,
line: line)
}
}

func testSingleErrorParsing() throws {
let json = """
{
"data": {
"hero": null
},
"errors": [
{
"message": "Invalid client auth token.",
Expand All @@ -25,24 +49,30 @@ class ErrorGenerationTests: XCTestCase {
}
"""

let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
statusCode: 403,
httpVersion: nil,
headerFields: nil)!

let data = try XCTUnwrap(json.data(using: .utf8),
"Couldn't create json data")
let deserialized = try JSONSerializationFormat.deserialize(data: data)
let jsonObject = try XCTUnwrap(deserialized as? JSONObject)
let response = GraphQLResponse(operation: HeroNameQuery(), body: jsonObject)
let result = try response.parseResultFast()
XCTAssertNotNil(result.data)
XCTAssertNil(result.data?.hero)

let httpResponseError = GraphQLHTTPResponseError(body: data,
response: response,
kind: .errorResponse)
XCTAssertEqual(httpResponseError.graphQLErrors?.count, 1)
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response: Invalid client auth token.")
XCTAssertEqual(result.errors?.count, 1)
let error = try XCTUnwrap(result.errors?.first)
XCTAssertEqual(error.message, "Invalid client auth token.")

self.checkExtensions(on: error, expectedDict: [
"code": "INTERNAL_SERVER_ERROR"
])
}

func testLocalizedStringFromErrorResponseWithMultipleErrors() throws {
let json = """
{
"data": {
"hero": null
},
"errors": [
{
"message": "Invalid client auth token.",
Expand All @@ -60,52 +90,27 @@ class ErrorGenerationTests: XCTestCase {
}
"""

let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
statusCode: 403,
httpVersion: nil,
headerFields: nil)!

let data = try XCTUnwrap(json.data(using: .utf8),
"Couldn't create json data")
let deserialized = try JSONSerializationFormat.deserialize(data: data)
let jsonObject = try XCTUnwrap(deserialized as? JSONObject)
let response = GraphQLResponse(operation: HeroNameQuery(), body: jsonObject)
let result = try response.parseResultFast()
XCTAssertNotNil(result.data)
XCTAssertNil(result.data?.hero)

let httpResponseError = GraphQLHTTPResponseError(body: data,
response: response,
kind: .errorResponse)
XCTAssertEqual(httpResponseError.graphQLErrors?.count, 2)
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response: Invalid client auth token.\nServer is having a sad.")
}

func testLocalizedStringFromPlaintextResponse() throws {
let text = "The server is having a sad."

let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
statusCode: 500,
httpVersion: nil,
headerFields: nil)!

let data = try XCTUnwrap(text.data(using: .utf8),
"Couldn't create text data")

let errors = try XCTUnwrap(result.errors)

let httpResponseError = GraphQLHTTPResponseError(body: data,
response: response,
kind: .errorResponse)
XCTAssertEqual(errors.count, 2)
XCTAssertEqual(errors.map { $0.message }, [
"Invalid client auth token.",
"Server is having a sad.",
])

XCTAssertNil(httpResponseError.graphQLErrors)
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response (500 internal server error): The server is having a sad.")
}

func testLocalizedStringFromNullDataResponse() {
let response = HTTPURLResponse(url: URL(string: "https://www.fake.com")!,
statusCode: 500,
httpVersion: nil,
headerFields: nil)!

let httpResponseError = GraphQLHTTPResponseError(body: nil,
response: response,
kind: .errorResponse)

XCTAssertNil(httpResponseError.graphQLErrors)
XCTAssertEqual(httpResponseError.localizedDescription, "Received error response (500 internal server error): [Empty response body]")
for error in errors {
self.checkExtensions(on: error, expectedDict: [
"code": "INTERNAL_SERVER_ERROR"
])
}
}
}