Skip to content

Commit

Permalink
Merge pull request #1034 from 0x1-company/share-link-client
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun authored Nov 30, 2023
2 parents 8606ded + 0cec85a commit 7718d4f
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 45 deletions.
7 changes: 7 additions & 0 deletions App/Development.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
B783E0FD2A11FFD0002E782F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B783E0FC2A11FFD0002E782F /* Preview Assets.xcassets */; };
B783E1022A120003002E782F /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = B783E1012A120003002E782F /* App.swift */; };
B78862D32A68FCFF0023B1FB /* AppFeature in Frameworks */ = {isa = PBXBuildFile; productRef = B78862D22A68FCFF0023B1FB /* AppFeature */; };
B7C58CE12B17FEFC001405EE /* ShareLinkClientLive in Frameworks */ = {isa = PBXBuildFile; productRef = B7C58CE02B17FEFC001405EE /* ShareLinkClientLive */; };
B7DE59AD2A959B14001D8C19 /* ApolloClientHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */; };
B7E273BD2AA3D06D005DC4BD /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E273BC2AA3D06D005DC4BD /* StoreKit.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -54,6 +55,7 @@
B7E273BD2AA3D06D005DC4BD /* StoreKit.framework in Frameworks */,
B7DE59AD2A959B14001D8C19 /* ApolloClientHelpers in Frameworks */,
B78862D32A68FCFF0023B1FB /* AppFeature in Frameworks */,
B7C58CE12B17FEFC001405EE /* ShareLinkClientLive in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -130,6 +132,7 @@
packageProductDependencies = (
B78862D22A68FCFF0023B1FB /* AppFeature */,
B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */,
B7C58CE02B17FEFC001405EE /* ShareLinkClientLive */,
);
productName = iOS;
productReference = B783E0F32A11FFD0002E782F /* App.app */;
Expand Down Expand Up @@ -406,6 +409,10 @@
isa = XCSwiftPackageProductDependency;
productName = AppFeature;
};
B7C58CE02B17FEFC001405EE /* ShareLinkClientLive */ = {
isa = XCSwiftPackageProductDependency;
productName = ShareLinkClientLive;
};
B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */ = {
isa = XCSwiftPackageProductDependency;
productName = ApolloClientHelpers;
Expand Down
2 changes: 2 additions & 0 deletions App/Multiplatform/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FirebaseAuth
import FirebaseAuthClient
import FirebaseDynamicLinks
import FirebaseMessaging
import ShareLinkClientLive
import GodClient
import Styleguide
import SwiftUI
Expand Down Expand Up @@ -46,6 +47,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
._printChanges()
.transformDependency(\.self) {
$0.godClient = .live(apolloClient: ApolloClient(build: $0.build))
$0.shareLink = .live(stream: $0.godClient.shareLink)
}
}
)
Expand Down
7 changes: 7 additions & 0 deletions App/Production.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
B783E0EB2A11FFBE002E782F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B783E0EA2A11FFBE002E782F /* Preview Assets.xcassets */; };
B783E1042A12000A002E782F /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = B783E1032A12000A002E782F /* App.swift */; };
B78862D52A68FD050023B1FB /* AppFeature in Frameworks */ = {isa = PBXBuildFile; productRef = B78862D42A68FD050023B1FB /* AppFeature */; };
B7C58CE32B17FF05001405EE /* ShareLinkClientLive in Frameworks */ = {isa = PBXBuildFile; productRef = B7C58CE22B17FF05001405EE /* ShareLinkClientLive */; };
B7DE59AF2A959B1D001D8C19 /* ApolloClientHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = B7DE59AE2A959B1D001D8C19 /* ApolloClientHelpers */; };
B7E273BF2AA3D079005DC4BD /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E273BE2AA3D079005DC4BD /* StoreKit.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -52,6 +53,7 @@
B7E273BF2AA3D079005DC4BD /* StoreKit.framework in Frameworks */,
B7DE59AF2A959B1D001D8C19 /* ApolloClientHelpers in Frameworks */,
B78862D52A68FD050023B1FB /* AppFeature in Frameworks */,
B7C58CE32B17FF05001405EE /* ShareLinkClientLive in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -127,6 +129,7 @@
packageProductDependencies = (
B78862D42A68FD050023B1FB /* AppFeature */,
B7DE59AE2A959B1D001D8C19 /* ApolloClientHelpers */,
B7C58CE22B17FF05001405EE /* ShareLinkClientLive */,
);
productName = iOS;
productReference = B783E0E12A11FFBE002E782F /* App.app */;
Expand Down Expand Up @@ -412,6 +415,10 @@
isa = XCSwiftPackageProductDependency;
productName = AppFeature;
};
B7C58CE22B17FF05001405EE /* ShareLinkClientLive */ = {
isa = XCSwiftPackageProductDependency;
productName = ShareLinkClientLive;
};
B7DE59AE2A959B1D001D8C19 /* ApolloClientHelpers */ = {
isa = XCSwiftPackageProductDependency;
productName = ApolloClientHelpers;
Expand Down
7 changes: 7 additions & 0 deletions App/Staging.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
B783E0FD2A11FFD0002E782F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B783E0FC2A11FFD0002E782F /* Preview Assets.xcassets */; };
B783E1022A120003002E782F /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = B783E1012A120003002E782F /* App.swift */; };
B78862D32A68FCFF0023B1FB /* AppFeature in Frameworks */ = {isa = PBXBuildFile; productRef = B78862D22A68FCFF0023B1FB /* AppFeature */; };
B7C58CDF2B17FEEE001405EE /* ShareLinkClientLive in Frameworks */ = {isa = PBXBuildFile; productRef = B7C58CDE2B17FEEE001405EE /* ShareLinkClientLive */; };
B7DE59AD2A959B14001D8C19 /* ApolloClientHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */; };
B7E273BD2AA3D06D005DC4BD /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E273BC2AA3D06D005DC4BD /* StoreKit.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -53,6 +54,7 @@
B7E273BD2AA3D06D005DC4BD /* StoreKit.framework in Frameworks */,
B7DE59AD2A959B14001D8C19 /* ApolloClientHelpers in Frameworks */,
B78862D32A68FCFF0023B1FB /* AppFeature in Frameworks */,
B7C58CDF2B17FEEE001405EE /* ShareLinkClientLive in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -129,6 +131,7 @@
packageProductDependencies = (
B78862D22A68FCFF0023B1FB /* AppFeature */,
B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */,
B7C58CDE2B17FEEE001405EE /* ShareLinkClientLive */,
);
productName = iOS;
productReference = B783E0F32A11FFD0002E782F /* App.app */;
Expand Down Expand Up @@ -406,6 +409,10 @@
isa = XCSwiftPackageProductDependency;
productName = AppFeature;
};
B7C58CDE2B17FEEE001405EE /* ShareLinkClientLive */ = {
isa = XCSwiftPackageProductDependency;
productName = ShareLinkClientLive;
};
B7DE59AC2A959B14001D8C19 /* ApolloClientHelpers */ = {
isa = XCSwiftPackageProductDependency;
productName = ApolloClientHelpers;
Expand Down
4 changes: 2 additions & 2 deletions God.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "63301f4a181ed9aefb46dccef2dfb66466798341",
"version" : "1.1.1"
"revision" : "9783b58167f7618cb86011156e741cbc6f4cc864",
"version" : "1.1.2"
}
},
{
Expand Down
10 changes: 10 additions & 0 deletions GraphQL/Queries/ShareLinkClient.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query ShareLinkClient {
currentUser {
id
username
}
invitationCode {
id
code
}
}
19 changes: 17 additions & 2 deletions Packages/DependencyPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let package = Package(
products: [
.library(name: "AnalyticsClient", targets: ["AnalyticsClient"]),
.library(name: "ApolloClientHelpers", targets: ["ApolloClientHelpers"]),
.library(name: "ApolloConcurrency", targets: ["ApolloConcurrency"]),
.library(name: "AsyncValue", targets: ["AsyncValue"]),
.library(name: "Constants", targets: ["Constants"]),
.library(name: "DeleteAccountReasonClient", targets: ["DeleteAccountReasonClient"]),
Expand All @@ -27,6 +28,8 @@ let package = Package(
.library(name: "GodTestMock", targets: ["GodTestMock"]),
.library(name: "PhoneNumberDependencies", targets: ["PhoneNumberDependencies"]),
.library(name: "ShareLinkBuilder", targets: ["ShareLinkBuilder"]),
.library(name: "ShareLinkClient", targets: ["ShareLinkClient"]),
.library(name: "ShareLinkClientLive", targets: ["ShareLinkClientLive"]),
.library(name: "StoreKitHelpers", targets: ["StoreKitHelpers"]),
.library(name: "StringHelpers", targets: ["StringHelpers"]),
.library(name: "TcaHelpers", targets: ["TcaHelpers"]),
Expand All @@ -38,6 +41,7 @@ let package = Package(
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.18.0"),
.package(url: "https://github.com/marmelroy/PhoneNumberKit", from: "3.7.5"),
.package(url: "https://github.com/apollographql/apollo-ios", from: "1.6.1"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.2"),
],
targets: [
.target(name: "AnalyticsClient", dependencies: [
Expand All @@ -49,6 +53,10 @@ let package = Package(
.product(name: "Build", package: "CupertinoPackage"),
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
]),
.target(name: "ApolloConcurrency", dependencies: [
.product(name: "Apollo", package: "apollo-ios"),
.product(name: "ApolloAPI", package: "apollo-ios"),
]),
.target(name: "AsyncValue"),
.target(name: "Constants"),
.target(name: "DeleteAccountReasonClient", dependencies: [
Expand Down Expand Up @@ -89,8 +97,7 @@ let package = Package(
]),
.target(name: "GodClient", dependencies: [
"God",
.product(name: "Apollo", package: "apollo-ios"),
.product(name: "ApolloAPI", package: "apollo-ios"),
"ApolloConcurrency",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "GodTestMock", dependencies: [
Expand All @@ -105,6 +112,14 @@ let package = Package(
.testTarget(name: "ShareLinkBuilderTests", dependencies: [
"ShareLinkBuilder",
]),
.target(name: "ShareLinkClient", dependencies: [
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
]),
.target(name: "ShareLinkClientLive", dependencies: [
"God",
"ShareLinkClient",
]),
.target(name: "StoreKitHelpers", dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Apollo
import ApolloAPI
import Foundation
import os

private let logger = Logger(subsystem: "jp.godapp", category: "ApolloClient")

public extension ApolloClient {
func watch<Query: GraphQLQuery>(
Expand Down Expand Up @@ -65,6 +62,33 @@ public extension ApolloClient {
}
}

public struct GodServerError: Error {
public let message: String
public let extensions: [String: Any]
public var code: GodServerErrorCode? {
guard let code = extensions["code"] as? String
else { return nil }
return GodServerErrorCode(rawValue: code)
}

public init(
message: String,
extensions: [String: Any]
) {
self.message = message
self.extensions = extensions
}

public enum GodServerErrorCode: String {
case badUserInput = "BAD_USER_INPUT"
case forbidden = "FORBIDDEN"
case unauthenticated = "UNAUTHENTICATED"
case `internal` = "INTERNAL_SERVER_ERROR"
case notInGodMode = "NOT_IN_GOD_MODE"
case noRevealPermission = "NO_REVEAL_PERMISSION"
}
}

public extension GodServerError {
init(error: GraphQLError) {
self.init(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

public extension God {
class ShareLinkClientQuery: GraphQLQuery {
public static let operationName: String = "ShareLinkClient"
public static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"query ShareLinkClient { currentUser { __typename id username } invitationCode { __typename id code } }"#
))

public init() {}

public struct Data: God.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: ApolloAPI.ParentType { God.Objects.Query }
public static var __selections: [ApolloAPI.Selection] { [
.field("currentUser", CurrentUser.self),
.field("invitationCode", InvitationCode.self),
] }

/// ログイン中ユーザーを取得
public var currentUser: CurrentUser { __data["currentUser"] }
/// 招待コードを取得
public var invitationCode: InvitationCode { __data["invitationCode"] }

/// CurrentUser
///
/// Parent Type: `User`
public struct CurrentUser: God.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: ApolloAPI.ParentType { God.Objects.User }
public static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("id", God.ID.self),
.field("username", String?.self),
] }

/// user id
public var id: God.ID { __data["id"] }
/// username
public var username: String? { __data["username"] }
}

/// InvitationCode
///
/// Parent Type: `InvitationCode`
public struct InvitationCode: God.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: ApolloAPI.ParentType { God.Objects.InvitationCode }
public static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("id", God.ID.self),
.field("code", String.self),
] }

public var id: God.ID { __data["id"] }
/// 招待コード
public var code: String { __data["code"] }
}
}
}

}
29 changes: 2 additions & 27 deletions Packages/DependencyPackage/Sources/GodClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,6 @@ public struct GodClient: Sendable {

public var banners: @Sendable () -> AsyncThrowingStream<God.BannersQuery.Data, Error>
public var clubActivities: @Sendable () -> AsyncThrowingStream<God.ClubActivitiesQuery.Data, Error>
}

public struct GodServerError: Error {
public let message: String
public let extensions: [String: Any]
public var code: GodServerErrorCode? {
guard let code = extensions["code"] as? String
else { return nil }
return GodServerErrorCode(rawValue: code)
}

public init(
message: String,
extensions: [String: Any]
) {
self.message = message
self.extensions = extensions
}

public enum GodServerErrorCode: String {
case badUserInput = "BAD_USER_INPUT"
case forbidden = "FORBIDDEN"
case unauthenticated = "UNAUTHENTICATED"
case `internal` = "INTERNAL_SERVER_ERROR"
case notInGodMode = "NOT_IN_GOD_MODE"
case noRevealPermission = "NO_REVEAL_PERMISSION"
}

public var shareLink: @Sendable () -> AsyncThrowingStream<God.ShareLinkClientQuery.Data, Error>
}
5 changes: 5 additions & 0 deletions Packages/DependencyPackage/Sources/GodClient/LiveKey.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ApolloConcurrency
import Apollo
import Dependencies
import Foundation
Expand Down Expand Up @@ -145,6 +146,10 @@ public extension GodClient {
clubActivities: {
let query = God.ClubActivitiesQuery()
return apolloClient.watch(query: query)
},
shareLink: {
let query = God.ShareLinkClientQuery()
return apolloClient.watch(query: query)
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion Packages/DependencyPackage/Sources/GodClient/TestKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extension GodClient: TestDependencyKey {
revealFullNameLimit: unimplemented("\(Self.self).revealFullNameLimit"),
revealFullName: unimplemented("\(Self.self).revealFullName"),
banners: unimplemented("\(Self.self).banners"),
clubActivities: unimplemented("\(Self.self).clubActivities")
clubActivities: unimplemented("\(Self.self).clubActivities"),
shareLink: unimplemented("\(Self.self).shareLink")
)
}
Loading

0 comments on commit 7718d4f

Please sign in to comment.