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

Response body empty when response caching configured #289

Closed
venushka opened this issue Dec 26, 2020 · 1 comment · Fixed by #290
Closed

Response body empty when response caching configured #289

venushka opened this issue Dec 26, 2020 · 1 comment · Fixed by #290
Labels

Comments

@venushka
Copy link

When GraphQLConfiguration is built with a GraphQLResponseCacheManager instance, the HTTP response body is empty. The servlet is created as follows,

public class GraphQLServlet extends GraphQLHttpServlet {

  ...

  @Override
  protected GraphQLConfiguration getConfiguration() {
    return GraphQLConfiguration
        .with(graphQLSchemaService)
        .with(graphQLResponseCacheManager)
        .build();
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Build the GraphQLConfiguration with a GraphQLResponseCacheManager as shown above.
  2. Make a GraphQL request to the servlet
  3. Response body is empty with a 200 OK response code.

Expected behavior
Result of the GraphQL query execution

Additional context
Looking through the code, it seems like the issue is in the following bit of code.

boolean returnedFromCache;
try {
returnedFromCache = !CacheReader.responseFromCache(
invocationInput, request, response, configuration.getResponseCacheManager()
);

The CacheReader returns false if the content is not served from cache, and here the returnedFromCache is set to the negate of the return value making it true.

This means the following condition is not met, so the query is not processed by the HttpRequestInvoker, resulting in no response in being sent to the client.

if (!returnedFromCache) {
requestInvoker.execute(invocationInput, request, response);
}

I think the fix is to just remove the ! in the following line, which seems to align with the naming of the variable and the associated comment.

With this change, it works as expected locally. Would be great to get this fixed and released.

p.s. Its great to have response caching supported, many thanks!

@venushka venushka added the bug label Dec 26, 2020
@oliemansm oliemansm linked a pull request Dec 26, 2020 that will close this issue
@venushka
Copy link
Author

Thanks for getting this fixed so quickly! @oliemansm

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

Successfully merging a pull request may close this issue.

1 participant