Class AuthorTrait

The Author trait adds author connection field to GraphQL types.

Usage:

traits:
- type: author
allow_change_author: true
check_membership:
target:
type: Organisation
edge: hasOrganisation
direction: out
user:
type: Organisation
edge: memberOf
direction: out

Settings:

  1. allow_change_author - allows to change author via update mutation
  2. check_membership - before updating author - compare membership of target entity and old author if it doesn't match - can update authorship. Works only if allow_change_author is true

Hierarchy

Constructors

Properties

_allowChangeAuthor: boolean = false

Trait instance configuration.

_global: boolean = false

Whether this is a global (not bound to any specific schema item) trait instance.

_graphqlSchemaManager: GraphQLSchemaManager
_targetMembership: null | MembershipDefinition = null
_type?: "author"

Trait type.

_userEntity?: string
_userMembership: null | MembershipDefinition = null
dataSourceWrapper: DataSourceWrapper
graphqlSchemaManager: GraphQLSchemaManager

Methods

  • Validate changing author against trait config

    Parameters

    • currentAuthorId: string

      author of entity before update

    • entityId: string

      entity id

    • context: KosmosUserContext<object>

      kosmos user context

    Returns Promise<void>

  • Parameters

    • itemId: string
    • newAuthorId: string
    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>

    Returns Promise<void>

  • Parameters

    • item: Record<string, any>
    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>

    Returns Promise<void>

  • Loads related entity by definition object

    Returns

    Entity or null

    Parameters

    • definition: MembershipDefinition

      description of relationships between vertices

    • context: KosmosUserContext<object>

      kosmos user context

    • forEntity: string

      target entity

    Returns Promise<any[]>

  • Parameters

    • schemaString: string
    • target: string
    • type: any

    Returns string

  • After the vertex has been created, add an edge pointing to its author.

    Parameters

    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>

      The trait data

    • item: any

      The data of the item that was created

    • datasourceWrapper: DataSourceWrapper

      Data source wrapper

    • context: any

      User Context

    Returns Promise<void>

  • Handle transferring authorship of entity

    Returns

    Parameters

    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>

      The trait data

    • item: any

      The data of the item that was updated

    • datasourceWrapper: DataSourceWrapper

      Legacy to be removed

    • context: any

      User Context

    Returns Promise<void>

  • This method is triggered when a trait callback has been activated

    Type Parameters

    • RT = any

    • Payload = any

    Parameters

    • callbackName: string

      This is the name of the callback function to call.

    • datasourceWrapper: DataSourceWrapper

      References to the Graph Hanlder

    • data: TraitDataObject<RT, Payload, Promise<any>>

      Request data passed along as part of the request.

    Returns Promise<RT>

  • Parameters

    • itemId: string
    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>

    Returns Promise<null | Record<string, any>>

Generated using TypeDoc