GET as a transport option instead of a parameter + ErrorCancellable #599
GET as a transport option instead of a parameter + ErrorCancellable #599designatednerd merged 18 commits intomasterfrom
Conversation
| // MARK: - Early-Exit Helper | ||
|
|
||
| /// A class to return when an error that should cause us to bail out of something still needs to return `Cancellable`. | ||
| public final class ErrorCancellable: Cancellable { |
There was a problem hiding this comment.
I'm wondering if this should really be tied to errors, or whether something more generic like an EmptyCancellable or NullCancellable (from null object pattern), would make sense.
There was a problem hiding this comment.
Ooh good call - EmptyCancellable is way more accurate
… need `Cancelable` after a completion handler has been called.
…everywhere; FetchHTTPMethod -> GraphQLHTTPMethod
(These are no longer necessary)
d2059ab to
6a89b50
Compare
dmandarino
left a comment
There was a problem hiding this comment.
@designatednerd thank you for considering me in this PR and for asking for my opinion.
I just did as parameter, so the user can choose between GET and POST whenever he/she wants to without instantiating Apollo again. And I thought that int the future, persisted query would be a parameter too.
But I checked out on others proposes in issues and open PR, and most of them are suggesting to use it as a property in HTTPNetworkTranspot. So I agree with this solution and that it looks better in this way, since WebSocket was ignoring the HTTPMethod parameter.
And I liked the way you solved the Cancellable issue and return. Nice!
| } else { | ||
| completionHandler(nil, GraphQLHTTPRequestError(kind: .serializedQueryParamsMessageError)) | ||
| completionHandler(nil, GraphQLHTTPRequestError.serializedQueryParamsMessageError) | ||
| return EmptyCancellable() |
|
@designatednerd: Perhaps I'm thinking too big picture here, but it might be worthwhile to look how custom extensions will evolve as
... we've been using NetworkTransports to compose different layers of behavior together into one larger NetworkTransport. For example, we have one NetworkTransport for Authentication-retries (i.e. when the user has to request a token from the server to continue requests), and (as of yesterday) one for PersistedQuery management. If the GET query option is baked into |
|
@SirensOfTitan Definitely good to keep the big picture in mind but I think at this point, particularly given that a) We're at a |
|
I agree with @designatednerd. People are asking for it since 2017 and there were issues opened last year too. The implementation may change in the future while the project goes on, and the need changes. |
|
@designatednerd @dmandarino Sorry, I'm not arguing against GET, I'm saying that the general, fuzzy idea of how the API will evolve could act as a useful heuristic as to whether we should keep GET as a parameter in |
|
Totally understand your point @SirensOfTitan, but at this point I want to get this out the door for day to day usage. I'm definitely planning on revisiting some of this architecture when I get the bugs to a manageable point, but with 173 open issues (as of right this second) that may be a minute 😃 |
# Conflicts: # Sources/Apollo/ApolloClient.swift # Sources/Apollo/GraphQLQueryWatcher.swift

I had a chat with @martijnwalraven about how using
GETvsPOSTwas handled in #572, and he had a couple good points I missed in the review: First, passing the fetch method as a parameter doesn't make sense if it's going to eventually be handed off to a web socket, since it'll ignore that parameter anyway. Second, if someone wants to useGETfor a fetch request, they almost certainly want to use it for all fetch requests.His suggestion (which I agreed with and implement here) was to use a parameter on the
HTTPNetworkTransportto set whether fetches should useGETorPOST- I left the default asPOSTto match existing behavior, but I think this will make things a lot simpler for the end user.@dmandarino I'd love to hear your thoughts on this as it's a pretty significant change to what you proposed, but I think with the same end result.
Also in this PR:
ErrorCancelablereturn type which allows you to return aCancellableafter encountering an error that should early-exit..xcodeprojfiles to ensure 2-space formatting for the Apollo projects (note: Didn't fix any existing 4-space formatting, will do that in a separate PR when I have more time)