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

Create a protocol for public methods of Apollo client #693

Closed
wants to merge 1 commit into from

Conversation

gsabran
Copy link

@gsabran gsabran commented Aug 5, 2019

This is so that developers can refer to the protocol instead of the concrete type, and use dependency injection for unit testing. It doesn't break any public APIs.

Copy link
Contributor

@designatednerd designatednerd left a comment

Choose a reason for hiding this comment

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

Really like the idea in general but there's a "fun" corner of POP that I think will bite us here.

public extension ApolloClientProtocol {

@discardableResult func fetch<Query: GraphQLQuery>(query: Query, cachePolicy: CachePolicy = .returnCacheDataElseFetch, context: UnsafeMutableRawPointer? = nil, queue: DispatchQueue = DispatchQueue.main, resultHandler: GraphQLResultHandler<Query.Data>? = nil) -> Cancellable {
return fetch(query: query, cachePolicy: cachePolicy, context: context, queue: queue, resultHandler: resultHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing to watch out for with these default implementations is that they will override the local implementation anywhere that the client is passed as ApolloClientProtocol. This is an extremely oversimplified example of that behavior.

I would recommend removing the default implementations here and just setting the default params on the actual implementations, since it seems like the default implementations are just there to re-add the default parameters.

@designatednerd designatednerd added this to the 0.15.0 milestone Aug 6, 2019
@designatednerd
Copy link
Contributor

@gsabran Would love to get this in with 0.15.0 - planning on some other changes that can make mocking easier as well, seems to fit well with those changes. LMK if you have questions on my feedback!

@designatednerd
Copy link
Contributor

Hey @gsabran - If I don't hear back from you by tomorrow, I'm going to take over this PR so I can get it shipped. Excellent idea!

@designatednerd
Copy link
Contributor

Closing in favor of #715 since there hasn't been any movement on this and I'd still like to get it out with 0.15.0.

@gsabran
Copy link
Author

gsabran commented Aug 18, 2019

Hi thanks a lot for taking over, and sorry for not following up at all.. I left for vacations :)

@designatednerd
Copy link
Contributor

Haha, yep, I figured. 'Tis August after all. Thanks for the idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants