acquia / waterwheel.js

A generic JavaScript helper library to query and manipulate Drupal 8 via core REST and JSON API
https://github.com/acquia/waterwheel.js
233 stars 26 forks source link

Automatically retrieve (and cache on the client-side) referenced resources #22

Closed wimleers closed 6 years ago

wimleers commented 7 years ago

See https://www.drupal.org/node/2282603. HAL+JSON has the notion of _embedded resources. But it embeds just links, not the actual resources. Which means the client must still go and fetch those.

That's annoying. So Waterwheel should do that automatically.

And in doing so, Waterwheel should do client-side caching (much like React's Relay does client-side caching), to avoid re-requesting unchanged resources.


As for the precise implementation: TBD. Perhaps a .getReference([reference_field_name])-style API makes sense? (So you can do entity.getReference('user') to get the author.)

wimleers commented 7 years ago

Also see https://www.drupal.org/node/2282603#comment-11441025 for the exact context/reason for me opening this.

brendan-hurley commented 7 years ago

@wimleers I was wondering what your thoughts are on embedded images - when making the request, the authorization token is added thus triggering a preflight request where origin is different - I don't know about you guys but that kind of came as a bit of a surprise to me as the assets in my nginx config are static and I'm not expecting a preflight. Perhaps it's my own peculiar setup?

mattgrill commented 6 years ago

I'm going to close this for now. I'm not sure how much effort should be put into waterwheel actually caching responses itself, perhaps your own middleware could handle those needs. If we want to reopen this, with some more context, perhaps around jsonapi that would be great.