Skip to content
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

Introduce InclusionResolver concept #3445

Closed
3 tasks
bajtos opened this issue Jul 26, 2019 · 0 comments · Fixed by #3517
Closed
3 tasks

Introduce InclusionResolver concept #3445

bajtos opened this issue Jul 26, 2019 · 0 comments · Fixed by #3517
Assignees
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package

Comments

@bajtos
Copy link
Member

bajtos commented Jul 26, 2019

Introduce the concept of a inclusion resolver, which is a function we can use to fetch related models (both in our ORM/REST API but also from GraphQL resolvers in the future).

/**
 * @returns An array of resolved values, the items must be ordered in the same
 * way as `sourceEntities`. The resolved value can be one of:
 * - `undefined` when no target model(s) were found
 * - `Entity` for relations targeting a single model
 * - `Entity[]` for relations targeting multiple models
 */
export type InclusionResolver = (
  /**
   * List of source models as returned by the first database query.
   */
  sourceEntities: Entity[],
  /**
   * Inclusion requested by the user (e.g. scope constraints to apply).
   */
  inclusion: Inclusion,
  /**
   * Generic options object, e.g. carrying the Transaction object.
   */
  options?: Options,
) => Promise<(Entity | undefined)[] | (Entity[] | undefined)[]>;

See #3387 for more details & a prototype implementation.

Acceptance criteria

  • Introduce a new type InclusionResolver
  • Implement a new helper function includeRelatedModels, it will become a part of a public API of @loopback/repository. Under the hood, this function should leverage inclusion resolvers to fetch related models.
  • Write unit-level tests to verify the implementation, use mocked or stubbed inclusion resolvers.

Note: helper name includeRelatedModels is not final, feel free to propose a better one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants