You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/09/10 10:15:47 UTC

[sling-org-apache-sling-graphql-core] branch master updated: Add Persisted Query Hash section

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 86494f1  Add Persisted Query Hash section
86494f1 is described below

commit 86494f11358840086b281a38cd39495b565e041f
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Sep 10 12:15:39 2020 +0200

    Add Persisted Query Hash section
---
 README.md | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index f2cad73..129c4c5 100644
--- a/README.md
+++ b/README.md
@@ -147,8 +147,22 @@ the parameter becoming too large for HTTP services and intermediates.
  (e.g. CDNs) to cache the JSON responses. 
 5. There's no guarantee on how long a persisted query is stored. A client that gets a `404` on a persisted query must be prepared to
  re`POST` the query, in order to store the prepared query again.
+
+#### Persisted Query Hash
+
+The hash that's part of the `persisted` URL is computed on the POSTed GraphQL query by the active `GraphQLCacheProvider` service. By 
+default this is the `SimpleGraphQLCacheProvider` which computes it as follows:
+
+    MessageDigest digest = MessageDigest.getInstance("SHA-256");
+    byte[] hash = digest.digest(query.getBytes(StandardCharsets.UTF_8));
     
-Here are a few examples:
+And encodes it in hex to build the persisted query's path.
+
+This means that, if desired, an optimistic client can compute the hash itself and try a GET to the `persisted/<hash>` URL without doing
+a POST first. If the query is already cache this saves the POST request, and if not the client gets a 404 status and has to POST the
+query first.
+
+#### Example HTTP interactions with persisted queries enabled
 
 1. Storing a query
     ```bash