Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApolloPagination usage docs #262

Merged
merged 31 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
557bea7
Add ApolloPagination to the DocC generation project
Iron-Ham Feb 9, 2024
4e776ea
A short intro guide to Apollo Pagination
Iron-Ham Feb 9, 2024
ede7488
Comments (1)
Iron-Ham Feb 13, 2024
103aefc
Cleanup existing content
Iron-Ham Feb 13, 2024
1a1a273
Field => Property
Iron-Ham Feb 13, 2024
3bc1675
Second page: Using custom response models
Iron-Ham Feb 13, 2024
8ba1d79
Third page: Directionality
Iron-Ham Feb 13, 2024
644649e
Multi-query pager
Iron-Ham Feb 13, 2024
e7c1b00
Offset
Iron-Ham Feb 13, 2024
30529e8
One more
Iron-Ham Feb 13, 2024
f1cae88
Generated docs again
Iron-Ham Feb 22, 2024
0786446
Touchup
Iron-Ham Feb 22, 2024
fee7e30
Re-generate docs
Iron-Ham Feb 22, 2024
bb153dd
Update intro
Iron-Ham Feb 22, 2024
750183a
Update Custom-Types
Iron-Ham Feb 22, 2024
87f0f9e
Move to Directional Pag
Iron-Ham Feb 22, 2024
2cbab20
Update directional
Iron-Ham Feb 22, 2024
d72e23c
Update multi-query
Iron-Ham Feb 22, 2024
fb1fcff
Rename in sidebar
Iron-Ham Feb 22, 2024
0a56b1a
Update cancel() function [breaking change]
Iron-Ham Feb 23, 2024
167544b
Update docs/source/pagination/introduction.mdx
Iron-Ham Feb 23, 2024
f9c9d05
Update docs/source/pagination/introduction.mdx
Iron-Ham Feb 23, 2024
5aee925
Update docs/source/pagination/custom-types.mdx
Iron-Ham Feb 23, 2024
e220678
Update docs/source/pagination/custom-types.mdx
Iron-Ham Feb 23, 2024
321bf95
Update docs/source/pagination/custom-types.mdx
Iron-Ham Feb 23, 2024
40a6414
Update docs/source/pagination/directional-pagers.mdx
Iron-Ham Feb 23, 2024
fe66eec
Update docs/source/pagination/multi-query.mdx
Iron-Ham Feb 23, 2024
bdc33be
Update docs/source/pagination/multi-query.mdx
Iron-Ham Feb 23, 2024
dc5fc9e
Update docs/source/pagination/multi-query.mdx
Iron-Ham Feb 23, 2024
c101fbf
Update cancel docs
Iron-Ham Feb 23, 2024
2581199
Again
Iron-Ham Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions SwiftScripts/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let package = Package(
dependencies: [
.package(name: "Apollo", path: "../apollo-ios"),
.package(name: "ApolloCodegen", path: "../apollo-ios-codegen"),
.package(name: "ApolloPagination", path: "../apollo-ios-pagination"),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
],
Expand Down Expand Up @@ -40,6 +41,7 @@ let package = Package(
.product(name: "ApolloAPI", package: "Apollo"),
.product(name: "ApolloSQLite", package: "Apollo"),
.product(name: "ApolloWebSocket", package: "Apollo"),
.product(name: "ApolloPagination", package: "ApolloPagination"),
.target(name: "SwiftScriptHelpers")
]
),
Expand Down
1 change: 1 addition & 0 deletions SwiftScripts/Sources/DocumentationGenerator/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Target: String, CaseIterable {
case ApolloSQLite
case ApolloWebSocket
case ApolloCodegenLib
case ApolloPagination

var name: String {
self.rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ public class AsyncGraphQLQueryPager<Model>: Publisher {
/// Resets pagination state and cancels further updates from the pager.
public func cancel() async {
await pager.cancel()
_subject.send(completion: .finished)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update unit tests for this? Can also be done in a separate PR later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that'd be wise, yes.
As written, I think this would require us to re-init a new pager – in the same sense that cancelling a watcher stops it from being used again.

cancellables.removeAll()
}

public func receive<S>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public extension GraphQLQueryPager {
client: ApolloClientProtocol,
watcherDispatchQueue: DispatchQueue = .main,
initialQuery: InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery?,
extractPageInfo: @escaping (InitialQuery.Data) -> P
) -> GraphQLQueryPager where Model == PaginationOutput<InitialQuery, InitialQuery> {
GraphQLQueryPager(pager: GraphQLQueryPagerCoordinator(
Expand All @@ -27,7 +27,7 @@ public extension GraphQLQueryPager {
client: ApolloClientProtocol,
watcherDispatchQueue: DispatchQueue = .main,
initialQuery: InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery?,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnthonyMDev I can pull this out of this PR if you prefer and into a second – but I noticed that the pageResolver wasn't expecting an Optional<InitialQuery> in the GraphQLQueryPager definitions, but was in the AsyncGraphQLQueryPager definitions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, that's fine!

extractPageInfo: @escaping (InitialQuery.Data) -> P,
transform: @escaping ([InitialQuery.Data], InitialQuery.Data, [InitialQuery.Data]) throws -> Model
) -> GraphQLQueryPager {
Expand All @@ -48,7 +48,7 @@ public extension GraphQLQueryPager {
client: ApolloClientProtocol,
watcherDispatchQueue: DispatchQueue = .main,
initialQuery: InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery,
pageResolver: @escaping (P, PaginationDirection) -> InitialQuery?,
extractPageInfo: @escaping (InitialQuery.Data) -> P,
transform: @escaping (InitialQuery.Data) throws -> Model
) -> GraphQLQueryPager where Model: RangeReplaceableCollection, T == Model.Element {
Expand All @@ -72,7 +72,7 @@ public extension GraphQLQueryPager {
watcherDispatchQueue: DispatchQueue = .main,
extractInitialPageInfo: @escaping (InitialQuery.Data) -> P,
extractNextPageInfo: @escaping (PaginatedQuery.Data) -> P,
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery?
) -> GraphQLQueryPager where Model == PaginationOutput<InitialQuery, PaginatedQuery> {
GraphQLQueryPager(
pager: .init(
Expand All @@ -95,7 +95,7 @@ public extension GraphQLQueryPager {
watcherDispatchQueue: DispatchQueue = .main,
extractInitialPageInfo: @escaping (InitialQuery.Data) -> P,
extractNextPageInfo: @escaping (PaginatedQuery.Data) -> P,
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery,
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery?,
transform: @escaping ([PaginatedQuery.Data], InitialQuery.Data, [PaginatedQuery.Data]) throws -> Model
) -> GraphQLQueryPager where Model == PaginationOutput<InitialQuery, PaginatedQuery> {
GraphQLQueryPager(
Expand All @@ -120,7 +120,7 @@ public extension GraphQLQueryPager {
watcherDispatchQueue: DispatchQueue = .main,
extractInitialPageInfo: @escaping (InitialQuery.Data) -> P,
extractNextPageInfo: @escaping (PaginatedQuery.Data) -> P,
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery,
pageResolver: @escaping (P, PaginationDirection) -> PaginatedQuery?,
initialTransform: @escaping (InitialQuery.Data) throws -> Model,
pageTransform: @escaping (PaginatedQuery.Data) throws -> Model
) -> GraphQLQueryPager where Model: RangeReplaceableCollection, T == Model.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public class GraphQLQueryPager<Model>: Publisher {
/// Resets pagination state and cancels further updates from the pager.
public func cancel() {
pager.cancel()
_subject.send(completion: .finished)
cancellables.removeAll()
}

public func receive<S>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@
"text" : " conforms to ",
"type" : "text"
},
{
"code" : "AnyScalarType",
"type" : "codeVoice"
},
{
"text" : " and ",
"type" : "text"
},
{
"code" : "Hashable",
"type" : "codeVoice"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"defaultImplementationsSections" : [
{
"identifiers" : [
"doc:\/\/ApolloAPI\/documentation\/ApolloAPI\/GraphQLOperation\/operationType-90ybj",
"doc:\/\/ApolloAPI\/documentation\/ApolloAPI\/GraphQLOperation\/operationType-370r3",
"doc:\/\/ApolloAPI\/documentation\/ApolloAPI\/GraphQLOperation\/operationType-5e63x",
"doc:\/\/ApolloAPI\/documentation\/ApolloAPI\/GraphQLOperation\/operationType-90ybj"
"doc:\/\/ApolloAPI\/documentation\/ApolloAPI\/GraphQLOperation\/operationType-5e63x"
],
"title" : "GraphQLOperation Implementations"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@
"type" : "text"
},
{
"code" : "AnyScalarType",
"code" : "JSONEncodable",
"type" : "codeVoice"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@
"text" : " conforms to ",
"type" : "text"
},
{
"code" : "AnyScalarType",
"type" : "codeVoice"
},
{
"text" : " and ",
"type" : "text"
},
{
"code" : "Hashable",
"type" : "codeVoice"
Expand Down Expand Up @@ -446,7 +454,7 @@
"type" : "text"
},
{
"code" : "AnyScalarType",
"code" : "JSONEncodable",
"type" : "codeVoice"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@
"doc://ApolloCodegenLib/documentation/ApolloCodegenLib/ApolloCodegenConfiguration/OutputOptions/pruneGeneratedFiles": {
"abstract" : [
{
"text" : "Whether unused generated files will be automatically deleted.",
"text" : "Whether unused previously generated files will be automatically deleted.",
"type" : "text"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"abstract" : [
{
"text" : "Whether unused generated files will be automatically deleted.",
"text" : "Whether unused previously generated files will be automatically deleted.",
"type" : "text"
}
],
Expand Down Expand Up @@ -520,7 +520,7 @@
"doc://ApolloCodegenLib/documentation/ApolloCodegenLib/ApolloCodegenConfiguration/OutputOptions/pruneGeneratedFiles": {
"abstract" : [
{
"text" : "Whether unused generated files will be automatically deleted.",
"text" : "Whether unused previously generated files will be automatically deleted.",
"type" : "text"
}
],
Expand Down
Loading
Loading