Skip to main content
Version: 0.3.x

Class: Context

client.Context

GraphQL execution context, exported by the client module.

import { Context } from '@composedb/client'

Constructors

constructor

new Context(params)

Parameters

NameType
paramsContextParams

Accessors

authenticated

get authenticated(): boolean

Returns whether the Ceramic client instance used internally is authenticated or not. When not authenticated, mutations will fail.

Returns

boolean


ceramic

get ceramic(): CeramicApi

Ceramic client instance used internally.

Returns

CeramicApi


loader

get loader(): DocumentLoader

Document loader instance used internally.

Returns

DocumentLoader


viewerID

get viewerID(): null | string

ID of the current viewer (authenticated DID), if set.

Returns

null | string

Methods

createDoc

createDoc<Content>(model, content): Promise<ModelInstanceDocument<Content>>

Create a new document with the given model and content.

Type parameters

NameType
Contentextends Record<string, any> = Record<string, any>

Parameters

NameType
modelstring
contentContent

Returns

Promise<ModelInstanceDocument<Content>>


createSingle

createSingle<Content>(model, content): Promise<ModelInstanceDocument<Content>>

Create a new single document with the given model and content.

Type parameters

NameType
Contentextends Record<string, any> = Record<string, any>

Parameters

NameType
modelstring
contentContent

Returns

Promise<ModelInstanceDocument<Content>>


loadDoc

loadDoc<Content>(id, fresh?): Promise<ModelInstanceDocument<Content>>

Load a document by ID, using the cache if possible.

Type parameters

NameType
Contentextends Record<string, any> = Record<string, any>

Parameters

NameTypeDefault value
idstring | StreamID | CommitIDundefined
freshbooleanfalse

Returns

Promise<ModelInstanceDocument<Content>>


queryConnection

queryConnection(query): Promise<Connection<null | ModelInstanceDocument<Record<string, any>>>>

Query the index for a connection of documents.

Parameters

NameType
queryConnectionQuery

Returns

Promise<Connection<null | ModelInstanceDocument<Record<string, any>>>>


queryCount

queryCount(query): Promise<number>

Query the index for the total number of documents matching the query parameters.

Parameters

NameType
queryBaseQuery

Returns

Promise<number>


querySingle

querySingle(query): Promise<null | ModelInstanceDocument<Record<string, any>>>

Query the index for a single document.

Parameters

NameType
queryBaseQuery

Returns

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


updateDoc

updateDoc<Content>(id, content, options?): Promise<ModelInstanceDocument<Content>>

Update an existing document.

Type parameters

NameType
Contentextends Record<string, any> = Record<string, any>

Parameters

NameType
idstring | StreamID
contentContent
options?UpdateDocOptions

Returns

Promise<ModelInstanceDocument<Content>>