Skip to main content

Class: BaseConvexClient

browser.BaseConvexClient

Low-level client for directly integrating state management libraries with Convex.

Most developers should use higher level clients, like the ConvexHttpClient or the React hook based ConvexReactClient.

Constructors

constructor

new BaseConvexClient(address, onTransition, options?)

Parameters

NameTypeDescription
addressstringThe url of your Convex deployment, often provided by an environment variable. E.g. https://small-mouse-123.convex.cloud.
onTransition(updatedQueries: string[]) => voidA callback receiving an array of query tokens corresponding to query results that have changed.
options?BaseConvexClientOptionsSee BaseConvexClientOptions for a full description.

Defined in

browser/sync/client.ts:182

Accessors

url

get url(): string

Return the address for this client, useful for creating a new client.

Not guaranteed to match the address with which this client was constructed: it may be canonicalized.

Returns

string

Defined in

browser/sync/client.ts:747

Methods

getMaxObservedTimestamp

getMaxObservedTimestamp(): undefined | Long

Returns

undefined | Long

Defined in

browser/sync/client.ts:417


setAuth

setAuth(fetchToken, onChange): void

Set the authentication token to be used for subsequent queries and mutations. fetchToken will be called automatically again if a token expires. fetchToken should return null if the token cannot be retrieved, for example when the user's rights were permanently revoked.

Parameters

NameTypeDescription
fetchTokenAuthTokenFetcheran async function returning the JWT-encoded OpenID Connect Identity Token
onChange(isAuthenticated: boolean) => voida callback that will be called when the authentication status changes

Returns

void

Defined in

browser/sync/client.ts:464


hasAuth

hasAuth(): boolean

Returns

boolean

Defined in

browser/sync/client.ts:471


clearAuth

clearAuth(): void

Returns

void

Defined in

browser/sync/client.ts:481


subscribe

subscribe(name, args?, options?): Object

Subscribe to a query function.

Whenever this query's result changes, the onTransition callback passed into the constructor will be called.

Parameters

NameTypeDescription
namestringThe name of the query.
args?Record<string, Value>An arguments object for the query. If this is omitted, the arguments will be {}.
options?SubscribeOptionsA SubscribeOptions options object for this query.

Returns

Object

An object containing a QueryToken corresponding to this query and an unsubscribe callback.

NameType
queryTokenstring
unsubscribe() => void

Defined in

browser/sync/client.ts:500


localQueryResult

localQueryResult(udfPath, args?): undefined | Value

A query result based only on the current, local state.

The only way this will return a value is if we're already subscribed to the query or its value has been set optimistically.

Parameters

NameType
udfPathstring
args?Record<string, Value>

Returns

undefined | Value

Defined in

browser/sync/client.ts:533


queryJournal

queryJournal(name, args?): undefined | QueryJournal

Retrieve the current QueryJournal for this query function.

If we have not yet received a result for this query, this will be undefined.

Parameters

NameTypeDescription
namestringThe name of the query.
args?Record<string, Value>The arguments object for this query.

Returns

undefined | QueryJournal

The query's QueryJournal or undefined.

Defined in

browser/sync/client.ts:586


connectionState

connectionState(): ConnectionState

Get the current ConnectionState between the client and the Convex backend.

Returns

ConnectionState

The ConnectionState with the Convex backend.

Defined in

browser/sync/client.ts:601


mutation

mutation(name, args?, options?): Promise<any>

Execute a mutation function.

Parameters

NameTypeDescription
namestringThe name of the mutation.
args?Record<string, Value>An arguments object for the mutation. If this is omitted, the arguments will be {}.
options?MutationOptionsA MutationOptions options object for this mutation.

Returns

Promise<any>

  • A promise of the mutation's result.

Defined in

browser/sync/client.ts:620


action

action(name, args?): Promise<any>

Execute an action function.

Parameters

NameTypeDescription
namestringThe name of the action.
args?Record<string, Value>An arguments object for the action. If this is omitted, the arguments will be {}.

Returns

Promise<any>

A promise of the action's result.

Defined in

browser/sync/client.ts:689


close

close(): Promise<void>

Close any network handles associated with this client and stop all subscriptions.

Call this method when you're done with an BaseConvexClient to dispose of its sockets and resources.

Returns

Promise<void>

A Promise fulfilled when the connection has been completely closed.

Defined in

browser/sync/client.ts:736