Skip to content

Commit

Permalink
[MBL-1221] Create mutation for the attribution event (#1960)
Browse files Browse the repository at this point in the history
* Create mutation file

* Regenerate graphapi

* Add create attribution event to service
  • Loading branch information
ifosli committed Feb 27, 2024
1 parent 2b4f052 commit c2bb385
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
399DAD8B2ACD163800238BA1 /* FetchProjectBySlugQuery.graphql in Resources */ = {isa = PBXBuildFile; fileRef = 06813BA326E2779C006BDFB2 /* FetchProjectBySlugQuery.graphql */; };
39B5E10E2B86C56600FFB720 /* RefInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B5E10D2B86C56600FFB720 /* RefInfo.swift */; };
39B5E1102B86C56E00FFB720 /* RefInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B5E10F2B86C56E00FFB720 /* RefInfoTests.swift */; };
39B5E1122B89120F00FFB720 /* CreateAttributionEvent.graphql in Resources */ = {isa = PBXBuildFile; fileRef = 39B5E1112B89120E00FFB720 /* CreateAttributionEvent.graphql */; };
4705D8982742E20900A13BBE /* ProjectHeaderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4705D8972742E20900A13BBE /* ProjectHeaderCell.swift */; };
470B771A26FCDC8900EBD5CA /* RiskMessagingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470B771926FCDC8900EBD5CA /* RiskMessagingViewModel.swift */; };
470B771C26FD022900EBD5CA /* RiskMessagingViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470B771B26FD022900EBD5CA /* RiskMessagingViewModelTests.swift */; };
Expand Down Expand Up @@ -1929,6 +1930,7 @@
37FEFBC7222F1E4F00FCA608 /* ProcessInfoType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessInfoType.swift; sourceTree = "<group>"; };
39B5E10D2B86C56600FFB720 /* RefInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefInfo.swift; sourceTree = "<group>"; };
39B5E10F2B86C56E00FFB720 /* RefInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefInfoTests.swift; sourceTree = "<group>"; };
39B5E1112B89120E00FFB720 /* CreateAttributionEvent.graphql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CreateAttributionEvent.graphql; sourceTree = "<group>"; };
3D1363951F0191FB00B53420 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
4705D8972742E20900A13BBE /* ProjectHeaderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectHeaderCell.swift; sourceTree = "<group>"; };
470B771926FCDC8900EBD5CA /* RiskMessagingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiskMessagingViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5633,6 +5635,7 @@
children = (
47D8619826B9E4F700A31F9A /* ClearUserUnseenActivity.graphql */,
475DEC0026B07BB9001B961B /* CancelBacking.graphql */,
39B5E1112B89120E00FFB720 /* CreateAttributionEvent.graphql */,
8AC3E0C1269E2ADC00168BF8 /* CreateBacking.graphql */,
6051C6602B600E6000514202 /* CreateCheckout.graphql */,
60C996EB2AC1FF0C006BE4F4 /* CreateFlagging.graphql */,
Expand Down Expand Up @@ -7462,6 +7465,7 @@
06DAAE5A26AA3CD500194E58 /* CategoryFragment.graphql in Resources */,
06DAAE5126AA3CBF00194E58 /* UserFragment.graphql in Resources */,
6008632E29B8F66F00B87B39 /* FetchUserEmail.graphql in Resources */,
39B5E1122B89120F00FFB720 /* CreateAttributionEvent.graphql in Resources */,
399DAD8A2ACD163400238BA1 /* UnwatchProject.graphql in Resources */,
06DAAE5B26AA3CD800194E58 /* BackingFragment.graphql in Resources */,
608F974A2B7522EF00DBE7D7 /* ValidateCheckout.graphql in Resources */,
Expand Down
145 changes: 145 additions & 0 deletions KsApi/GraphAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,57 @@ public enum GraphAPI {
}
}

