Skip to content

Commit 752d1e1

Browse files
authored
Merge pull request #54 from OpenDive/graphql
GraphQL Provider implementation
2 parents 672b472 + 44a8d34 commit 752d1e1

191 files changed

Lines changed: 11536 additions & 178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ let package = Package(
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.1.1"),
2020
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21-
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0"),
22+
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0"))
2223
],
2324
targets: [
2425
.target(
@@ -31,7 +32,8 @@ let package = Package(
3132
.product(name: "AnyCodable", package: "AnyCodable"),
3233
.product(name: "Bip39", package: "Bip39.swift"),
3334
.product(name: "web3swift", package: "web3swift"),
34-
.product(name: "JWTDecode", package: "JWTDecode.swift")
35+
.product(name: "JWTDecode", package: "JWTDecode.swift"),
36+
.product(name: "Apollo", package: "apollo-ios")
3537
],
3638
path: "Sources"
3739
),

[email protected]

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

[email protected]

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Marcus Arnett on 1/17/24.
6+
//
7+
8+
import Foundation
9+
10+
extension AnyHashable: ScalarType, OutputTypeConvertible, AnyScalarType {
11+
public init(_jsonValue value: JSONValue) throws {
12+
self = value
13+
}
14+
15+
public static var _asOutputType: ApolloAPI.Selection.Field.OutputType {
16+
.scalar(AnyHashable.self)
17+
}
18+
19+
public var _jsonValue: ApolloAPI.JSONValue {
20+
self
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Marcus Arnett on 1/29/24.
6+
//
7+
8+
import Foundation
9+
10+
extension DateFormatter {
11+
static func unixTimestamp(from dateString: String) -> Int? {
12+
let dateFormatter = DateFormatter()
13+
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
14+
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
15+
guard let date = dateFormatter.date(from: dateString) else {
16+
return nil
17+
}
18+
return Int(date.timeIntervalSince1970 * 1_000)
19+
}
20+
}

Sources/SuiKit/Protocols/Sui/ConnectionProtocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public protocol ConnectionProtocol {
3333
/// Optional URL for a faucet service to obtain tokens.
3434
/// Default is nil, meaning no faucet is configured.
3535
var faucet: String? { get }
36+
37+
var graphql: String? { get }
3638

3739
/// Optional URL for a WebSocket connection.
3840
/// Default is nil, meaning no WebSocket is configured.

Sources/SuiKit/Types/Enums/Errors/SuiError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,7 @@ public enum SuiError: Error, Equatable {
165165

166166
/// The Kiosk Data is invalid.
167167
case invalidKioskData
168+
169+
/// The result for the GraphQL query is missing
170+
case missingGraphQLData
168171
}

Sources/SuiKit/Types/Enums/Objects/ObjectOwner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Foundation
2727
import SwiftyJSON
2828

2929
/// `ObjectOwner` represents the possible types of ownership for objects.
30-
public enum ObjectOwner: KeyProtocol {
30+
public enum ObjectOwner: KeyProtocol, Equatable {
3131
/// Represents an object owned by an address. The associated value is a `String` containing the address.
3232
case addressOwner(String)
3333

Sources/SuiKit/Types/Enums/Objects/RawData.swift

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,57 @@ import SwiftyJSON
3030
///
3131
/// This enum allows for either a `MoveObjectRaw` or `PackageRaw` data type, capturing
3232
/// the raw information for either a Move object or a package object.
33-
public enum RawData {
33+
public enum RawData: Equatable {
3434
/// Represents raw data for a Move object. The associated value is a `MoveObjectRaw` containing the Move object's raw data.
3535
case moveObject(MoveObjectRaw)
3636

3737
/// Represents raw data for a package object. The associated value is a `PackageRaw` containing the package object's raw data.
3838
case packageObject(PackageRaw)
3939

40+
public init(graphql: TryGetPastObjectQuery.Data.Object.AsMoveObject, version: String) {
41+
self = .moveObject(
42+
MoveObjectRaw(
43+
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
44+
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
45+
type: graphql.ifShowBcs!.contents!.type.repr,
46+
version: version
47+
)
48+
)
49+
}
50+
51+
public init(graphql: GetOwnedObjectsQuery.Data.Address.ObjectConnection.Node.AsMoveObject, version: String) {
52+
self = .moveObject(
53+
MoveObjectRaw(
54+
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
55+
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
56+
type: graphql.ifShowBcs!.contents!.type.repr,
57+
version: version
58+
)
59+
)
60+
}
61+
62+
public init(graphql: MultiGetObjectsQuery.Data.ObjectConnection.Node.AsMoveObject, version: String) {
63+
self = .moveObject(
64+
MoveObjectRaw(
65+
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
66+
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
67+
type: graphql.ifShowBcs!.contents!.type.repr,
68+
version: version
69+
)
70+
)
71+
}
72+
73+
public init(graphql: GetObjectQuery.Data.Object.AsMoveObject, version: String) {
74+
self = .moveObject(
75+
MoveObjectRaw(
76+
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
77+
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
78+
type: graphql.ifShowBcs!.contents!.type.repr,
79+
version: version
80+
)
81+
)
82+
}
83+
4084
/// Parses a `JSON` object to determine the type of raw data it contains and returns a corresponding `RawData` instance.
4185
///
4286
/// - Parameters:

0 commit comments

Comments
 (0)