-
Notifications
You must be signed in to change notification settings - Fork 57
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] Update PaginationOutput
to operate over GraphQLResult
s
#428
Conversation
👷 Deploy request for apollo-ios-docc pending review.Visit the deploys page to approve it
|
👷 Deploy request for eclectic-pie-88a2ba pending review.Visit the deploys page to approve it
|
errors
via the errors
response key
fb3d589
to
37a82e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you’re still working on getting this PR passing CI. But I’m doing some code review now and I’m having a hard time understanding some of the changes made here. Adding this PaginationResult feels like it adds a lot of complexity, both internally and in the consumption of the API in calling code.
This also seems to be concatenating all errors from individual pages into one [errors]
array on the PaginationResult
. That is not ideal, as it will be difficult to understand which errors came from which requests and trace them back using the error path
and location
.
As is often the case, this is becoming a lot more involved than was originally anticipated to solve the issues in apollographql/apollo-ios#3413. I'm wondering if there is a different approach to addressing that without making such sweeping changes.
I'm not sure if this is the right approach either, but would it be possible to keep the transform
APIs, but change them to expose the errors for each query? That could allow users to determine if they want to ignore and suppress those errors or expose them however they see fit. This could mean we are just pushing off the difficulty of dealing with per-page errors to the users, rather than handling them ourselves though...
apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPager.swift
Outdated
Show resolved
Hide resolved
f5e5d91
to
e5699dc
Compare
4a80d6c
to
cefeafb
Compare
cefeafb
to
7248770
Compare
cc: @AnthonyMDev |
errors
via the errors
response keyPaginationOutput
to operate over GraphQLResult
s
cc: @AnthonyMDev would it be helpful to split this into a few smaller PRs? |
b591b09c [ApolloPagination] Update `PaginationOutput` to operate over `GraphQLResult`s (#428) git-subtree-dir: apollo-ios-pagination git-subtree-split: b591b09cc9891e16d699925be4fb706b37ff2714
…aginationOutput` to operate over `GraphQLResult`s git-subtree-dir: apollo-ios-pagination git-subtree-mainline: a17a165 git-subtree-split: b591b09cc9891e16d699925be4fb706b37ff2714
|
||
extension PaginationOutput where InitialQuery == PaginatedQuery { | ||
public var allData: [InitialQuery.Data] { | ||
previousPages.compactMap(\.data) + [initialPage?.data].compactMap { $0 } + nextPages.compactMap(\.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super
Closes: apollographql/apollo-ios#3413
Caution
This is a breaking change.
The goal of this PR is two-fold:
loadAll
, where some cases may lead to continued retries of fetching data.Changes
Broken down into:
Exposing Errors
Changing the stored values of
PaginationOutput
We started by changing the stored values of
PaginationOutput
to beGraphQLResult<GraphQLQuery.Data
, instead of theGraphQLQuery.Data
: See this diff for detail.Changing the
Output
types ofGraphQLQueryPager
With the changes to
PaginationOutput
in place, with each page containing aSource
(i.e.,cache
orserver
) via itsGraphQLResult
, we made the choice to modify theOutput
values of bothGraphQLQueryPager
andAsyncGraphQLQueryPager
such that those values are no longer tuples of(Model, UpdateSource)
and are instead justModel
: 1 2.Improving
loadAll
To correctly handle errors within
loadAll
, we first detect whether an error occurred and use that error to setisLoadingAll
tofalse
(1), which forces an exit ofloadAll
.Storing the most recent result
This is important in order to know the most recent
Source
of an update, as well as theerrors
key of the most recent update. 1Simplifying Usage
Changes to
subscribe
We marked the
subscribe
methods of bothGraphQLQueryPager
andAsyncGraphQLQueryPager
as deprecated: 1 2. This is because the subscribe method was already redundant: TheGraphQLQueryPager
andAsyncGraphQLQueryPager
are CombinePublisher
s, and a consumer of the API can subscribe to them by callingsink
.Removal of Initializers
In conjunction with the changes related to errors, we've removed various initializers that were no longer valid given the change in return types. We considered removal of all convenience initializers and initializers that contain a
transform
function, but found them useful in specific applications. For example, some consumers of the library must have an output type that is not constrained to any underlyingQuery
, as the underlyingQuery
may be different. For those consumers, thetransform:
initializers remain. For all others, however, it's highly recommended that the standardtransform
-less initializer is used, as it retains information about the most recent value, errors within, and so on.New computed properties
Some users have made note that they commonly employ a bit of code like this one:
We've added a computed property that should automatically do that for you if the pages are of the same type, as well as a computed property that surfaces all data.
Similarly, we've added a computed property that surfaces all errors from all pages.
Other Changes
We've removed conformance to
Equatable
onGraphQLQueryPager
, as it doesn't make much sense – we were previously comparing the equatability of the current values – but not of the underlying data or state of the pager. 1 2We've renamed the
fetch
case ofUpdateSource
toserver
, to be more in line withGraphQLResult.Source
. 1.Impact
The impact of this PR is:
GraphQLQueryPager
loadAll
can no longer short-circuit.