Class BehavioursTrait

The Behaviours Trait.

Attaches all existing Behaviours to a given entity type, allows listing, enabling and disabling Behaviours.

TODO: Implement limiting Behaviours types per Behaviour Trait instance.

Usage:

traits:
- type: behaviours

Mermaid

Services stack

%%{init:{"theme":"dark"}}%% flowchart TB KosmosConfig["Kosmos config"] GraphQLSchemaManager --initializes--> BehavioursTrait BehavioursTrait --adds fields and mutations--> GraphQLSchemaManager BehavioursTrait --retrieves Behaviours list-->KosmosConfig BehavioursTrait --stores/retrieves Behaviours configs--> BehavioursInstanceManager
%%{init:{"theme":"default"}}%% flowchart TB KosmosConfig["Kosmos config"] GraphQLSchemaManager --initializes--> BehavioursTrait BehavioursTrait --adds fields and mutations--> GraphQLSchemaManager BehavioursTrait --retrieves Behaviours list-->KosmosConfig BehavioursTrait --stores/retrieves Behaviours configs--> BehavioursInstanceManager
flowchart TB
    KosmosConfig["Kosmos config"]
    GraphQLSchemaManager --initializes--> BehavioursTrait
    BehavioursTrait --adds fields and mutations--> GraphQLSchemaManager
    BehavioursTrait --retrieves Behaviours list-->KosmosConfig
    BehavioursTrait --stores/retrieves Behaviours configs--> BehavioursInstanceManager

Mermaid

Kosmos GraphQL server initialization

%%{init:{"theme":"dark"}}%% sequenceDiagram participant GraphQLSchemaManager participant SchemaManager participant BehavioursTrait participant BehavioursSchemaManager GraphQLSchemaManager->>SchemaManager: Retrieves a schema items SchemaManager->>GraphQLSchemaManager: Schema items list loop For each schema item GraphQLSchemaManager->>BehavioursTrait: Triggers GraphQL schema hooks BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL query to list Behaviours and their statuses BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL mutations to enable/disable Behaviours BehavioursTrait->>BehavioursSchemaManager: Trigger registering in GraphQL schema BehavioursTrait->>GraphQLSchemaManager: Wraps Behaviours resolvers into wrapper, adds GraphQL queries, mutations, fields and corresponding wrapped resolvers end
%%{init:{"theme":"default"}}%% sequenceDiagram participant GraphQLSchemaManager participant SchemaManager participant BehavioursTrait participant BehavioursSchemaManager GraphQLSchemaManager->>SchemaManager: Retrieves a schema items SchemaManager->>GraphQLSchemaManager: Schema items list loop For each schema item GraphQLSchemaManager->>BehavioursTrait: Triggers GraphQL schema hooks BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL query to list Behaviours and their statuses BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL mutations to enable/disable Behaviours BehavioursTrait->>BehavioursSchemaManager: Trigger registering in GraphQL schema BehavioursTrait->>GraphQLSchemaManager: Wraps Behaviours resolvers into wrapper, adds GraphQL queries, mutations, fields and corresponding wrapped resolvers end
sequenceDiagram
    participant GraphQLSchemaManager
    participant SchemaManager
    participant BehavioursTrait
    participant BehavioursSchemaManager
    GraphQLSchemaManager->>SchemaManager: Retrieves a schema items
    SchemaManager->>GraphQLSchemaManager: Schema items list
    loop For each schema item
        GraphQLSchemaManager->>BehavioursTrait: Triggers GraphQL schema hooks
        BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL query to list Behaviours and their statuses
        BehavioursTrait->>GraphQLSchemaManager: Adds GraphQL mutations to enable/disable Behaviours
        BehavioursTrait->>BehavioursSchemaManager: Trigger registering in GraphQL schema
        BehavioursTrait->>GraphQLSchemaManager: Wraps Behaviours resolvers into wrapper, adds GraphQL queries, mutations, fields and corresponding wrapped resolvers
    end

Mermaid

Listing Behaviours

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager User->>Kosmos: GraphQL query retrieving Behaviours list Kosmos->>BehavioursTrait: Executes Behaviours listing resolver BehavioursTrait->>BehavioursInstanceManager: Retrieves tenant's active behaviours instances BehavioursInstanceManager->>BehavioursTrait: Returns list of all available behaviours and their statuses (active/inactive) BehavioursTrait->>Kosmos: Resolver response Kosmos->>User: GraphQL response
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager User->>Kosmos: GraphQL query retrieving Behaviours list Kosmos->>BehavioursTrait: Executes Behaviours listing resolver BehavioursTrait->>BehavioursInstanceManager: Retrieves tenant's active behaviours instances BehavioursInstanceManager->>BehavioursTrait: Returns list of all available behaviours and their statuses (active/inactive) BehavioursTrait->>Kosmos: Resolver response Kosmos->>User: GraphQL response
sequenceDiagram
    actor User
    participant Kosmos
    participant BehavioursTrait
    participant BehavioursInstanceManager
    User->>Kosmos: GraphQL query retrieving Behaviours list
    Kosmos->>BehavioursTrait: Executes Behaviours listing resolver
    BehavioursTrait->>BehavioursInstanceManager: Retrieves tenant's active behaviours instances
    BehavioursInstanceManager->>BehavioursTrait: Returns list of all available behaviours and their statuses (active/inactive)
    BehavioursTrait->>Kosmos: Resolver response
    Kosmos->>User: GraphQL response

