Open cleitonper opened 4 years ago
Hi there,
Sorry for the delay. Nice idea, I hadn't thought of using the _fields query parameter, and also good way of handling it with the options using a resources field - would allow for backwards compatibility. I can look into implementing this, it looks like it'd actually be fairly quick if I got around to it, although I have less free time at the moment (and am not actively working with this plugin currently). Otherwise, feel free to open a PR!
Hi again,
I actually ended up having a chance to have a brief look at this. I've created a new branch with the filter fields feature - using the same config layout as suggested by you.
Currently, if the resources config option is set, it'll ignore the fields and use that instead. There's not really checking to make sure the config layout is correct at the moment, but have a look if you get a chance, to see if it reduces the build time much for you / if you see major issues with it (I wouldn't be surprised, I rushed through it a little bit)
Filter resources with the Wordpress REST API
_fields
query parameter Would be nice to have a configuration in the plugin to filter resources (products
,categories
, etc) coming from the API.In my case, for example, each product has dozens of fields, but my frontend in gatsby don't need all of these fields. Requesting only the fields that we need will reduce the build time significantly.
Why this feature is needed? To reduce build times.
How to handle it?
In this case the current option called
fields
would be renamed toresources
, and each resource must have aname
and a list offields
. If all the fields are needed in the gatsby we can pass a string with theall
value to thefields
option.