-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the composites guide #37
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ Let’s say you have a model written in a `my-schema.graphql` file. To convert t | |
<TabItem value="cli"> | ||
|
||
```bash | ||
composedb composite:create my-schema.graphql --output=my-composite.json --did-private-key=your-private-key | ||
composedb composite:create my-schema.graphql --output=./__generated__/definition.json --did-private-key=your-private-key | ||
``` | ||
|
||
</TabItem> | ||
|
@@ -65,16 +65,16 @@ const ceramic = new CeramicClient('http://localhost:7007') | |
ceramic.did = did | ||
|
||
// Replace by the path to the source schema file | ||
const composite = await createComposite(ceramic, './source-schema.graphql') | ||
const composite = await createComposite(ceramic, './my-schema.graphql') | ||
|
||
// Replace by the path to the encoded composite file | ||
await writeEncodedComposite(composite, './my-composite.json') | ||
await writeEncodedComposite(composite, './__generated__/definition.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calling this json file |
||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
This will create a file called `my-composite.json` which contains the composite in JSON. | ||
This will create a file called `definition.json` which contains the composite definition in JSON. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was correct as it was before. |
||
|
||
### Deploying composites | ||
After creating the composite, deploy it to your local node: | ||
|
@@ -89,7 +89,7 @@ After creating the composite, deploy it to your local node: | |
<TabItem value="cli"> | ||
|
||
```bash | ||
composedb composite:deploy my-composite.json --ceramic-url=http://localhost:7007 --did-private-key=your-private-key | ||
composedb composite:deploy ./__generated__/definition.json --ceramic-url=http://localhost:7007 --did-private-key=your-private-key | ||
``` | ||
|
||
</TabItem> | ||
|
@@ -120,7 +120,7 @@ const ceramic = new CeramicClient('http://localhost:7007') | |
ceramic.did = did | ||
|
||
// Replace by the path to the local encoded composite file | ||
const composite = await readEncodedComposite(ceramic, 'my-first-composite.json') | ||
const composite = await readEncodedComposite(ceramic, './__generated__/definition.json') | ||
|
||
// Notify the Ceramic node to index the models present in the composite | ||
await composite.startIndexingOn(ceramic) | ||
|
@@ -138,10 +138,62 @@ This will also automatically add all models contained in the composite to the [M | |
|
||
After deploying your composite, compile it so you can start perform [data interactions](../../guides/data-interactions/data-interactions.mdx) using the ComposeDB client. | ||
|
||
<Tabs | ||
defaultValue="cli" | ||
groupId="cli-or-js" | ||
values={[ | ||
{label: 'CLI', value: 'cli'}, | ||
{label: 'JavaScript', value: 'js'}, | ||
]}> | ||
<TabItem value="cli"> | ||
|
||
```bash | ||
composedb composite:compile my-first-composite.json runtime-composite.json | ||
composedb composite:compile ./__generated__/definition.json ./__generated__/definition.js | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="js"> | ||
|
||
```jsx | ||
import { CeramicClient } from '@ceramicnetwork/http-client' | ||
import { DID } from 'dids' | ||
import { Ed25519Provider } from 'key-did-provider-ed25519' | ||
import { getResolver } from 'key-did-resolver' | ||
import { fromString } from 'uint8arrays/from-string' | ||
|
||
import { writeEncodedCompositeRuntime } from '@composedb/devtools-node' | ||
|
||
// Hexadecimal-encoded private key for a DID having admin access to the target Ceramic node | ||
// Replace the example key here by your admin private key | ||
const privateKey = fromString('b0cb[...]515f', 'base16') | ||
|
||
const did = new DID({ | ||
resolver: getResolver(), | ||
provider: new Ed25519Provider(privateKey), | ||
}) | ||
await did.authenticate() | ||
|
||
// Replace by the URL of the Ceramic node you want to deploy the Models to | ||
const ceramic = new CeramicClient('http://localhost:7007') | ||
// An authenticated DID with admin access must be set on the Ceramic instance | ||
ceramic.did = did | ||
|
||
|
||
// Create a composite for runtime usage | ||
await writeEncodedCompositeRuntime( | ||
ceramic, | ||
'./__generated__/definition.json', | ||
'./__generated__/definition.js' | ||
); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
This will generate a composite definition `definition.js`, ready for the runtime use. Keep in mind that you | ||
can compile the composite in `.json` and `.ts` formats as well. Check out the [API reference](https://composedb.js.org/) for more details. | ||
|
||
## Advanced | ||
--- | ||
### Merging composites | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command does return a simple json file instead of a file inside the
__generated__
subdirectory, I mean it will create the output where the users specifies, but then they might confuse this with the definition json file used in the runtime when using the composedb server that is autogenerated by thewriteEncodedCompositeRuntime
function