Skip to content

Commit

Permalink
- Updated schema.graphqls (#2183)
Browse files Browse the repository at this point in the history
- Gradle upgrade
- re-writted thirdPartyEvents mutation
- Adopted Apollo3 version of `override fun triggerThirdPartyEvent(eventInput: TPEventInputData): Observable<Pair<Boolean, String>>` in KSApolloClientV2

Co-authored-by: jlplks <[email protected]>
Co-authored-by: Leigh Douglas <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent ee65993 commit 68eca93
Show file tree
Hide file tree
Showing 6 changed files with 4,325 additions and 373 deletions.
4,565 changes: 4,257 additions & 308 deletions app/src/main/graphql/schema.graphqls

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions app/src/main/graphql/thirdPartyEvents.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#mutation triggerThirdPartyEvent ($triggerThirdPartyEventInput: TriggerThirdPartyEventInput!) {
# triggerThirdPartyEvent(input: $triggerThirdPartyEventInput) {
# message
# success
# }
#}
mutation triggerThirdPartyEvent($deviceId: String!, $eventName: String!, $firebaseScreen: String, $firebasePreviousScreen: String, $items: [ThirdPartyEventItemInput!],
$projectId: ID!, $pledgeAmount: Float, $shipping: Float, $transactionId: String, $userId: String, $appData: AppDataInput ) {
triggerThirdPartyEvent(input: {deviceId: $deviceId, eventName: $eventName, firebaseScreen: $firebaseScreen, firebasePreviousScreen: $firebasePreviousScreen,
items: $items, projectId: $projectId, pledgeAmount: $pledgeAmount, shipping: $shipping, transactionId: $transactionId, userId: $userId, appData: $appData}) {
message
success
}
}
46 changes: 23 additions & 23 deletions app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import com.kickstarter.services.transformers.encodeRelayId
import com.kickstarter.services.transformers.getCreateAttributionEventMutation
import com.kickstarter.services.transformers.getCreateOrUpdateBackingAddressMutation
import com.kickstarter.services.transformers.getPledgedProjectsOverviewQuery
import com.kickstarter.services.transformers.getTriggerThirdPartyEventMutation
import com.kickstarter.services.transformers.pledgedProjectsOverviewEnvelopeTransformer
import com.kickstarter.services.transformers.projectTransformer
import com.kickstarter.services.transformers.rewardTransformer
Expand Down Expand Up @@ -876,28 +877,27 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient
override fun triggerThirdPartyEvent(eventInput: TPEventInputData): Observable<Pair<Boolean, String>> {
return Observable.defer {
val ps = PublishSubject.create<Pair<Boolean, String>>()
// TODO: rewrite this query on the thirdPartyEvents.graphQL file, something is off here
// val mutation = getTriggerThirdPartyEventMutation(eventInput)
//
// service.mutate(mutation)
// .enqueue(object : ApolloCall.Callback<TriggerThirdPartyEventMutation.Data>() {
// override fun onFailure(exception: ApolloException) {
// ps.onError(exception)
// }
//
// override fun onResponse(response: Response<TriggerThirdPartyEventMutation.Data>) {
// if (response.hasErrors()) {
// ps.onError(Exception(response.errors?.first()?.message ?: ""))
// }
//
// response.data?.let {
// val message = it.triggerThirdPartyEvent()?.message() ?: ""
// val isSuccess = it.triggerThirdPartyEvent()?.success() ?: false
// ps.onNext(Pair(isSuccess, message))
// }
// ps.onComplete()
// }
// })

val mutation = getTriggerThirdPartyEventMutation(eventInput)

service
.mutation(mutation)
.rxSingle()
.doOnError { throwable ->
ps.onError(throwable)
}
.subscribe { response ->
if (response.hasErrors()) {
ps.onError(java.lang.Exception(response.errors?.first()?.message))
} else {
val message = response.data?.triggerThirdPartyEvent?.message
val isSuccess = response.data?.triggerThirdPartyEvent?.success ?: false

ps.onNext(Pair(isSuccess, message))
}

ps.onComplete()
}.addToDisposable(disposables)
return@defer ps
}
}
Expand Down Expand Up @@ -1710,7 +1710,7 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient

response.data?.completeOrder?.let {
val payload = CompleteOrderPayload(
status = it.status,
status = it.status.name,
clientSecret = it.clientSecret ?: ""
)
ps.onNext(payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kickstarter.CreateAttributionEventMutation
import com.kickstarter.CreateOrUpdateBackingAddressMutation
import com.kickstarter.FetchProjectRewardsQuery
import com.kickstarter.PledgedProjectsOverviewQuery
import com.kickstarter.TriggerThirdPartyEventMutation
import com.kickstarter.UserPrivacyQuery
import com.kickstarter.features.pledgedprojectsoverview.data.Flag
import com.kickstarter.features.pledgedprojectsoverview.data.PPOCard
Expand All @@ -19,6 +20,7 @@ import com.kickstarter.fragment.PpoCard.DeliveryAddress
import com.kickstarter.fragment.ProjectCard
import com.kickstarter.libs.Permission
import com.kickstarter.libs.utils.extensions.isNotNull
import com.kickstarter.libs.utils.extensions.isNull
import com.kickstarter.libs.utils.extensions.isPresent
import com.kickstarter.libs.utils.extensions.negate
import com.kickstarter.mock.factories.RewardFactory
Expand Down Expand Up @@ -48,6 +50,7 @@ import com.kickstarter.services.apiresponses.ShippingRulesEnvelope
import com.kickstarter.services.apiresponses.commentresponse.PageInfoEnvelope
import com.kickstarter.services.mutations.CreateAttributionEventData
import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData
import com.kickstarter.type.AppDataInput
import com.kickstarter.type.CollaboratorPermission
import com.kickstarter.type.CreateAttributionEventInput
import com.kickstarter.type.CreateOrUpdateBackingAddressInput
Expand All @@ -56,6 +59,8 @@ import com.kickstarter.type.CurrencyCode
import com.kickstarter.type.Feature
import com.kickstarter.type.RewardType
import com.kickstarter.type.ShippingPreference
import com.kickstarter.type.ThirdPartyEventItemInput
import com.kickstarter.viewmodels.usecases.TPEventInputData
import org.jetbrains.annotations.Nullable
import org.joda.time.DateTime
import java.nio.charset.Charset
Expand Down Expand Up @@ -880,40 +885,36 @@ fun shippingRulesListTransformer(shippingRulesExpanded: List<com.kickstarter.fra
* From KS dataModel TPEventInputData, transform it into
* GraphQL defined mutation TriggerThirdPartyEventMutation
*/
// fun getTriggerThirdPartyEventMutation(eventInput: TPEventInputData): TriggerThirdPartyEventMutation {
// val graphAppData = AppDataInput.builder()
// .advertiserTrackingEnabled(eventInput.appData.iOSConsent)
// .applicationTrackingEnabled(eventInput.appData.androidConsent)
// .extinfo(eventInput.appData.extInfo)
// .build()
//
// val items: List<ThirdPartyEventItemInput> = eventInput.items
// .map {
// ThirdPartyEventItemInput.builder()
// .itemId(it.itemId)
// .itemName(it.itemName)
// .price(it.price)
// .build()
// }
//
// val graphInput =
// TriggerThirdPartyEventInput.builder()
// .userId(eventInput.userId)
// .eventName(eventInput.eventName)
// .deviceId(eventInput.deviceId)
// .firebaseScreen(eventInput.firebaseScreen)
// .firebasePreviousScreen(eventInput.firebasePreviousScreen)
// .projectId(eventInput.projectId)
// .pledgeAmount(eventInput.pledgeAmount)
// .shipping(eventInput.shipping)
// .appData(graphAppData)
// .items(items)
// .transactionId(eventInput.transactionId)
// .build()
//
// return TriggerThirdPartyEventMutation.builder().triggerThirdPartyEventInput(graphInput)
// .build()
// }
fun getTriggerThirdPartyEventMutation(eventInput: TPEventInputData): TriggerThirdPartyEventMutation {
val graphAppData = AppDataInput(
advertiserTrackingEnabled = eventInput.appData.iOSConsent,
applicationTrackingEnabled = eventInput.appData.androidConsent,
extinfo = eventInput.appData.extInfo
)

val items: List<ThirdPartyEventItemInput> = eventInput.items
.map {
ThirdPartyEventItemInput(
itemId = it.itemId,
itemName = it.itemName,
price = if (it.price.isNotNull()) Optional.present(it.price) else Optional.absent()
)
}

return TriggerThirdPartyEventMutation(
userId = if (eventInput.isNull()) Optional.absent() else Optional.present(eventInput.userId),
eventName = eventInput.eventName,
deviceId = eventInput.deviceId,
firebaseScreen = if (eventInput.firebaseScreen.isNull()) Optional.absent() else Optional.present(eventInput.firebaseScreen),
firebasePreviousScreen = if (eventInput.firebasePreviousScreen.isNull()) Optional.absent() else Optional.present(eventInput.firebasePreviousScreen),
projectId = eventInput.projectId,
pledgeAmount = if (eventInput.pledgeAmount.isNull()) Optional.absent() else Optional.present(eventInput.pledgeAmount),
shipping = if (eventInput.shipping.isNull()) Optional.absent() else Optional.present(eventInput.shipping),
appData = if (graphAppData.isNull()) Optional.absent() else Optional.present(graphAppData),
items = if (items.isNull()) Optional.absent() else Optional.present(items),
transactionId = if (eventInput.isNull()) Optional.absent() else Optional.present(eventInput.transactionId)
)
}

/**
* From KS dataModel CreateAttributionEventData, transform it into
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.6.1'
classpath 'com.android.tools.build:gradle:8.7.2'
classpath 'com.google.gms:google-services:4.3.15'
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 26 16:41:20 PST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 68eca93

Please sign in to comment.