-
-
Notifications
You must be signed in to change notification settings - Fork 741
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
allow $select in params query when get #450
Comments
Indeed. There is several issues for this (feathersjs-ecosystem/feathers-service-tests#25 being the starting point). The current workaround for this is a three line hook: const pick = require('lodash.pick');
app.service('myservice').after(function(hook) {
if(hook.params.query.$select) {
hook.result = pick(hook.result, hook.params.query.$select);
}
}); |
hmmm.. does I would go with this workaround for now, but to be frankly it's painful to add this hook to all services in an app. I understand that making this change to |
This will be released for all adapters shortly. But I just wanted to point out that it is now pretty easy to add a hook to all services with application hooks in |
cool~! |
This has now been merged and released as a minor version in all official adapters. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
The service method
get
allows aparams
to be passed in, but currently just ignores it, as @daffl explained in here:But in fact
$select
in the query does change something. It would pluck the record and only returns the fields you need. This is particularly useful when you have a client-side cache of the record and want to see if the record is expired: you can just do:By doing this we could just transfer a small part of the record (only the id and the updatedAt time), and then be able to check if the cache is expired. If does, call
get
again to get the whole record; if not, just use the cache.But currently, when calling
get
for the first time, it always return the whole record (might be very very large), making the client-side cache totally useless.The text was updated successfully, but these errors were encountered: