Skip to main content
Version: 0.3.x

Using Relay

What is Relay?

Relay is a popular GraphQL client for React.

It is not necessary to use it to execute queries and mutations on ComposeDB, but it can help simplify the developer experience for common use-cases.

The ComposeDB client can be used with Relay by creating a custom network layer, as shown in the example below:

Make sure you have the composedb packages installed, before running the code below. Additionally, you'll need the relay-runtime package.

import { ComposeClient } from '@composedb/client'
import { Environment, Network, RecordSource, Store } from 'relay-runtime'

// Path to the generated runtime composite definition
import { definition } from './__generated__/definition.js'

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

// Create a custom Network using the ComposeClient instance to execute operations
const network = Network.create(async (request, variables) => {
return await client.executeQuery(request.text, variables)
})

// Use the created Network instance to create the Relay Environment
export const environment = new Environment({ network, store: new Store(new RecordSource()) })