Class JsonContentTrait

The JsonContentTrait is used to enable adding multiple json fields to an entity. A schema vertex must be defined along with the property which is used as the name of the schema.

For each field a name must be defined and optionally a type which is used to hold the name of the applied schema if ones is defined. If one is not defined the field will not be validated against a schema.

Usage:

traits:
- type: json_content
schema:
vertex: Schema
property: name
edge: usesSchema
fields:
- name: jsonData
type: type
- name: profile
storage:
name: json-content
revisions: true

Hierarchy

Constructors

Properties

Trait instance configuration.

_dataSourceWrapper: DataSourceWrapper
_externalStorageManager: ExternalStorageManager
_global: boolean = false

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

_graphqlSchemaManager: GraphQLSchemaManager
_jsonContentSchemaManager: JsonContentSchemaManager
_mutationFields: Record<string, string> = {}
_retainRevisions: boolean = false
_schemaManager: SchemaManager
_storageEngine: any = undefined
_type?: "json_content"

Trait type.

_validatorFactory: (() => KosmosSchemaValidator)

Type declaration

Methods

  • This function is used to return a list of array types.

    Returns

    Array of the defined json field types.

    Returns string[]

  • Add mutation to enable the JSON field to be updated.

    Returns

    GraphQL schema segment for inclusion in main graphql doc.

    Parameters

    • schemaString: string

      The existing schema string.

    • source: string

      String name of the source vertex that the trait is connected to.

    Returns string

  • Called after vertex is updated.

    Returns

    Parameters

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

      Used by traits for non user accessible entities

    • data: Record<string, any>

      The item being updated.

    Returns Promise<void>

  • Post-view hook implementation, handles replacing the keyed data with the content from the storage engine

    Returns

    Parameters

    • item: any

      The current item being retrieved

    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>

  • This function is used to implement the query schema for the trait.

    Returns

    GraphQL schema segment for inclusion in main graphql doc.

    Parameters

    • schemaString: string

      The existing schema thats passed in.

    Returns string

  • Utility function used to save a json entity to storage.

    Returns

    Boolean indication if saving was successful.

    Parameters

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

      The trait data object.

    • item: ItemWithId

      The json data to be stored.

    • validate: boolean = true

    Returns Promise<boolean>

  • Helper function for updating vertex field.

    Parameters

    • traitData: any
    • fieldName: string

    Returns Promise<void>

  • Throws error when query arguments contain forbidden relations

    Parameters

    • args: Record<string, any>
    • disabledRelations: TheItemsSchema[]

      list of disabled relations

    Returns void

  • Throws error when query arguments contain forbidden relations or don't contain required

    Parameters

    • args: Record<string, any>
    • target: string
    • context: KosmosUserContext<object>

      user context

    Returns Promise<void>

  • Throws error when relation isn't valid

    Parameters

    • relation: RelationshipData

      relation to create / remove

    • entityType: string

      entity type to validate

    • entityId: string

      entity id to validate

    • modificationType: "remove" | "create"

      action with edge

    • context: KosmosUserContext<object>

      user context

    • inverse: boolean = false

    Returns Promise<void>

Generated using TypeDoc