Entity

    Class EnforcingEntityLoader<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>

    Enforcing entity loader. All normal loads are batched, cached, and authorized against the entity's EntityPrivacyPolicy. All loads through this loader will throw if the load is not successful.

    Type Parameters

    Index

    Constructors

    Methods

    • Load an entity where fieldName equals fieldValue, or null if no entity exists.

      Type Parameters

      • N extends string | number | symbol

      Parameters

      • uniqueFieldName: N

        entity field being queried

      • fieldValue: NonNullable<TFields[N]>

        uniqueFieldName field value being queried

      Returns Promise<null | TEntity>

      entity where uniqueFieldName equals fieldValue, or null if no entity matches the condition.

      when multiple entities match the condition

      EntityNotAuthorizedError when viewer is not authorized to view the returned entity

    • Load an entity by a specified ID, or return null if non-existent.

      Parameters

      Returns Promise<null | TEntity>

      entity for matching ID, or null if no entity exists for ID.

      EntityNotAuthorizedError when viewer is not authorized to view the returned entity

      when multiple entities are found matching the condition

    • Load many entities where fieldName equals fieldValue.

      Type Parameters

      • N extends string | number | symbol

      Parameters

      • fieldName: N

        entity field being queried

      • fieldValue: NonNullable<TFields[N]>

        fieldName field value being queried

      Returns Promise<readonly TEntity[]>

      array of entities that match the query for fieldValue

      EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities

    • Load many entities where fieldName is one of fieldValues.

      Type Parameters

      • N extends string | number | symbol

      Parameters

      • fieldName: N

        entity field being queried

      • fieldValues: readonly NonNullable<TFields[N]>[]

        fieldName field values being queried

      Returns Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly TEntity[]>>

      map from fieldValue to entities that match the query for that fieldValue

      EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities

    • Loads many entities matching the selection constructed from the conjunction of specified operands. Entities loaded using this method are not batched or cached.

      Type Parameters

      • N extends string | number | symbol

      Parameters

      Returns Promise<readonly TEntity[]>

      array of entities that match the query

      fieldEqualityOperands:
      `[{fieldName: 'hello', fieldValue: 1}, {fieldName: 'world', fieldValues: [2, 3]}]`
      Entities returned with a SQL EntityDatabaseAdapter:
      `WHERE hello = 1 AND world = ANY({2, 3})`

      EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities

    • Loads many entities for a list of IDs.

      Parameters

      Returns Promise<ReadonlyMap<TFields[TIDField], TEntity>>

      map from ID to corresponding entity result, where result error can be UnauthorizedError or EntityNotFoundError.

      EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities

      EntityNotFoundError when no entity exists for one or more of the IDs

    • Loads many entities matching the raw WHERE clause. Corresponds to the knex whereRaw argument format.

      Parameters

      • rawWhereClause: string

        parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders

      • bindings: object | any[]

        array of positional bindings or object of named bindings

      • querySelectionModifiers: QuerySelectionModifiersWithOrderByRaw<TFields> = {}

        limit, offset, orderBy, and orderByRaw for the query

      Returns Promise<readonly TEntity[]>

      array of entities that match the query

      Important notes:

      • Fields in clause are database column names instead of transformed entity field names.
      • Entities loaded using this method are not batched or cached.
      • Not all database adapters implement the ability to execute this method of fetching entities.
      rawWhereClause: `id = ?`
      bindings: `[1]`
      Entites returned `WHERE id = 1`

      http://knexjs.org/#Builder-whereRaw
      http://knexjs.org/#Raw-Bindings

      EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities

      Error when rawWhereClause or bindings are invalid

    MMNEPVFCICPMFPCPTTAAATR