Skip to content

willex/composedb-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ComposeDB Workshop @ IPFS Camp 2022 - Lisbon

MIT license Twitter

ATTN: ComposeDB is currently in active development and composites CANNOT be deployed on mainnet!

What does this workshop cover:

  1. Setup Ceramic node incl. ComposeDB developer preview with relations support
  2. Create and deploy your first composites
  3. Add and query data
  4. ✨Ceramic Magic ✨

Oh and btw... we'd ❤️ to hear your feedback - ping us on Discord or submit directly through our FORUM

So, lets get started! 🚀

1. Installation

Install the necessities - @next ensures you are running the latest developer preview:
pnpm install --global @composedb/cli@next @ceramicnetwork/cli@next

Now to create a new PK & corresponding DID to get our node setup.
composedb did:generate-private-key
composedb did:from-private-key ADD_GENERATED_PK_HERE

For demo purposes and to follow along with the tutorial you can store the PK in priv.key. Just be careful NOT TO COMMIT this file by accident. Alternatively, you can also set a new ENV variable DID_PRIVATE_KEY. Doing this you can just omit --did-private-key from the example commands.

ATTN: ALWAYS keep your private key safe and copy the DID into the node config file located under ~/.ceramic/daemon.config.json which will prepare the node for future CLI interactions. If you don't have a config file in your directory yet, simply start the node once via ceramic daemon and exit again. This will create a default config file:

Node config example:

{
  "anchor": {},
  "http-api": {
    "cors-allowed-origins": [
      ".*"
    ],
    "admin-dids": ["did:key:INSERT_DID_KEY_HERE"]
  },
  "ipfs": {
    "mode": "bundled"
  },
  "logger": {
    "log-level": 2,
    "log-to-files": false
  },
  "metrics": {
    "metrics-exporter-enabled": false,
    "metrics-port": 9090
  },
  "network": {
    "name": "testnet-clay"
  },
  "node": {},
  "state-store": {
    "mode": "fs",
    "local-directory": "/Users/Ceramic/.ceramic/statestore/"
  },
  "indexing": {
    "db": "sqlite:///Users/Ceramic/.ceramic/indexing.sqlite",
    "allow-queries-before-historical-sync": true,
    "models": []
  }
}

After adding the DID, lets start the node and on to the build steps:
export CERAMIC_ENABLE_EXPERIMENTAL_COMPOSE_DB="true"; ceramic daemon

2. Composite Build Steps - Your First Relation

Ensure the Cearmic Daemon is running and proper indexing environment variables are set export CERAMIC_ENABLE_EXPERIMENTAL_COMPOSE_DB=true WARNING: if you have previous models indexed that you don’t care about anymore you’ll need to remove the sqlite file if you no longer want Ceramic to index them. The daemon will not start if they exist in the database but are not referenced in the config.

  1. Create or edit AddressBook.graphql schema
  2. Create a composite from the AddressBook schema:
    composedb composite:create schemas/AddressBook.graphql --output eth-address-book.json --did-private-key $(cat priv.key)
  3. Get the created AddressBook ID to reference it in the relational schema:
    composedb composite:models eth-address-book.json

Copy out ID to use in the next step:

✔ Fetching composite's models... Done!
[{"id":"kjzl6hvfrbw6c8q2qtmt297gpp66meihwthrcg3uiohzxhv5myz5d7ajf30ylgz","name":"AddressBook","description":"Simple Address Book"}]
  1. Create or edit AddressBookEntry.graqhql schema and use the correct ID from the previous step to reference AddressBook:
    composedb composite:create schemas/AddressBookEntry.graphql --output=eth-address-book-entries.json --did-private-key $(cat priv.key)
  2. Merge the composites into a single encoded file:
    composedb composite:merge eth-address-book.json eth-address-book-entries.json --output=demo-address-book-merged.json
  3. Deploy the merged composite. This will add the models to your local node and start indexing automatically:
    composedb composite:deploy demo-address-book-merged.json

Still with me... great! We are ready to play with data! 🙌

3. Runtime Steps - Say Hello to GRAPHIQL

If you made it this far, I'm proud of you! Now comes the really fun part:

  1. Compile a runtime representation to use (this would be used by our application to interact with the node):
    composedb composite:compile demo-address-book-merged.json demo-runtime.json

  2. In lieu of a front-end, ComposeDB ships with GraphiQL to get you started:
    composedb graphql:server --graphiql --port=35000 demo-runtime.json --did-private-key=$(cat priv.key)

You should be able to CONNECT now!

Query Composite:

query{
    addressBookIndex(first:10) {
        edges{
            node{
                id
                addressBookName
        }}
    
    }
}

Since we don't have data nothing will be returned, but if you don't get an error you are ready to go!

Create New AddressBook

mutation CreateNewAddressBook($i: CreateAddressBookInput!) {
    createAddressBook(input: $i) {
        document {
            id
            addressBookName
        }
    }
}

Query Variables:

{
    "i": {
        "content": {
            "addressBookName": "PL Summit"
        }
    }
}

Create New AddressBookEntry

mutation CreateNewAddressBookEntry ($i: CreateAddressBookEntryInput!) {
    createAddressBookEntry(input: $i) {
        document {
            id
            entryName
            walletAddresses {
                address
                blockchainNetwork
            }
        }
    }
}

Query Variables:

{
  "i": {
    "content": {
      "addressBook": "INSERT CREATED ADDRESS BOOK ID HERE",
      "entryName": "my fantastic entry",
      "walletAddresses": {
          "address": "0x00",
          "blockchainNetwork": "ethereum"
      }
    }
  }
}

Query Final Composite Data:

query {
    addressBookEntryIndex(first: 5) {
        edges{
            node {
                book {
                    id
                    addressBookName
                }
                entryName
                walletAddresses {
                    address
                    blockchainNetwork
                }
            }
        }
    }
}

And that's all folks 😎 ! You are now officialy a ComposeDB PRO. Go back and have a look at the schemas and play around with them or try to create your own schemas and models. Can't wait to see what you are building on ComposeDB!

4. Bonus Content

WARNING: not a 100% match to the above & might be a bit outdated but captures the gist of the demo

About

ComposeDB with releations (DP) workshop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published