-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 array in Filter.fields #5857
Comments
I would like to solve this issue. Is anybody working on this? |
Awesome, I am looking forward to your pull request! Let me assign the issue to you to make it clear that you are working on it. |
After working a little bit on the PR I found small details and questions to take into account:
(In case you need to check the current docs here is the link)
This works: And I want to apologize, I know that this is an easy good-first-issue but this is my first contribution and I want to be sure. Thank you. |
Good questions, @jeffersonlicet!
Yes, we want to allow JSON-enconding of query string values (i.e. the top-level To avoid possible confusion, we DO NOT want to support JSON encoding of the nested
Yes please! Personally, I find the array-based syntax easier to use than the current object-based one, so I think it makes a lot of sense to show the array version first, as the recommended one. Just make sure to describe the other version too. It's best to be explicit about this. Keep all examples consistently using the same style, and then add new content to explain and show the alternate syntax. It would be great to also mention the version of
I don't have a strong opinion. Let's start with what works for you, we can discuss this aspect more deeply during pull request review.
No need to apologize, we are happy to help 😄 Note: @achrinza is working on extracting filter-related code into a standalone package, his pull request #6182 is pretty much ready to be landed. Please keep an eye on it, I think you will have to rework your changes to accommodate the new structure of files & packages. |
@jeffersonlicet ping, have you have a chance to make any progress on this issue? Is there anything we can help you with? |
since jefferson is not working any more on this issue, could i take this? and i have a question how is going to be handled in controllers methods? findById(@param.filter() filter: Filter) {
// how is going to work here te access should remain as an object? (no introducing breaking changes)
filter.fields.name
// or
filter.fields.indexOf('name')
// or
filter.fields.has(name) // as a Set
} |
While I cannot speak for @jeffersonlicet, I think it should be ok to take over this work from him, since he haven't posted any update for a month.
The top-level type At the moment, If you are accessing findById(@param.filter() filter: Filter) {
const hasName = Array.isArray(filter.fields)
? filter.fields.includes('name')
: filter.fields?.['name'];
} |
Suggestion
Follow-up story from #4992 (comment)
Now the fields filter only allow object, like
{fields: {title: true, desc: true}}
, but doesn't allow the array shortcut like{fields: ['title', 'desc']}
.We should support the array shortcut as well.
Copy the details here:
fields: ['foo', 'bar']
is not allowed with bad request error. The reason is, typeFields<T>
only allows object, so that typeFilter<T>
can only have fields as object. Array is now accepted. See:https://github.com/strongloop/loopback-next/blob/ccea25fc382457f9436adfc0d8f6ce3a2d029c5e/packages/repository/src/query.ts#L196
and
https://github.com/strongloop/loopback-next/blob/ccea25fc382457f9436adfc0d8f6ce3a2d029c5e/packages/repository/src/query.ts#L162
But as @InvictusMB pointed out, the where builder allows array. And LB3 supports array syntax as well.
https://github.com/strongloop/loopback-next/blob/a81ce7e1193f7408d30d984d0c3ddcec74f7c316/packages/repository/src/query.ts#L508-L523
I am creating a new story to allow array in type
Fields<T>
. We can move the further discussion there.Use Cases
Filter with fields as array:
{fields: ['title', 'desc']}
Examples
Filter with fields as array:
{fields: ['title', 'desc']}
Acceptance criteria
Fields<T>
type to accept array(keyof MT)[]
🎆 Hacktoberfest 2020
Greetings 👋 to all Hacktoberfest 2020 participants!
Here are few tips 👀 to make your start easier, see also #6456:
#loopback-contributors
channel, you can join our Slack workspace here.The text was updated successfully, but these errors were encountered: