Graphql-engine: Add support for etag header

Created on 28 Aug 2019  路  12Comments  路  Source: hasura/graphql-engine

As you are going to support gzip in https://github.com/hasura/graphql-engine/issues/1253, do you consider to implement etag, in order to improve performances when data does not change?

server quickfix enhancement high

All 12 comments

@0x777 any comment about this one?

@rakeshkky will check if it can be easily added to the existing PR which adds support for compression.

It can also be implemented later, to avoid delaying the next release which includes compression.

However, etag looks easier to implement than compression as the hash implementation is not part of the etag specification. Any hash library will do the job.

https://www.logicbig.com/quick-info/web/etag-header.html

https://tools.ietf.org/html/rfc2616#section-14.19

@rakeshkky what do you think about this?

For rarely updated data, the benefits of etag header would be huge.

@Toub Soon we'll work on this. :slightly_smiling_face:

Hi @Toub, I've implemented the ETag header support in https://github.com/hasura/graphql-engine/pull/3311.
Can you please test the preview app https://hge-ci-pull-3311.herokuapp.com/ or just you can use the image hasura/graphql-engine:pull3311-df687332 to deploy and test it anywhere.

Thank you.

Great news!

Sure I will test it!

But I am just leaving for holidays tomorrow morning, back in 2 weeks!

The Etag header value looks good.

However, the browser (Chrome or Firefox) does not automatically add the If-None-Match header when using graphiql explorer, so if I run multiple times the same query within the explorer, I get the full 200 response again.

If I manually add the If-None-Match header in Firefox dev tools, I successfully get a 304 Not Modified response.

Maybe because the Etag header should be sent inside quotes:

Could you try to add theses quotes in the response?

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag

Hi @Toub, I made a change to double-quote the generated ETag value in the latest commit of #3311. Please test out the preview build present in https://github.com/hasura/graphql-engine/pull/3311#issuecomment-559006034.

Thank you.

The browser behavior remains the same.

According to the HTTP specification 14.26 If-None-Match, I guess the problem is the POST HTTP method used here to retrieve data.

if the request method was GET or HEAD, the server SHOULD respond with a 304 (Not Modified) response, including the cache- related header fields (particularly ETag) of one of the entities that matched. For all other request methods, the server MUST respond with a status of 412 (Precondition Failed).

Is Hasura graphql server compatible with HTTP GET queries ?

https://graphql.org/learn/serving-over-http/

Thanks for this efforts with this issue.
It is probably not as simple to implement that I initially thought.

@Toub Indeed, I thought the same.

The issue for HTTP GET queries https://github.com/hasura/graphql-engine/issues/574. Please comment about your use case of ETag header in #574. It'd be highly helpful.

Also, is it better to add the support for ETag with the current state in #3311? Browsers won't be picking it up. One should manually handle the case in their client app with POST request. I'm not sure whether it is possible (I'm a backend guy). Or else, I will pause the development of #3311 until #574 is done.

Thank you.

I agree to pause the development until #574 is done.

Implementing manually Etag behavior in the client is possible, but will be really painful.

I will comment my use case in #574.

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

egislook picture egislook  路  3Comments

stereobooster picture stereobooster  路  3Comments

Fortidude picture Fortidude  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

jjangga0214 picture jjangga0214  路  3Comments