loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

Simpler Syntax for Inclusion #3205

Closed nabdelgadir closed 3 years ago

nabdelgadir commented 5 years ago

Description / Steps to reproduce / Feature proposal

See https://github.com/strongloop/loopback-next/pull/3171/files#r296128644.

Currently to specify inclusion, the following filter syntax is needed: {include: [{relation: 'todos'}]} e.g. http://127.0.0.1:3000/todo-lists?filter[include][][relation]=todos

If we try the following call:

await todoListRepo.findById(todoList.id, {include: ['todos']});

The complier complains: Argument of type '{ include: string[]; }' is not assignable to parameter of type 'Filter<TodoList>' because the type is currently: include?: Inclusion<MT>[];

As LoopBack 3 supports {include: ['todos']}, LoopBack 4 should support this shortcut as well.

Acceptance Criteria

Important: we need to preserve backwards compatiblity, i.e. the current verbose syntax must stay supported too.

bajtos commented 5 years ago

Few examples of the syntax supported by LB3:

userRepo.find({include: ['posts', 'passports']});

userRepo.find({
  include: [
    {relation: 'posts', scope: {where: {title: 'Post A'}}},
    'passports',
  ],
});