Skip to content

Allow array in Filter.fieldsΒ #5857

@jannyHou

Description

@jannyHou

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, type Fields<T> only allows object, so that type Filter<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

  • Modify the Fields<T> type to accept array (keyof MT)[]
  • Update code and test after the type change
  • Document the new behavior in LB4/Working-with-data/fields-filter page

πŸŽ† Hacktoberfest 2020

Greetings πŸ‘‹ to all Hacktoberfest 2020 participants!

Here are few tips πŸ‘€ to make your start easier, see also #6456:

  • Before you start working on this issue, please leave a comment to let others know.
  • If you are new to GitHub pull requests, then you can learn about the process in Submitting a pull request to LoopBack 4.
  • If this is your first contribution to LoopBack, then please take a look at our Developer guide.
  • Feel free to ask for help in #loopback-contributors channel, you can join our Slack workspace here.

Metadata

Metadata

Assignees

Labels

HacktoberfestTasks ready for new contributors to work onRepositoryIssues related to @loopback/repository packagedeveloper-experienceIssues affecting ease of use and overall experience of LB usersfeaturegood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions