Skip to main content
Version: 0.2.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
ContentRecord<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
ContentRecord<string, any>

Parameters​

NameTypeDefault value
idstring | StreamID | CommitIDundefined
freshbooleanfalse

Returns​

Promise<ModelInstanceDocument<Content>>


queryConnection​

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

Query the index for a connection of documents.

Parameters​

NameType
queryConnectionQuery

Returns​

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


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
ContentRecord<string, any>

Parameters​

NameType
idstring | StreamID
contentContent
options?UpdateDocOptions

Returns​

Promise<ModelInstanceDocument<Content>>