-
Notifications
You must be signed in to change notification settings - Fork 656
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
Feature application interceptors #428
Feature application interceptors #428
Conversation
… feature-extensible-interceptors
… feature-extensible-interceptors
@@ -84,6 +88,7 @@ private ApolloClient(Builder builder) { | |||
this.defaultHttpCacheControl = builder.defaultHttpCacheControl; | |||
this.defaultCacheControl = builder.defaultCacheControl; | |||
this.logger = builder.apolloLogger; | |||
this.applicationInterceptors = builder.applicationInterceptors; |
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.
pls wrap this into Collections.unmodifiableList()
or even earlier in ApolloClient.Builder
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.
Never mind we don't set in builder the list of interceptors but add them one by one
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.
Well, the initial thought was to wrap it in an unmodifiable list, but then I realized that we are not exposing the list of interceptors in any way to the clients, so it might as well just remain a simple List.
applicationInterceptors); | ||
} | ||
|
||
private List<ApolloInterceptor> getInterceptors() { |
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.
just a nit: we usually omit get
prefixes. So I guess we can make this method to return RealApolloInterceptorChain
so to have smth like this:
private ApolloInterceptorChain prepareInterceptorChain(Operation operation, List< ApolloInterceptor> applicationInterceptors) {
...
return new RealApolloInterceptorChain(operation, interceptors);
}
|
||
@Test | ||
public void syncApplicationInterceptorCanShortCircuitResponses() throws IOException, ApolloException { | ||
mockWebServer.shutdown(); |
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.
Do we need this?
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.
Yeah, we do need this, so as to ensure that response is indeed the intercepted response and not from the server.
.build(); | ||
} | ||
|
||
@NonNull private InterceptorResponse getInterceptorResponse(EpisodeHeroName query) { |
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.
nit: we don't like get
prefixes :)
|
||
Response<EpisodeHeroName.Data> actualResponse = client.newCall(query).execute(); | ||
|
||
assertThat(expectedResponse.parsedResponse.get()).isEqualTo(actualResponse); |
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.
would be nice if we check that other interceptors aren't called.
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 am wondering how can we test that the other interceptors aren't called? Maybe check that the httpResponse
& cachedResponse
are equal to the fake ones that we pass to the interceptedResponse
? But that would tell us nothing about other interceptors being called or not called.
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.
Just minor comments.
Overall we don't really use get
prefixes.
Maybe test should go to apollo-runtime itself as it more junit test then integration (it doesn't need to run apollo compiler etc)
@sav007 It would be difficult to move this class to the apollo-runtime module because InterceptorTest class needs objects like |
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.
Pls change withCustomTypeAdapter
to addCustomTypeAdapter
and applicationInterceptor
to addApplicationInterceptor
in ApolloClient builder be consistent and that is what OkHttp.Builder does.
…adhera/apollo-android into feature-extensible-interceptors
@sav007 Changed the method names as requested. If everything else looks fine, we can go ahead and merge it. |
@sav007 Oh btw, do you have any inputs on how we can test that the rest of the interceptors are not called when we short circuit responses? |
create a unit tests for RealApolloInterceptorChain add couple interceptors and make one of them to return value right away. Then call |
… feature-extensible-interceptors
@sav007 Added the test which checks that other interceptors are not called when one of the the interceptors short circuits the response. Also made changes to the docs of the corresponding builder method to reflect the same. |
@VisheshVadhera sorry to request so much, but could you please add additional test to verify if |
Np, I'll be happy to add them, the more tests we have the better it is for
the project.
…On 20 Apr 2017 8:45 pm, "Ivan Savytskyi" ***@***.***> wrote:
@VisheshVadhera <https://github.com/VisheshVadhera> sorry to request so
much, but could you please add additional test to verify if
com.apollographql.apollo.interceptor.ApolloInterceptorChain#dispose is
called for application interceptors as well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#428 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD1DEA9xf0ubMM68j9-f1TURW5VlZ04Jks5rx3aLgaJpZM4NAI6_>
.
|
@sav007 Added a test case for the dispose method, plus a couple more for asyncInterceptors. Also I realized we don't have tests for ApolloInterceptorChain. Want me to open another PR? |
lgtm |
Yup please do that in the next pr to keep this one from growing anymore |
… feature-extensible-interceptors
Merging? |
Lgtm
…On Apr 21, 2017 6:56 PM, "Ivan Savytskyi" ***@***.***> wrote:
Merging?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#428 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEUX3MBiNaSwew37DkD8nX-NnyLFWrQVks5ryTQ5gaJpZM4NAI6_>
.
|
Closes #346