Skip to content

Commit 9f6e31b

Browse files
Marcus ArnettMarcus Arnett
authored andcommitted
Implement lint for GraphQL core function objects
1 parent 775e5c4 commit 9f6e31b

6 files changed

Lines changed: 47 additions & 11 deletions

File tree

Sources/SuiKit/Types/Structs/GraphQL/GraphQLClient.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
//
2-
// File.swift
3-
//
2+
// GraphQLClient.swift
3+
// SuiKit
44
//
5-
// Created by Marcus Arnett on 12/19/23.
5+
// Copyright (c) 2023 OpenDive
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
624
//
725

826
import Foundation
927
import Apollo
1028
import ApolloAPI
1129

12-
public struct GraphQLClient {
13-
public static func fetchQuery<T: GraphQLQuery>(client: ApolloClient, query: T) async throws -> GraphQLResult<T.Data> {
30+
/// A wrapper struct for being able to query data from the GraphQL node.
31+
internal struct GraphQLClient {
32+
/// Given the Apollo client and a query that conforms to the GraphQLQuery type, fetch data from that endpoint and return the conformed object representing the data.
33+
/// - Parameters:
34+
/// - client: The Apollo client used for sending the query out.
35+
/// - query: The query itself containing information such as user inputs parameters, the endpoint itself, and various other metadata for making the GraphQL client functional.
36+
/// - Returns: A GraphQLResult object of either T.Data type, or throws an error.
37+
internal static func fetchQuery<T: GraphQLQuery>(client: ApolloClient, query: T) async throws -> GraphQLResult<T.Data> {
1438
return try await withCheckedThrowingContinuation { (con: CheckedContinuation<GraphQLResult<T.Data>, Error>) in
1539
let _ = client.fetch(query: query) { result in
1640
switch result {

Sources/SuiKit/Types/Structs/Provider/GraphQLSuiProvider.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SuiProvider.swift
2+
// GraphQLSuiProvider.swift
33
// SuiKit
44
//
55
// Copyright (c) 2023 OpenDive
@@ -235,6 +235,7 @@ public struct GraphQLSuiProvider {
235235
return "\(result.data!.checkpoint!.sequenceNumber)"
236236
}
237237

238+
// TODO: Implement function when write becomes available
238239
/// Retrieves the loaded child objects associated with a given digest from the Sui blockchain.
239240
/// - Parameter digest: The digest string of the parent object.
240241
/// - Throws: A `SuiError` if an error occurs during the JSON RPC call or if there are errors in the response data.
@@ -407,6 +408,7 @@ public struct GraphQLSuiProvider {
407408
return BigInt(data.checkpoint!.networkTotalTransactions!)
408409
}
409410

411+
// TODO: Implement function when write becomes available
410412
/// Return the transaction response object.
411413
/// - Parameters:
412414
/// - digest: A `String` representing the digest of the queried transaction.
@@ -454,6 +456,7 @@ public struct GraphQLSuiProvider {
454456
}
455457
}
456458

459+
// TODO: Implement function when write becomes available
457460
/// Returns an ordered list of transaction responses The method will throw an error if the input contains any duplicate or the input size exceeds `QUERY_MAX_RESULT_LIMIT`.
458461
/// - Parameters:
459462
/// - digests: An array of `String` representing the digests of the transaction blocks to be retrieved.
@@ -499,6 +502,7 @@ public struct GraphQLSuiProvider {
499502
return .versionFound(SuiObjectData(graphql: data.object!, showBcs: options?.showBcs ?? false))
500503
}
501504

505+
// TODO: Implement function when write becomes available
502506
/// Return the object information for a specified version.
503507
///
504508
/// There is no software-level guarantee/SLA that objects with past versions can be retrieved by this API, even if the object and version exists/existed. The result may vary across nodes depending on their pruning policies.
@@ -618,6 +622,7 @@ public struct GraphQLSuiProvider {
618622
)
619623
}
620624

625+
// TODO: Implement function when write becomes available
621626
/// Return the committee information for the asked `epoch`.
622627
/// - Parameter epoch: he epoch of interest. If None, default to the latest epoch.
623628
/// - Returns: A `CommitteeInfo` object containing the information of the committee for the specified epoch.
@@ -628,6 +633,7 @@ public struct GraphQLSuiProvider {
628633
throw SuiError.notImplemented
629634
}
630635

636+
// TODO: Implement function when write becomes available
631637
/// Return the dynamic field object information for a specified object.
632638
/// - Parameters:
633639
/// - parentId: The ID of the queried parent object.
@@ -641,6 +647,7 @@ public struct GraphQLSuiProvider {
641647
throw SuiError.notImplemented
642648
}
643649

650+
// TODO: Implement function when write becomes available
644651
/// Return the dynamic field object information for a specified object.
645652
/// - Parameters:
646653
/// - parentId: The ID of the queried parent object.
@@ -674,6 +681,7 @@ public struct GraphQLSuiProvider {
674681
throw SuiError.notImplemented
675682
}
676683

684+
// TODO: Implement function when write becomes available
677685
/// Return the latest SUI system state object on-chain.
678686
/// - Returns: A `JSON` object containing the information of the latest Sui system state.
679687
/// - Throws: `SuiError.rpcError` if there are errors in the JSON RPC response.
@@ -739,6 +747,7 @@ public struct GraphQLSuiProvider {
739747
return BigInt(data.epoch!.referenceGasPrice!, radix: 10)!
740748
}
741749

750+
// TODO: Implement function when write becomes available
742751
/// Retrieves the staking information for a given owner.
743752
/// - Parameter owner: The address of the owner whose staking information is to be retrieved.
744753
/// - Returns: An array of `DelegatedStake` objects representing the staking information.
@@ -749,6 +758,7 @@ public struct GraphQLSuiProvider {
749758
throw SuiError.notImplemented
750759
}
751760

761+
// TODO: Implement function when write becomes available
752762
/// Retrieves the staking information for given stake IDs.
753763
///
754764
/// If a Stake was withdrawn its status will be Unstaked.
@@ -844,6 +854,7 @@ public struct GraphQLSuiProvider {
844854
throw SuiError.notImplemented
845855
}
846856

857+
// TODO: Implement function when write becomes available
847858
/// Resolves a nameservice address to its corresponding account address.
848859
/// - Parameter name: A string representing the nameservice address to resolve.
849860
/// - Returns: An `AccountAddress` representing the resolved account address.
@@ -853,7 +864,6 @@ public struct GraphQLSuiProvider {
853864
}
854865

855866
// TODO: Implement Resolve Name Service Names
856-
857867
/// Waits for a transaction to be processed and retrieves the transaction block.
858868
/// - Parameters:
859869
/// - tx: A string representing the transaction hash.
@@ -867,6 +877,7 @@ public struct GraphQLSuiProvider {
867877
throw SuiError.notImplemented
868878
}
869879

880+
// TODO: Implement function when write becomes available
870881
/// Checks if a transaction block is valid by ensuring it has a timestamp.
871882
/// - Parameters:
872883
/// - tx: A string representing the transaction hash.

Sources/SuiKit/Types/Structs/Provider/Responses/DisplayFieldsResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct DisplayFieldsResponse: Equatable {
3636
/// An optional instance of `ObjectResponseError` representing any error that occurred while generating the response.
3737
/// This will be `nil` if there is no error to report.
3838
public var error: ObjectResponseError?
39-
39+
4040
public init(data: [String : String]? = nil, error: ObjectResponseError? = nil) {
4141
self.data = data
4242
self.error = error

Sources/SuiKit/Types/Structs/Provider/Responses/Object/SuiObjectData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct SuiObjectData: Equatable {
7676
self.type = graphql.asMoveObject!.ifShowType != nil ? graphql.asMoveObject!.ifShowType!.contents!.type.repr : nil
7777
self.version = "\(graphql.version)"
7878
}
79-
79+
8080
public init(graphql: GetObjectQuery.Data.Object, showBcs: Bool = false) {
8181
self.bcs = showBcs ? RawData(graphql: graphql.asMoveObject!, version: "\(graphql.version)") : nil
8282
self.content = graphql.asMoveObject!.ifShowContent != nil ? SuiParsedData(graphql: graphql.asMoveObject!) : nil

Sources/SuiKit/Types/Structs/Provider/Responses/PaginatedObjectsResponse.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public struct PaginatedObjectsResponse {
4040
/// An optional string representing the cursor for the next page of objects.
4141
/// `nil` if there are no more pages available.
4242
public var nextCursor: String?
43-
43+
44+
/// Page info object for the given Object Response page.
4445
public var pageInfo: PageInfo?
4546

4647
public init(data: [SuiObjectResponse], pageInfo: PageInfo? = nil, hasNextPage: Bool? = nil, nextCursor: String? = nil) {

Sources/SuiKit/Types/Structs/Provider/Responses/ValidatorApys.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct ValidatorApys: Equatable {
4242
self.apys = input["apys"].arrayValue.map { ValidatorApy(input: $0) }
4343
self.epoch = input["epoch"].stringValue
4444
}
45-
45+
4646
public init(graphql: GetValidatorsApyQuery.Data) {
4747
self.apys = graphql.epoch!.validatorSet!.activeValidators!.map { validator in
4848
ValidatorApy(

0 commit comments

Comments
 (0)