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

Support send HttpGetMethod for Persisted Queries #1376

Conversation

Codebear98
Copy link
Contributor

  • Support APQs with CDN through useHttpGetMethodForPersistedQueries

Ref. Integrate APQs with CDN

Implemented useHttpGetMethodForPersistedQueries which sends with HttpGetMethod when it's a persisted query request, otherwise send HttpGetMethod or HttpPostMethod depends on global setting of useHttpGetMethodForQueries.

Example

ApolloClient.builder()
.enableAutoPersistedQueries(true)
.useHttpGetMethodForPersistedQueries(true)
.build()

ref. #1317 #1055

@Codebear98 Codebear98 marked this pull request as ready for review June 18, 2019 06:57
@@ -20,15 +20,27 @@

private final ApolloLogger logger;
private volatile boolean disposed;
private boolean useHttpGetMethodForQueries;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this flag can be local in interceptAsync ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

InterceptorRequest newRequest = request.toBuilder()
.sendQueryDocument(false)
.autoPersistQueries(true)
.useHttpGetMethodForQueries(useHttpGetMethodForQueries || useHttpGetMethodForPersistedQueries)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: think can be replaced with:

.useHttpGetMethodForQueries(request.useHttpGetMethodForQueries || useHttpGetMethodForPersistedQueries)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced, thanks!

return Optional.of(request.toBuilder()
.sendQueryDocument(true)
.autoPersistQueries(true)
.useHttpGetMethodForQueries(useHttpGetMethodForQueries)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we don't need this as request is our original request (not modified). So it will have already set this flag.

See line with:

chain.proceedAsync(newRequest, dispatcher, new CallBack() {
      @Override public void onResponse(@NotNull InterceptorResponse response) {
        if (disposed) return;
        Optional<InterceptorRequest> retryRequest = handleProtocolNegotiation(request, response);

request is original request not modified.

Copy link
Contributor Author

@Codebear98 Codebear98 Jun 19, 2019

Choose a reason for hiding this comment

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

yes you r right, as original request is preserved, can reuse that one. Fixed as suggestion above.

Beware that we still need to send the http body with extension.persistedQuery for creating PQ cache in server for later request. So we need .sendQueryDocument(true) and .autoPersistQueries(true) and guarantee original request has those value on.

And its value now depends in RealApolloCall.java line. 139

    ApolloInterceptor.InterceptorRequest request = ApolloInterceptor.InterceptorRequest.builder(operation)
        .cacheHeaders(cacheHeaders)
        .requestHeaders(requestHeaders)
        .fetchFromCache(false)
        .optimisticUpdates(optimisticUpdates)
        .useHttpGetMethodForQueries(useHttpGetMethodForQueries)
        .autoPersistQueries(enableAutoPersistedQueries)
        .build();
    interceptorChain.proceedAsync(request, dispatcher, interceptorCallbackProxy());
  }

@Codebear98 Codebear98 force-pushed the feature/support_httpget_for_persistedqueries2 branch from 56bbd15 to b35c6b4 Compare June 24, 2019 04:07
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.

LGTM!

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