Architecture
Goal
Get a preview entity into front end without saving entity before.
Methode GET
The idea is that Drupal go to front-end with a the cache id to get back the data. If you got preview_graphql_jwt it will store inside JWT token.
When the front build the preview page, it takes the cache id, then ask with this cid, data to Drupal. Drupal read the cache, get the entity to preview, process the Graphql query (actually just before redirect front) then return the result enoded in json.
In summary
One redirection back to front
One call GET on back
One redirection front to back
When to choose this method:
Sometimes (often) it's hard in front end technology to build an web endpoint. So we decide to send the cache id( in JWT token if you got preview_graphql_jwt enable) in parameter. Then the front-end has just to contact the back end. Drupal also fetch data, process it and return a string with the same data structure as it should have when it's display in normal page.
Method POST
The idea is that Drupal first send DATA with a POST on front. On this endpoint front build or store the data recieved and also prepare the page for the preview. After this the front end must to return the redirect url to Drupal in the POST response. With this url Drupal will finally redirect user on front preview page.
Not@ : the front end can also fetch data again with the cid key (or JWT) like in GET method but it should already get it (all data) by the POST request.
In summary
One call POST on front
One redirection back to front
One redirection front to back
When to choose this method:
If the front end can easily implements one POST endpoint, you should use this method. All data are directly send to front end, also you don't need to request Drupal after the redirection. In more all data are send into POST so front end will received an complete Json object instead of received a json object convert into string and json encoded.
Why not using token API ?
You will see that the graphql Query is a bit reduced of what you can fill inside. Indeed you must to have a query that is build with an entity parent.
It would be possible to imagine using replacement token inside GraphQL query and also simplify the comprehension of query graphql input. But it's not possible cause the entity being preview is unsaved. So all data are unknown for graphQL.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion