-
Notifications
You must be signed in to change notification settings - Fork 90
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
RFC: Support for Automatic Persisted Queries (APQ) #759
Comments
Hi @zanettin, before getting into the details of this request there's one thing I would like to clarify. You mention
Are we talking about persisted queries as a caching mechanism or am I not understanding this right? |
Hi @simoneb Sorry that I was not clear about that point. It's not caching related but eliminates the step of persisting the queries at build time. As visualized on the sequence diagram above the client sends always just an sha256 hash to the graphql server. if the server knows the hash, he translates it to the real query and executes it. if the server is not aware of that hash since he never had to answer a request with that hash, he returns an error to the client. the client then has to send the query alongside with the sha256 hash. the server will execute the query and if it was successful he'll stores the hash/query map on any (shared) cache. the cache could look like this:
so on any upcoming requests with the hash pros and conspro
cons
thanks for your reply and considering adding that feature 🙏 |
Thanks for clarifying. Can you explain what is the benefit of doing so? Persisted queries are (to the best of my understanding) a security mechanism which prevents clients from sending queries outside of those already known by the server. What you're proposing basically bypasses this mechanism, so I'm not sure I understand what is the value. |
The security aspect is one thing, yes. The others are sending less data over the wire (on the request) as well as make it easier or even possible to cache it on a CDN. Another thing is that with regularly persisted query (on build time) the client has to load the map as well to get the ID needed for the request. This slows down the client load time and increase the bundle size. So regarding your question about the value: as developer you don't need to configure babel plugins to create your query map and upload them to your graphql server implementation. this happens all on request base. i saw in the readme that you compare the lib with apollo in many cases and try to motivate developers to switch to this lib so this could be another selling point. i am not sure how the graphql server implementations will evolve over time and if this will be the new standard or not. at least for the above mentioned implementation it is already in place for those who want to use it 👍 |
Sounds good. As a follow-up to this issue we should consider supporting this protocol in mercurius as well. |
Hi @zanettin, thanks for the proposal and for your initial analysis! Regarding other server implementations supporting persisted queries:
This entire mechanism is something that would need to be implemented on a middleware (like Apollo does with *For "custom logic" I mean:
Regarding the current |
I started a public discussion on the repo about adding middleware support: #761 |
Once middleware support will ship, this feature can be worked out, i.e. blocked by #769. |
Description
We offer currently a persisting method thanks to @salmanm's PR. with this method we create the hashes on build time and they need to be available on the backend as well. with the automatic approach the client would hash the query on request and sends it to the server. if the server already has a cached response for this hash, it would return it. otherwise he'll send an error code after which the client has to resend the request using the query and the hash. illustrated here:
Server Implementations with APG support
Suggested implementation
GET
requestcurl -g 'http://localhost:4000/graphql?extensions={"persistedQuery":{"version":1,"sha256Hash":"ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38"}}'
PERSISTED_QUERY_NOT_FOUND
: resend query usingPOST
together with the hashQuestions
persisted
optionThe text was updated successfully, but these errors were encountered: