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

Save responses and subscriptions #3

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c31e94e
Updated subscription code
terhechte Mar 23, 2022
a76f261
More changes to make it work
terhechte Mar 23, 2022
b8acb0a
Debugging connection errors
terhechte Mar 23, 2022
1dae892
Additional GraphQL fixes, add NWNetworking support
terhechte Mar 24, 2022
619fd0c
Improved error handling
terhechte Mar 28, 2022
45e44e1
Support for ping
terhechte Mar 29, 2022
c9eaf70
Back to supporting the more modern graphql standard
terhechte Mar 29, 2022
1ed24fc
Improved Error forwarding
terhechte Apr 19, 2022
1463799
Error reporting and save the last query
terhechte Apr 21, 2022
105de6f
Better query name
terhechte Apr 21, 2022
5bbc853
Write out variables as well
terhechte Apr 29, 2022
812716a
Support Extensions for Result and Error
terhechte Jun 13, 2022
41eeaa9
remove noisy logs
terhechte Jun 29, 2022
8c2595f
Merge pull request #1 from unstoppablefi/feature/safer-websockets
bruwozniak Jul 4, 2022
49395e2
Fix to make the project build again
bruwozniak Jul 5, 2022
a86f2f1
Merge pull request #2 from unstoppablefi/fix_build
bruwozniak Jul 5, 2022
850a0c8
When endpoint is not specified, read introspection from stdin
bruwozniak Jul 5, 2022
630bf01
Merge pull request #3 from unstoppablefi/stdin
bruwozniak Jul 5, 2022
566549b
reconnect when back from background
terhechte Jul 22, 2022
040908a
multiple changes to make sure a connection_error or a connection_term…
terhechte Jul 25, 2022
5a2b1e1
if we're pinging the void, restart
terhechte Jul 25, 2022
fbe9a81
don't have multiple ping queues
terhechte Jul 25, 2022
5f688ec
Merge pull request #4 from unstoppablefi/bugfix/unstoppable_socket
terhechte Jul 25, 2022
e8a8b91
enqueue restarts in a serial queue
codifilo Oct 28, 2022
d8c1369
Merge pull request #6 from unstoppablefi/fix/restart-concurrency-crash
codifilo Nov 14, 2022
fce44bf
expose the status code on failure
terhechte Nov 28, 2022
66a2e3d
Merge pull request #7 from unstoppablefi/expose_bad_status
terhechte Nov 28, 2022
c8a339b
the bad resolution of the filename caused queries to be overridden
terhechte Dec 14, 2022
e47e98d
Merge pull request #8 from unstoppablefi/fix_overwriting_queries
terhechte Dec 14, 2022
9d613b9
oops
terhechte Dec 14, 2022
a2f05c5
ooops
terhechte Dec 14, 2022
306e627
save responses and subscriptions
terhechte Dec 16, 2022
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
Prev Previous commit
Next Next commit
Support Extensions for Result and Error
  • Loading branch information
terhechte committed Jun 13, 2022
commit 812716aef5f335374c0b70a6322c55242108841f
6 changes: 3 additions & 3 deletions Sources/SwiftGraphQL/HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private func send<Type, TypeLock>(
} catch let error as HttpError {
return completionHandler(.failure(error))
} catch let error {
return completionHandler(.failure(.decodingError(error)))
return completionHandler(.failure(.decodingError(error, extensions: nil)))
}
}

Expand All @@ -146,8 +146,8 @@ public enum HttpError: Error {
case badpayload
case badstatus
case cancelled
case decodingError(Error)
case graphQLErrors([GraphQLError])
case decodingError(Error, extensions: [String: AnyCodable]?)
case graphQLErrors([GraphQLError], extensions: [String: AnyCodable]?)
}

extension HttpError: Equatable {
Expand Down
12 changes: 9 additions & 3 deletions Sources/SwiftGraphQL/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Foundation
public struct GraphQLResult<Type, TypeLock> {
public let data: Type
public let errors: [GraphQLError]?
public let extensions: [String: AnyCodable]?
}

extension GraphQLResult: Equatable where Type: Equatable, TypeLock: Decodable {}
Expand All @@ -13,18 +14,21 @@ extension GraphQLResult where TypeLock: Decodable {
init(_ response: Data, with selection: Selection<Type, TypeLock?>) throws {
// Decodes the data using provided selection.
var errors: [GraphQLError]? = nil
var extensions: [String: AnyCodable]? = nil
do {
let decoder = JSONDecoder()
let response = try decoder.decode(GraphQLResponse.self, from: response)
errors = response.errors
extensions = response.extensions
self.data = try selection.decode(data: response.data)
self.errors = errors
self.extensions = extensions
} catch let error {
// If we have specific errors, use them
if let errors = errors, !errors.isEmpty {
throw HttpError.graphQLErrors(errors)
throw HttpError.graphQLErrors(errors, extensions: extensions)
} else {
throw HttpError.decodingError(error)
throw HttpError.decodingError(error, extensions: extensions)
}
}
}
Expand All @@ -35,6 +39,7 @@ extension GraphQLResult where TypeLock: Decodable {
let response: GraphQLResponse = try webSocketMessage.decodePayload()
self.data = try selection.decode(data: response.data)
self.errors = response.errors
self.extensions = response.extensions
} catch {
// Catches all errors and turns them into a bad payload SwiftGraphQL error.
throw HttpError.badpayload
Expand All @@ -45,6 +50,7 @@ extension GraphQLResult where TypeLock: Decodable {

struct GraphQLResponse: Decodable {
let data: TypeLock?
let extensions: [String: AnyCodable]?
let errors: [GraphQLError]?
}
}
Expand All @@ -54,7 +60,7 @@ extension GraphQLResult where TypeLock: Decodable {
public struct GraphQLError: Codable, Equatable {
public let message: String
public let locations: [Location]?
// public let path: [String]?
public let extensions: [String: AnyCodable]?

public struct Location: Codable, Equatable {
public let line: Int
Expand Down