Creating Composites
Composites are the abstraction ComposeDB tools and client use to represent and manipulate data models used by applications.
In order to create new composites, especially to create new models that do not already exist on the Ceramic network, a high-level schema can be used as an abstraction for the composite structure.
Composite schema
The recommended way to create composites including new models is to use a schema file based on GraphQL, described in the dedicated documentation page.
Converting a schema to a composite
After a schema file has been created, it must be converted to a composite to be usable by the other tools and client.
- Using the CLI
- Using the API
Make sure you have the composedb
packages installed, before running the code below.
In order to create a Composite using the API, you also need to have an authenticated DID instance. You can use the did-session
package from js-did
to achieve this: DIDSession.DID Documentation
import { CeramicClient } from '@ceramicnetwork/http-client'
import { createComposite, writeEncodedComposite } 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')
ceramic.setDID(<Authenticated DID instance>)
// Replace by the path to the source schema file
const composite = await createComposite(ceramic, 'source-schema.graphql')
// Replace by the path to the encoded composite file
await writeEncodedComposite(composite, 'my-composite.json')
More details: createComposite
, writeEncodedComposite
If you want to create a composite using the CLI, you need to pass the --did-private-key
flag. More details: did:generate-private-key CLI command
composedb composite:create source-schema.graphql --output=my-composite.json --did-private-key='<DID Private Key>' --ceramic-url=http://localhost:7007