-
Notifications
You must be signed in to change notification settings - Fork 749
GraphManager/Engine Headers + minor WebSocket cleanup #858
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81b8001
add helpers to get typical information for a bundle
designatednerd 052b14b
make sure `NetworkTransport` is class-bound
designatednerd 6bb80cf
add client name and version properties for sending to the server
designatednerd 896bbeb
update http network transport request with headers
designatednerd 1b51799
Pull related classes out of `WebSocketTransport` file and into their …
designatednerd 3f4a5ca
better client/version setup for websocket and split network transports.
designatednerd 4e62438
update tests for updated requirements
designatednerd 0472f96
add splitnetwork transport tests
designatednerd 5cf9a54
centralize header because typos, add tests for http transport to make…
designatednerd 6f7f9b7
use `request.addValue` instead of harder method
designatednerd e0ca1b3
alphabetize files
designatednerd 1e71b44
add/finish adding moar docs
designatednerd 981ff46
that can just be private now
designatednerd 6aa8c62
fix gunked up test alignment
designatednerd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // | ||
| // Bundle+Helpers.swift | ||
| // Apollo | ||
| // | ||
| // Created by Ellen Shapiro on 10/23/19. | ||
| // Copyright © 2019 Apollo GraphQL. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| extension Bundle { | ||
|
|
||
| /// Type-safe getter for info dictionary key objects | ||
| /// | ||
| /// - Parameter key: The key to try to grab an object for | ||
| /// - Returns: The object of the desired type, or nil if it is not present or of the incorrect type. | ||
| func bundleValue<T>(forKey key: String) -> T? { | ||
| return object(forInfoDictionaryKey: key) as? T | ||
| } | ||
|
|
||
| /// The bundle identifier of this bundle, or nil if not present. | ||
| var bundleIdentifier: String? { | ||
| return self.bundleValue(forKey: String(kCFBundleIdentifierKey)) | ||
| } | ||
|
|
||
| /// The build number of this bundle (kCFBundleVersion) as a string, or nil if not present. | ||
| var buildNumber: String? { | ||
| return self.bundleValue(forKey: String(kCFBundleVersionKey)) | ||
| } | ||
|
|
||
| /// The short version string for this bundle, or nil if not present. | ||
| var shortVersion: String? { | ||
| return self.bundleValue(forKey: "CFBundleShortVersionString") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import Starscream | ||
| import Foundation | ||
|
|
||
| // MARK: - Client protocol | ||
|
|
||
| /// Protocol allowing alternative implementations of web sockets beyond `ApolloWebSocket`. Extends `Starscream`'s `WebSocketClient` protocol. | ||
| public protocol ApolloWebSocketClient: WebSocketClient { | ||
|
|
||
| /// Required initializer | ||
| /// | ||
| /// - Parameter request: The URLRequest to use on connection. | ||
| /// - Parameter protocols: The supported protocols | ||
| init(request: URLRequest, protocols: [String]?) | ||
|
|
||
| /// The URLRequest used on connection. | ||
| var request: URLRequest { get set } | ||
| } | ||
|
|
||
| // MARK: - WebSocket | ||
|
|
||
| /// Included implementation of an `ApolloWebSocketClient`, based on `Starscream`'s `WebSocket`. | ||
| public class ApolloWebSocket: WebSocket, ApolloWebSocketClient { | ||
| required public convenience init(request: URLRequest, protocols: [String]? = nil) { | ||
| self.init(request: request, protocols: protocols, stream: FoundationStream()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #if !COCOAPODS | ||
| import Apollo | ||
| #endif | ||
| import Foundation | ||
|
|
||
| final class OperationMessage { | ||
| enum Types : String { | ||
| case connectionInit = "connection_init" // Client -> Server | ||
| case connectionTerminate = "connection_terminate" // Client -> Server | ||
| case start = "start" // Client -> Server | ||
| case stop = "stop" // Client -> Server | ||
|
|
||
| case connectionAck = "connection_ack" // Server -> Client | ||
| case connectionError = "connection_error" // Server -> Client | ||
| case connectionKeepAlive = "ka" // Server -> Client | ||
| case data = "data" // Server -> Client | ||
| case error = "error" // Server -> Client | ||
| case complete = "complete" // Server -> Client | ||
| } | ||
|
|
||
| let serializationFormat = JSONSerializationFormat.self | ||
| var message: GraphQLMap = [:] | ||
| var serialized: String? | ||
|
|
||
| var rawMessage : String? { | ||
| let serialized = try! serializationFormat.serialize(value: message) | ||
| if let str = String(data: serialized, encoding: .utf8) { | ||
| return str | ||
| } else { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| init(payload: GraphQLMap? = nil, id: String? = nil, type: Types = .start) { | ||
| if let payload = payload { | ||
| message += ["payload": payload] | ||
| } | ||
| if let id = id { | ||
| message += ["id": id] | ||
| } | ||
| message += ["type": type.rawValue] | ||
| } | ||
|
|
||
| init(serialized: String) { | ||
| self.serialized = serialized | ||
| } | ||
|
|
||
| func parse(handler: (_ type: String?, _ id: String?, _ payload: JSONObject?, _ error: Error?) -> Void) { | ||
| guard let serialized = self.serialized else { | ||
| handler(nil, nil, nil, WebSocketError(payload: nil, error: nil, kind: .serializedMessageError)) | ||
| return | ||
| } | ||
|
|
||
| guard let data = self.serialized?.data(using: (.utf8) ) else { | ||
| handler(nil, nil, nil, WebSocketError(payload: nil, error: nil, kind: .unprocessedMessage(serialized))) | ||
| return | ||
| } | ||
|
|
||
| var type : String? | ||
| var id : String? | ||
| var payload : JSONObject? | ||
|
|
||
| do { | ||
| let json = try JSONSerializationFormat.deserialize(data: data ) as? JSONObject | ||
|
|
||
| id = json?["id"] as? String | ||
| type = json?["type"] as? String | ||
| payload = json?["payload"] as? JSONObject | ||
|
|
||
| handler(type,id,payload,nil) | ||
| } | ||
| catch { | ||
| handler(type, id, payload, WebSocketError(payload: payload, error: error, kind: .unprocessedMessage(serialized))) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually decided against this on my end as I'm increasing the build number on each build (based of number of commits) and it makes the "Clients" view in Apollo Engine a bit noisy for the non-public environments/variants. YMMV of course and it's always configurable anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah in my past experience when I've had build number auto-incrementing it's actually been quite helpful in being able to identify exactly where I broke something 😄. And as you said, it's configurable, so if people don't like the default, they can always adjust.