/// Autogenerated input type of CreateAttributionEvent
public struct CreateAttributionEventInput: GraphQLMapConvertible {
public var graphQLMap: GraphQLMap

/// - Parameters:
/// - eventName
/// - eventProperties
/// - projectId
/// - clientMutationId: A unique identifier for the client performing the mutation.
public init(eventName: String, eventProperties: Swift.Optional<String?> = nil, projectId: Swift.Optional<GraphQLID?> = nil, clientMutationId: Swift.Optional<String?> = nil) {
graphQLMap = ["eventName": eventName, "eventProperties": eventProperties, "projectId": projectId, "clientMutationId": clientMutationId]
}

public var eventName: String {
get {
return graphQLMap["eventName"] as! String
}
set {
graphQLMap.updateValue(newValue, forKey: "eventName")
}
}

public var eventProperties: Swift.Optional<String?> {
get {
return graphQLMap["eventProperties"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
}
set {
graphQLMap.updateValue(newValue, forKey: "eventProperties")
}
}

public var projectId: Swift.Optional<GraphQLID?> {
get {
return graphQLMap["projectId"] as? Swift.Optional<GraphQLID?> ?? Swift.Optional<GraphQLID?>.none
}
set {
graphQLMap.updateValue(newValue, forKey: "projectId")
}
}

/// A unique identifier for the client performing the mutation.
public var clientMutationId: Swift.Optional<String?> {
get {
return graphQLMap["clientMutationId"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
}
set {
graphQLMap.updateValue(newValue, forKey: "clientMutationId")
}
}
}

/// Autogenerated input type of CreateBacking
public struct CreateBackingInput: GraphQLMapConvertible {
public var graphQLMap: GraphQLMap
Expand Down Expand Up @@ -3933,6 +3984,100 @@ public enum GraphAPI {
}
}

public final class CreateAttributionEventMutation: GraphQLMutation {
/// The raw GraphQL definition of this operation.
public let operationDefinition: String =
"""
mutation createAttributionEvent($input: CreateAttributionEventInput!) {
createAttributionEvent(input: $input) {
__typename
successful
}
}
"""

public let operationName: String = "createAttributionEvent"

public var input: CreateAttributionEventInput

public init(input: CreateAttributionEventInput) {
self.input = input
}

public var variables: GraphQLMap? {
return ["input": input]
}

public struct Data: GraphQLSelectionSet {
public static let possibleTypes: [String] = ["Mutation"]

public static var selections: [GraphQLSelection] {
return [
GraphQLField("createAttributionEvent", arguments: ["input": GraphQLVariable("input")], type: .object(CreateAttributionEvent.selections)),
]
}

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(createAttributionEvent: CreateAttributionEvent? = nil) {
self.init(unsafeResultMap: ["__typename": "Mutation", "createAttributionEvent": createAttributionEvent.flatMap { (value: CreateAttributionEvent) -> ResultMap in value.resultMap }])
}

/// Creates an attribution event. Specifying a project will pass the project properties for attribution events. Sending this request as a logged-in user passes that user's properties as well. Any passed-in property with the same name overwrites the generated properties.
public var createAttributionEvent: CreateAttributionEvent? {
get {
return (resultMap["createAttributionEvent"] as? ResultMap).flatMap { CreateAttributionEvent(unsafeResultMap: $0) }
}
set {
resultMap.updateValue(newValue?.resultMap, forKey: "createAttributionEvent")
}
}

public struct CreateAttributionEvent: GraphQLSelectionSet {
public static let possibleTypes: [String] = ["CreateAttributionEventPayload"]

public static var selections: [GraphQLSelection] {
return [
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
GraphQLField("successful", type: .nonNull(.scalar(Bool.self))),
]
}

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(successful: Bool) {
self.init(unsafeResultMap: ["__typename": "CreateAttributionEventPayload", "successful": successful])
}

public var __typename: String {
get {
return resultMap["__typename"]! as! String
}
set {
resultMap.updateValue(newValue, forKey: "__typename")
}
}

public var successful: Bool {
get {
return resultMap["successful"]! as! Bool
}
set {
resultMap.updateValue(newValue, forKey: "successful")
}
}
}
}
}

public final class CreateBackingMutation: GraphQLMutation {
/// The raw GraphQL definition of this operation.
public let operationDefinition: String =
Expand Down
16 changes: 16 additions & 0 deletions KsApi/MockService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

fileprivate let changePasswordResult: Result<EmptyResponseEnvelope, ErrorEnvelope>?

fileprivate let createAttributionEventResult: Result<EmptyResponseEnvelope, ErrorEnvelope>?

fileprivate let createBackingResult: Result<CreateBackingEnvelope, ErrorEnvelope>?

fileprivate let createCheckoutResult: Result<CreateCheckoutEnvelope, ErrorEnvelope>?
Expand Down Expand Up @@ -227,6 +229,7 @@
cancelBackingResult: Result<EmptyResponseEnvelope, ErrorEnvelope>? = nil,
changeEmailResult: Result<EmptyResponseEnvelope, ErrorEnvelope>? = nil,
changePasswordResult: Result<EmptyResponseEnvelope, ErrorEnvelope>? = nil,
createAttributionEventResult: Result<EmptyResponseEnvelope, ErrorEnvelope>? = nil,
createBackingResult: Result<CreateBackingEnvelope, ErrorEnvelope>? = nil,
createCheckoutResult: Result<CreateCheckoutEnvelope, ErrorEnvelope>? = nil,
createFlaggingResult: Result<EmptyResponseEnvelope, ErrorEnvelope>? = nil,
Expand Down Expand Up @@ -350,6 +353,8 @@

self.clearUserUnseenActivityResult = clearUserUnseenActivityResult

self.createAttributionEventResult = createAttributionEventResult

self.createBackingResult = createBackingResult

self.createCheckoutResult = createCheckoutResult
Expand Down Expand Up @@ -618,6 +623,17 @@
return client.performWithResult(mutation: mutation, result: self.changePasswordResult)
}

public func createAttributionEvent(input: GraphAPI.CreateAttributionEventInput) ->
SignalProducer<EmptyResponseEnvelope, ErrorEnvelope> {
guard let client = self.apolloClient else {
return .empty
}

let mutation = GraphAPI.CreateAttributionEventMutation(input: input)

return client.performWithResult(mutation: mutation, result: self.createAttributionEventResult)
}

internal func createBacking(input: CreateBackingInput)
-> SignalProducer<CreateBackingEnvelope, ErrorEnvelope> {
guard let client = self.apolloClient else {
Expand Down
9 changes: 9 additions & 0 deletions KsApi/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public struct Service: ServiceType {
}
}

public func createAttributionEvent(input: GraphAPI.CreateAttributionEventInput) ->
SignalProducer<EmptyResponseEnvelope, ErrorEnvelope> {
return GraphQL.shared.client
.perform(mutation: GraphAPI.CreateAttributionEventMutation(input: input))
.flatMap { _ in
SignalProducer(value: EmptyResponseEnvelope())
}
}

public func createBacking(input: CreateBackingInput) ->
SignalProducer<CreateBackingEnvelope, ErrorEnvelope> {
return GraphQL.shared.client
Expand Down
4 changes: 4 additions & 0 deletions KsApi/ServiceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public protocol ServiceType {
func clearUserUnseenActivity(input: EmptyInput)
-> SignalProducer<ClearUserUnseenActivityEnvelope, ErrorEnvelope>

/// Let the server know to create/track an attribution event.
func createAttributionEvent(input: GraphAPI.CreateAttributionEventInput) ->
SignalProducer<EmptyResponseEnvelope, ErrorEnvelope>

func createBacking(input: CreateBackingInput) ->
SignalProducer<CreateBackingEnvelope, ErrorEnvelope>

Expand Down
5 changes: 5 additions & 0 deletions KsApi/mutations/CreateAttributionEvent.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation createAttributionEvent($input: CreateAttributionEventInput!) {
createAttributionEvent(input: $input) {
successful
}
}

0 comments on commit c2bb385

Please sign in to comment.