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

Feature application interceptors #428

Merged

Conversation

VisheshVadhera
Copy link
Contributor

Closes #346

@@ -84,6 +88,7 @@ private ApolloClient(Builder builder) {
this.defaultHttpCacheControl = builder.defaultHttpCacheControl;
this.defaultCacheControl = builder.defaultCacheControl;
this.logger = builder.apolloLogger;
this.applicationInterceptors = builder.applicationInterceptors;
Copy link
Contributor

@sav007 sav007 Apr 18, 2017

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

Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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();
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 this?

Copy link
Contributor Author

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) {
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

@VisheshVadhera VisheshVadhera Apr 19, 2017

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.

Copy link
Contributor

@sav007 sav007 left a 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)

@VisheshVadhera
Copy link
Contributor Author

VisheshVadhera commented Apr 19, 2017

@sav007 It would be difficult to move this class to the apollo-runtime module because InterceptorTest class needs objects like NamedCountdownLatch & EpisodeHeroName which are only available in the apollo-integration module. Moving it to apollo-runtime would mean adding apollo-integration as a dependency for apollo-runtime which we don't want.

Copy link
Contributor

@sav007 sav007 left a 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
@VisheshVadhera
Copy link
Contributor Author

@sav007 Changed the method names as requested. If everything else looks fine, we can go ahead and merge it.

@VisheshVadhera
Copy link
Contributor Author

@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?

@sav007
Copy link
Contributor

sav007 commented Apr 19, 2017

create a unit tests for RealApolloInterceptorChain add couple interceptors and make one of them to return value right away. Then callinterceptorChain.proceed() and check if only those interceptors who supposed to be are called

@VisheshVadhera
Copy link
Contributor Author

@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.

@sav007
Copy link
Contributor

sav007 commented Apr 20, 2017

@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.

@VisheshVadhera
Copy link
Contributor Author

VisheshVadhera commented Apr 20, 2017 via email

@VisheshVadhera
Copy link
Contributor Author

@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?

@digitalbuddha
Copy link
Contributor

lgtm

@digitalbuddha
Copy link
Contributor

Yup please do that in the next pr to keep this one from growing anymore

@sav007
Copy link
Contributor

sav007 commented Apr 21, 2017

Merging?

@digitalbuddha
Copy link
Contributor

digitalbuddha commented Apr 21, 2017 via email

@sav007 sav007 merged commit 367104e into apollographql:master Apr 21, 2017
@VisheshVadhera VisheshVadhera deleted the feature-extensible-interceptors branch May 4, 2017 05:49
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.

3 participants