Class FileUrlTrait

File URL Trait provides downloadUrl and uploadUrl query fields and global setFileUploaded mutation triggered by S3 file upload Lambda.

Usage:

traits:
- type: file_url

Mermaid

Media file upload

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant S3 participant S3 Lambda Trigger User->>Kosmos: GraphQL mutation creating file entity activate Kosmos Kosmos->>User: Response with file UUID and signed S3 upload URL deactivate Kosmos User->>S3: File upload S3->>User: OK S3->>S3 Lambda Trigger: Trigger upload event S3 Lambda Trigger->>Kosmos: GraphQL mutation confirming file was uploaded activate Kosmos Kosmos->>S3 Lambda Trigger: OK deactivate Kosmos
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant S3 participant S3 Lambda Trigger User->>Kosmos: GraphQL mutation creating file entity activate Kosmos Kosmos->>User: Response with file UUID and signed S3 upload URL deactivate Kosmos User->>S3: File upload S3->>User: OK S3->>S3 Lambda Trigger: Trigger upload event S3 Lambda Trigger->>Kosmos: GraphQL mutation confirming file was uploaded activate Kosmos Kosmos->>S3 Lambda Trigger: OK deactivate Kosmos
sequenceDiagram
    actor User
    participant Kosmos
    participant S3
    participant S3 Lambda Trigger
    User->>Kosmos: GraphQL mutation creating file entity
    activate Kosmos
    Kosmos->>User: Response with file UUID and signed S3 upload URL
    deactivate Kosmos
    User->>S3: File upload
    S3->>User: OK
    S3->>S3 Lambda Trigger: Trigger upload event
    S3 Lambda Trigger->>Kosmos: GraphQL mutation confirming file was uploaded
    activate Kosmos
    Kosmos->>S3 Lambda Trigger: OK
    deactivate Kosmos

Mermaid

Retrieving file entity before file was uploaded

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant S3 User->>Kosmos: GraphQL query retrieving file entity activate Kosmos Kosmos->>User: Response with empty file download URL deactivate Kosmos
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant S3 User->>Kosmos: GraphQL query retrieving file entity activate Kosmos Kosmos->>User: Response with empty file download URL deactivate Kosmos
sequenceDiagram
    actor User
    participant Kosmos
    participant S3
    User->>Kosmos: GraphQL query retrieving file entity
    activate Kosmos
    Kosmos->>User: Response with empty file download URL
    deactivate Kosmos

Mermaid

Retrieving file entity after file was uploaded

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant S3 User->>Kosmos: GraphQL query retrieving file entity activate Kosmos Kosmos->>User: Response with signed file download URL deactivate Kosmos User->>S3: GET file by signed URL S3->>User: File object
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant S3 User->>Kosmos: GraphQL query retrieving file entity activate Kosmos Kosmos->>User: Response with signed file download URL deactivate Kosmos User->>S3: GET file by signed URL S3->>User: File object
sequenceDiagram
    actor User
    participant Kosmos
    participant S3
    User->>Kosmos: GraphQL query retrieving file entity
    activate Kosmos
    Kosmos->>User: Response with signed file download URL
    deactivate Kosmos
    User->>S3: GET file by signed URL
    S3->>User: File object

Hierarchy

Constructors

Properties

_cacheEnabled: boolean

Trait instance configuration.

_global: boolean = false

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

_type?: "file_url"

Trait type.

accessControl: AccessControl
cacheService: CacheService
dataSourceWrapper: DataSourceWrapper
graphqlSchemaManager: GraphQLSchemaManager
runtimeConfig: RuntimeConfig
s3Client: S3

Methods

  • Deletes a file from S3.

    Parameters

    • s3FileKey: string

      The S3 object key of the file to be deleted.

    Returns Promise<void>

  • Helper method which initializes/returns RepositoryTrait storage object.

    Parameters

    Returns FileUrlTraitStorage

  • Checks if given file exists at S3.

    Parameters

    • s3FileKey: string

    Returns Promise<boolean>

  • Defines mutation schema for updating file upload status.

    Parameters

    • schemaString: string

    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>

  • Adds downloadUrl and uploadUrl fields definitions.

    TODO: Remove resolvers assignment; this hook should only return a schema string. Resolvers (or 'handlers' should be defined and retrieved via separate hook).

    Updated GraphQL query schema string.

    Parameters

    • schemaString: string

    Returns string

Generated using TypeDoc