Mermaid

Executing Behaviours queries/mutations

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager participant Behaviour Instance User->>Kosmos: GraphQL query/mutation Kosmos->>BehavioursTrait: Calls resolver wrapper BehavioursTrait->>BehavioursInstanceManager: Checks if Behavior instance exists BehavioursInstanceManager->>BehavioursTrait: Instance config opt no behaviour instance (behaviour not enabled) BehavioursTrait->>User: Error response end BehavioursTrait->>Behaviour Instance: Executes resolver with schema item and instance config Behaviour Instance->>Kosmos: Response Kosmos->>User: Response
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager participant Behaviour Instance User->>Kosmos: GraphQL query/mutation Kosmos->>BehavioursTrait: Calls resolver wrapper BehavioursTrait->>BehavioursInstanceManager: Checks if Behavior instance exists BehavioursInstanceManager->>BehavioursTrait: Instance config opt no behaviour instance (behaviour not enabled) BehavioursTrait->>User: Error response end BehavioursTrait->>Behaviour Instance: Executes resolver with schema item and instance config Behaviour Instance->>Kosmos: Response Kosmos->>User: Response
sequenceDiagram
    actor User
    participant Kosmos
    participant BehavioursTrait
    participant BehavioursInstanceManager
    participant Behaviour Instance
    User->>Kosmos: GraphQL query/mutation
    Kosmos->>BehavioursTrait: Calls resolver wrapper
    BehavioursTrait->>BehavioursInstanceManager: Checks if Behavior instance exists
    BehavioursInstanceManager->>BehavioursTrait: Instance config
    opt no behaviour instance (behaviour not enabled)
        BehavioursTrait->>User: Error response
    end
    BehavioursTrait->>Behaviour Instance: Executes resolver with schema item and instance config
    Behaviour Instance->>Kosmos: Response
    Kosmos->>User: Response

Mermaid

Enabling/Disabling Behaviours

%%{init:{"theme":"dark"}}%% sequenceDiagram actor Admin participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager Admin->>Kosmos: GraphQL enable/disable mutation Kosmos->>BehavioursTrait: Executes Behaviours enable/disable resolver BehavioursTrait->>BehavioursInstanceManager: Calls add/remove Behaviour method alt could be enabled/disabled BehavioursInstanceManager->>Kosmos: GraphQL mutation
%%{init:{"theme":"default"}}%% sequenceDiagram actor Admin participant Kosmos participant BehavioursTrait participant BehavioursInstanceManager Admin->>Kosmos: GraphQL enable/disable mutation Kosmos->>BehavioursTrait: Executes Behaviours enable/disable resolver BehavioursTrait->>BehavioursInstanceManager: Calls add/remove Behaviour method alt could be enabled/disabled BehavioursInstanceManager->>Kosmos: GraphQL mutation
sequenceDiagram
    actor Admin
    participant Kosmos
    participant BehavioursTrait
    participant BehavioursInstanceManager
    Admin->>Kosmos: GraphQL enable/disable mutation
    Kosmos->>BehavioursTrait: Executes Behaviours enable/disable resolver
    BehavioursTrait->>BehavioursInstanceManager: Calls add/remove Behaviour method
    alt could be enabled/disabled
        BehavioursInstanceManager->>Kosmos: GraphQL mutation
`true` response else already enabled/disabled BehavioursInstanceManager->>Kosmos: GraphQL mutation `false` response else input validation failure BehavioursInstanceManager->>Kosmos: error response end Kosmos->>Admin: GraphQL response

Hierarchy

Constructors

Properties

Trait instance configuration.

_global: boolean = false

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

_type?: "behaviours"

Trait type.

accessControl: AccessControl
behaviours: BehaviourBase<string, KosmosConfig<string>, InstanceConfig<string>>[]
behavioursInstanceManager: BehavioursInstanceManager
behavioursSchemaManager: BehavioursSchemaManager
graphQlSchemaManager: GraphQLSchemaManager
hookedIntoAccessControl: boolean = false

Methods

  • Returns the enable/disable mutation type.

    Parameters

    • vertexLabel: string
    • type: "enable" | "disable"

    Returns string

  • Returns the Behaviours list query name.

    Parameters

    • vertexLabel: string
    • type: "list"

    Returns string

  • 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>

Generated using TypeDoc