Regenerate GQL, set createPageEntry when uploading files
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -24,16 +24,16 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.ArchiveLinkResult> {
|
||||
try $0.on(
|
||||
archiveLinkError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
archiveLinkSuccess: .init { .success(linkId: try $0.linkId()) }
|
||||
archiveLinkSuccess: .init { .success(linkId: try $0.linkId()) },
|
||||
archiveLinkError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.setLinkArchived(
|
||||
input: InputObjects.ArchiveLinkInput(
|
||||
archived: archived,
|
||||
linkId: itemID
|
||||
linkId: itemID,
|
||||
archived: archived
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -40,22 +40,22 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateHighlightResult> {
|
||||
try $0.on(
|
||||
createHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) },
|
||||
createHighlightSuccess: .init {
|
||||
.saved(highlight: try $0.highlight(selection: highlightSelection))
|
||||
}
|
||||
},
|
||||
createHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.createHighlight(
|
||||
input: InputObjects.CreateHighlightInput(
|
||||
annotation: OptionalArgument(highlight.annotation),
|
||||
articleId: articleId,
|
||||
id: highlight.id,
|
||||
shortId: highlight.shortId,
|
||||
articleId: articleId,
|
||||
patch: highlight.patch,
|
||||
quote: highlight.quote,
|
||||
shortId: highlight.shortId
|
||||
annotation: OptionalArgument(highlight.annotation)
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -34,17 +34,17 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateLabelResult> {
|
||||
try $0.on(
|
||||
createLabelError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
createLabelSuccess: .init { .saved(label: try $0.label(selection: feedItemLabelSelection)) }
|
||||
createLabelSuccess: .init { .saved(label: try $0.label(selection: feedItemLabelSelection)) },
|
||||
createLabelError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.createLabel(
|
||||
input: InputObjects.CreateLabelInput(
|
||||
name: label.name,
|
||||
color: label.color,
|
||||
description: OptionalArgument(label.labelDescription),
|
||||
name: label.name
|
||||
description: OptionalArgument(label.labelDescription)
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -12,9 +12,6 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateNewsletterEmailResult> {
|
||||
try $0.on(
|
||||
createNewsletterEmailError: .init {
|
||||
.error(errorCode: try $0.errorCodes().first ?? .badRequest)
|
||||
},
|
||||
createNewsletterEmailSuccess: .init {
|
||||
.saved(newsletterEmail: try $0.newsletterEmail(selection: Selection.NewsletterEmail {
|
||||
InternalNewsletterEmail(
|
||||
@ -23,6 +20,9 @@ public extension DataService {
|
||||
confirmationCode: try $0.confirmationCode()
|
||||
)
|
||||
}))
|
||||
},
|
||||
createNewsletterEmailError: .init {
|
||||
.error(errorCode: try $0.errorCodes().first ?? .badRequest)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -37,21 +37,21 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateReminderResult> {
|
||||
try $0.on(
|
||||
createReminderError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
createReminderSuccess: .init {
|
||||
.complete(id: try $0.reminder(selection: Selection.Reminder { try $0.id() }))
|
||||
}
|
||||
},
|
||||
createReminderError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.createReminder(
|
||||
input: InputObjects.CreateReminderInput(
|
||||
archiveUntil: true,
|
||||
clientRequestId: OptionalArgument(reminderItemId.clientRequestId),
|
||||
linkId: OptionalArgument(reminderItemId.linkId),
|
||||
remindAt: DateTime(from: remindAt),
|
||||
sendNotification: true
|
||||
clientRequestId: OptionalArgument(reminderItemId.clientRequestId),
|
||||
archiveUntil: true,
|
||||
sendNotification: true,
|
||||
remindAt: DateTime(from: remindAt)
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -30,10 +30,10 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.DeleteHighlightResult> {
|
||||
try $0.on(
|
||||
deleteHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .unauthorized) },
|
||||
deleteHighlightSuccess: .init {
|
||||
.saved(id: try $0.highlight(selection: Selection.Highlight { try $0.id() }))
|
||||
}
|
||||
},
|
||||
deleteHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .unauthorized) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -12,8 +12,8 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.UnsubscribeResult> {
|
||||
try $0.on(
|
||||
unsubscribeError: .init { .error(errorMessage: (try $0.errorCodes().first ?? .unauthorized).rawValue) },
|
||||
unsubscribeSuccess: .init { .success(id: try $0.subscription(selection: Selection.Subscription { try $0.id() })) }
|
||||
unsubscribeSuccess: .init { .success(id: try $0.subscription(selection: Selection.Subscription { try $0.id() })) },
|
||||
unsubscribeError: .init { .error(errorMessage: (try $0.errorCodes().first ?? .unauthorized).rawValue) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -34,10 +34,10 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SetDeviceTokenResult> {
|
||||
try $0.on(
|
||||
setDeviceTokenError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
setDeviceTokenSuccess: .init {
|
||||
.saved(id: try $0.deviceToken(selection: Selection.DeviceToken { try $0.id() }))
|
||||
}
|
||||
},
|
||||
setDeviceTokenError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -46,25 +46,25 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.MergeHighlightResult> {
|
||||
try $0.on(
|
||||
mergeHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) },
|
||||
mergeHighlightSuccess: .init {
|
||||
.saved(highlight: try $0.highlight(selection: highlightSelection))
|
||||
}
|
||||
},
|
||||
mergeHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.mergeHighlight(
|
||||
input: InputObjects.MergeHighlightInput(
|
||||
annotation: .absent(),
|
||||
articleId: articleId,
|
||||
id: highlight.id,
|
||||
overlapHighlightIdList: overlapHighlightIdList,
|
||||
patch: highlight.patch,
|
||||
prefix: .absent(),
|
||||
quote: highlight.quote,
|
||||
shortId: highlight.shortId,
|
||||
suffix: .absent()
|
||||
articleId: articleId,
|
||||
patch: highlight.patch,
|
||||
quote: highlight.quote,
|
||||
prefix: .absent(),
|
||||
suffix: .absent(),
|
||||
annotation: .absent(),
|
||||
overlapHighlightIdList: overlapHighlightIdList
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -23,10 +23,10 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.DeleteLabelResult> {
|
||||
try $0.on(
|
||||
deleteLabelError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
deleteLabelSuccess: .init {
|
||||
.success(labelID: try $0.label(selection: Selection.Label { try $0.id() }))
|
||||
}
|
||||
},
|
||||
deleteLabelError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -24,14 +24,14 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SetBookmarkArticleResult> {
|
||||
try $0.on(
|
||||
setBookmarkArticleError: .init { .error(errorCode: try $0.errorCodes().first ?? .notFound) },
|
||||
setBookmarkArticleSuccess: .init {
|
||||
.success(
|
||||
linkId: try $0.bookmarkedArticle(selection: Selection.Article {
|
||||
try $0.id()
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
setBookmarkArticleError: .init { .error(errorCode: try $0.errorCodes().first ?? .notFound) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@ public extension Networker {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.ArticleSavingRequestResult> {
|
||||
try $0.on(
|
||||
articleSavingRequestError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .notFound) },
|
||||
articleSavingRequestSuccess: .init {
|
||||
.saved(
|
||||
status: try $0.articleSavingRequest(
|
||||
@ -41,7 +40,8 @@ public extension Networker {
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
articleSavingRequestError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .notFound) }
|
||||
)
|
||||
}
|
||||
|
||||
@ -102,15 +102,15 @@ public extension DataService {
|
||||
}()
|
||||
|
||||
let input = InputObjects.CreateArticleInput(
|
||||
url: pageScrapePayload.url,
|
||||
preparedDocument: OptionalArgument(preparedDocument),
|
||||
uploadFileId: uploadFileId != nil ? .present(uploadFileId!) : .null(),
|
||||
url: pageScrapePayload.url
|
||||
uploadFileId: uploadFileId != nil ? .present(uploadFileId!) : .null()
|
||||
)
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateArticleResult> {
|
||||
try $0.on(
|
||||
createArticleError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unableToParse) },
|
||||
createArticleSuccess: .init { .saved(created: try $0.created()) }
|
||||
createArticleSuccess: .init { .saved(created: try $0.created()) },
|
||||
createArticleError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unableToParse) }
|
||||
)
|
||||
}
|
||||
|
||||
@ -163,7 +163,6 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.CreateArticleSavingRequestResult> {
|
||||
try $0.on(
|
||||
createArticleSavingRequestError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .badData) },
|
||||
createArticleSavingRequestSuccess: .init {
|
||||
.saved(
|
||||
status: try $0.articleSavingRequest(
|
||||
@ -175,7 +174,8 @@ public extension DataService {
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
createArticleSavingRequestError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .badData) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ public extension DataService {
|
||||
data: Data,
|
||||
requestId: String
|
||||
) -> AnyPublisher<Void, SaveArticleError> {
|
||||
uploadFileRequestPublisher(pageScrapePayload: pageScrapePayload)
|
||||
uploadFileRequestPublisher(pageScrapePayload: pageScrapePayload, requestId: requestId)
|
||||
.flatMap { self.uploadFilePublisher(fileUploadConfig: $0, data: data) }
|
||||
.flatMap { self.saveFilePublisher(pageScrapePayload: pageScrapePayload, uploadFileId: $0, requestId: requestId) }
|
||||
.catch { _ in self.saveUrlPublisher(pageScrapePayload: pageScrapePayload, requestId: requestId) }
|
||||
@ -26,20 +26,21 @@ private struct UploadFileRequestPayload {
|
||||
|
||||
private extension DataService {
|
||||
// swiftlint:disable:next line_length
|
||||
func uploadFileRequestPublisher(pageScrapePayload: PageScrapePayload) -> AnyPublisher<UploadFileRequestPayload, SaveArticleError> {
|
||||
func uploadFileRequestPublisher(pageScrapePayload: PageScrapePayload, requestId: String?) -> AnyPublisher<UploadFileRequestPayload, SaveArticleError> {
|
||||
enum MutationResult {
|
||||
case success(payload: UploadFileRequestPayload)
|
||||
case error(errorCode: Enums.UploadFileRequestErrorCode?)
|
||||
}
|
||||
|
||||
let input = InputObjects.UploadFileRequestInput(
|
||||
url: pageScrapePayload.url,
|
||||
contentType: "application/pdf",
|
||||
url: pageScrapePayload.url
|
||||
createPageEntry: OptionalArgument(true),
|
||||
clientRequestId: OptionalArgument(requestId)
|
||||
)
|
||||
|
||||
let selection = Selection<MutationResult, Unions.UploadFileRequestResult> {
|
||||
try $0.on(
|
||||
uploadFileRequestError: .init { .error(errorCode: try? $0.errorCodes().first) },
|
||||
uploadFileRequestSuccess: .init {
|
||||
.success(
|
||||
payload: UploadFileRequestPayload(
|
||||
@ -48,7 +49,8 @@ private extension DataService {
|
||||
urlString: try $0.uploadSignedUrl()
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
uploadFileRequestError: .init { .error(errorCode: try? $0.errorCodes().first) }
|
||||
)
|
||||
}
|
||||
|
||||
@ -90,15 +92,13 @@ private extension DataService {
|
||||
|
||||
// swiftlint:disable:next line_length
|
||||
func uploadFilePublisher(fileUploadConfig: UploadFileRequestPayload, data: Data) -> AnyPublisher<String, SaveArticleError> {
|
||||
let pdfData = data // URL(string: "http://localhost:4000/local/debug/endpoint").flatMap { try? Data(contentsOf: $0) }
|
||||
|
||||
let url = fileUploadConfig.urlString.flatMap { URL(string: $0) }
|
||||
guard let url = url else { return Future { $0(.failure(.badData)) }.eraseToAnyPublisher() }
|
||||
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "PUT"
|
||||
request.addValue("application/pdf", forHTTPHeaderField: "content-type")
|
||||
request.httpBody = pdfData
|
||||
request.httpBody = data
|
||||
|
||||
return networker.urlSession.dataTaskPublisher(for: request)
|
||||
.tryMap { data, response -> String in
|
||||
@ -133,16 +133,16 @@ private extension DataService {
|
||||
}
|
||||
|
||||
let input = InputObjects.SaveFileInput(
|
||||
clientRequestId: requestId,
|
||||
url: pageScrapePayload.url,
|
||||
source: "ios-file",
|
||||
uploadFileId: uploadFileId,
|
||||
url: pageScrapePayload.url
|
||||
clientRequestId: requestId,
|
||||
uploadFileId: uploadFileId
|
||||
)
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SaveResult> {
|
||||
try $0.on(
|
||||
saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) },
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") },
|
||||
saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -12,17 +12,16 @@ public extension DataService {
|
||||
}
|
||||
|
||||
let input = InputObjects.SavePageInput(
|
||||
clientRequestId: requestId,
|
||||
originalContent: html,
|
||||
source: "ios-page",
|
||||
url: requestId,
|
||||
source: html,
|
||||
clientRequestId: "ios-page",
|
||||
title: OptionalArgument(title),
|
||||
url: pageScrapePayload.url
|
||||
originalContent: pageScrapePayload.url
|
||||
)
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SaveResult> {
|
||||
try $0.on(
|
||||
saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) },
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }, saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -12,15 +12,15 @@ public extension DataService {
|
||||
}
|
||||
|
||||
let input = InputObjects.SaveUrlInput(
|
||||
clientRequestId: requestId,
|
||||
url: pageScrapePayload.url,
|
||||
source: "ios-url",
|
||||
url: pageScrapePayload.url
|
||||
clientRequestId: requestId
|
||||
)
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SaveResult> {
|
||||
try $0.on(
|
||||
saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) },
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }
|
||||
saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") },
|
||||
saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -32,16 +32,16 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SetLabelsResult> {
|
||||
try $0.on(
|
||||
setLabelsError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },
|
||||
setLabelsSuccess: .init { .saved(feedItem: try $0.labels(selection: feedItemLabelSelection.list)) }
|
||||
setLabelsSuccess: .init { .saved(feedItem: try $0.labels(selection: feedItemLabelSelection.list)) },
|
||||
setLabelsError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.setLabels(
|
||||
input: InputObjects.SetLabelsInput(
|
||||
labelIds: labelIDs,
|
||||
pageId: itemID
|
||||
pageId: itemID,
|
||||
labelIds: labelIDs
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -33,12 +33,12 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.SaveArticleReadingProgressResult> {
|
||||
try $0.on(
|
||||
saveArticleReadingProgressError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) },
|
||||
saveArticleReadingProgressSuccess: .init {
|
||||
.saved(
|
||||
readingProgress: try $0.updatedArticle(selection: Selection.Article { try $0.readingProgressPercent() })
|
||||
)
|
||||
}
|
||||
},
|
||||
saveArticleReadingProgressError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) }
|
||||
)
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@ extension DataService {
|
||||
try $0.saveArticleReadingProgress(
|
||||
input: InputObjects.SaveArticleReadingProgressInput(
|
||||
id: itemID,
|
||||
readingProgressAnchorIndex: anchorIndex,
|
||||
readingProgressPercent: readingProgress
|
||||
readingProgressPercent: readingProgress,
|
||||
readingProgressAnchorIndex: anchorIndex
|
||||
),
|
||||
selection: selection
|
||||
)
|
||||
|
||||
@ -31,18 +31,18 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.UpdateHighlightResult> {
|
||||
try $0.on(
|
||||
updateHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) },
|
||||
updateHighlightSuccess: .init {
|
||||
.saved(highlight: try $0.highlight(selection: highlightSelection))
|
||||
}
|
||||
},
|
||||
updateHighlightError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) }
|
||||
)
|
||||
}
|
||||
|
||||
let mutation = Selection.Mutation {
|
||||
try $0.updateHighlight(
|
||||
input: InputObjects.UpdateHighlightInput(
|
||||
annotation: OptionalArgument(annotation),
|
||||
highlightId: highlightID,
|
||||
annotation: OptionalArgument(annotation),
|
||||
sharedAt: OptionalArgument(nil)
|
||||
),
|
||||
selection: selection
|
||||
|
||||
@ -90,7 +90,7 @@ extension DataService {
|
||||
case error(error: String)
|
||||
}
|
||||
|
||||
let articleSelection = Selection.Article {
|
||||
let articleContentSelection = Selection.Article {
|
||||
ArticleProps(
|
||||
item: InternalLinkedItem(
|
||||
id: try $0.id(),
|
||||
@ -121,18 +121,17 @@ extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.ArticleResult> {
|
||||
try $0.on(
|
||||
articleSuccess: .init {
|
||||
QueryResult.success(result: try $0.article(selection: articleContentSelection))
|
||||
},
|
||||
articleError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
articleSuccess: .init {
|
||||
QueryResult.success(result: try $0.article(selection: articleSelection))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
let query = Selection.Query {
|
||||
// backend has a hack that allows us to pass in itemID in place of slug
|
||||
try $0.article(slug: itemID, username: username, selection: selection)
|
||||
try $0.article(username: username, slug: itemID, selection: selection)
|
||||
}
|
||||
|
||||
let path = appEnvironment.graphqlPath
|
||||
|
||||
@ -12,11 +12,11 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.LabelsResult> {
|
||||
try $0.on(
|
||||
labelsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
labelsSuccess: .init {
|
||||
QueryResult.success(result: try $0.labels(selection: feedItemLabelSelection.list))
|
||||
},
|
||||
labelsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -24,9 +24,6 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.ArticlesResult> {
|
||||
try $0.on(
|
||||
articlesError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
articlesSuccess: .init {
|
||||
QueryResult.success(
|
||||
result: InternalHomeFeedData(
|
||||
@ -36,22 +33,25 @@ public extension DataService {
|
||||
})
|
||||
)
|
||||
)
|
||||
},
|
||||
articlesError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
let query = Selection.Query {
|
||||
try $0.articles(
|
||||
after: OptionalArgument(cursor),
|
||||
first: OptionalArgument(limit),
|
||||
includePending: OptionalArgument(true),
|
||||
query: OptionalArgument(searchQuery),
|
||||
sharedOnly: .present(false),
|
||||
sort: OptionalArgument(
|
||||
InputObjects.SortParams(
|
||||
by: .updatedTime, order: .present(.descending)
|
||||
order: .present(.descending), by: .updatedTime
|
||||
)
|
||||
),
|
||||
after: OptionalArgument(cursor),
|
||||
first: OptionalArgument(limit),
|
||||
query: OptionalArgument(searchQuery),
|
||||
includePending: OptionalArgument(true),
|
||||
selection: selection
|
||||
)
|
||||
}
|
||||
@ -90,20 +90,44 @@ public extension DataService {
|
||||
case error(error: String)
|
||||
}
|
||||
|
||||
let articleSelection = Selection.Article {
|
||||
InternalLinkedItem(
|
||||
id: try $0.id(),
|
||||
title: try $0.title(),
|
||||
createdAt: try $0.createdAt().value ?? Date(),
|
||||
savedAt: try $0.savedAt().value ?? Date(),
|
||||
readingProgress: try $0.readingProgressPercent(),
|
||||
readingProgressAnchor: try $0.readingProgressAnchorIndex(),
|
||||
imageURLString: try $0.image(),
|
||||
onDeviceImageURLString: nil,
|
||||
documentDirectoryPath: nil,
|
||||
pageURLString: try $0.url(),
|
||||
descriptionText: try $0.description(),
|
||||
publisherURLString: try $0.originalArticleUrl(),
|
||||
siteName: try $0.siteName(),
|
||||
author: try $0.author(),
|
||||
publishDate: try $0.publishedAt()?.value,
|
||||
slug: try $0.slug(),
|
||||
isArchived: try $0.isArchived(),
|
||||
contentReader: try $0.contentReader().rawValue,
|
||||
labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? []
|
||||
)
|
||||
}
|
||||
|
||||
let selection = Selection<QueryResult, Unions.ArticleResult> {
|
||||
try $0.on(
|
||||
articleError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
articleSuccess: .init {
|
||||
QueryResult.success(result: try $0.article(selection: articleSelection))
|
||||
},
|
||||
articleError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
let query = Selection.Query {
|
||||
// backend has a hack that allows us to pass in itemID in place of slug
|
||||
try $0.article(slug: itemID, username: username, selection: selection)
|
||||
try $0.article(username: username, slug: itemID, selection: selection)
|
||||
}
|
||||
|
||||
let path = appEnvironment.graphqlPath
|
||||
@ -130,7 +154,7 @@ public extension DataService {
|
||||
}
|
||||
}
|
||||
|
||||
private let articleSelection = Selection.Article {
|
||||
private let libraryArticleSelection = Selection.Article {
|
||||
InternalLinkedItem(
|
||||
id: try $0.id(),
|
||||
title: try $0.title(),
|
||||
@ -155,5 +179,5 @@ private let articleSelection = Selection.Article {
|
||||
}
|
||||
|
||||
private let articleEdgeSelection = Selection.ArticleEdge {
|
||||
try $0.node(selection: articleSelection)
|
||||
try $0.node(selection: libraryArticleSelection)
|
||||
}
|
||||
|
||||
@ -20,9 +20,6 @@ extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.SearchResult> {
|
||||
try $0.on(
|
||||
searchError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
searchSuccess: .init {
|
||||
QueryResult.success(
|
||||
result: LinkedItemIDFetchResult(
|
||||
@ -32,6 +29,9 @@ extension DataService {
|
||||
})
|
||||
)
|
||||
)
|
||||
},
|
||||
searchError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -20,11 +20,11 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.NewsletterEmailsResult> {
|
||||
try $0.on(
|
||||
newsletterEmailsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
newsletterEmailsSuccess: .init {
|
||||
QueryResult.success(result: try $0.newsletterEmails(selection: newsletterEmailSelection.list))
|
||||
},
|
||||
newsletterEmailsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -26,11 +26,11 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<QueryResult, Unions.SubscriptionsResult> {
|
||||
try $0.on(
|
||||
subscriptionsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
},
|
||||
subscriptionsSuccess: .init {
|
||||
QueryResult.success(result: try $0.subscriptions(selection: subsciptionSelection.list))
|
||||
},
|
||||
subscriptionsError: .init {
|
||||
QueryResult.error(error: try $0.errorCodes().description)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user