Skip to main content
Version: 0.3.x

Client setup

Compiling the composite

In order to interact with a composite at runtime, it is first necessary to create a runtime composite definition file that will be used to configure the client.

Make sure you have the composedb packages installed, before running the code below.

import { CeramicClient } from '@ceramicnetwork/http-client'
import { writeEncodedCompositeRuntime } from '@composedb/devtools-node'

// Replace by the URL of the Ceramic node you want to deploy the models to
const ceramic = new CeramicClient('http://localhost:7007')

// Replace by the path to the local encoded composite file
await writeEncodedCompositeRuntime(
ceramic,
'my-first-composite.json',
'src/__generated__/definition.js'
)

More details: writeEncodedCompositeRuntime

Configuring the client

Once the composite definition file is written, for example in src/__generated__/definition.js using the example above, it can be imported in the app to configure the client:

Make sure you have the composedb packages installed, before running the code below.app to configure the client.

src/compose.js
import { ComposeClient } from '@composedb/client'

import { definition } from './__generated__/definition.js'

export const compose = new ComposeClient({ ceramic: 'http://localhost:7007', definition })

More details: ComposeClient

Executing queries

The ComposeClient instance created in the previous step can be used to execute GraphQL queries using a schema automatically generated from the runtime composite definition.

await compose.executeQuery(`
query {
viewer {
id
}
}
`)

More details: executeQuery