Using relay-nextjs

Hi guys.
Can we use relay-nextjs for composedb?
As it look like could it be done by replacing the client-side environment by relay-nextjs with

// lib/client_environment.ts
import { hydrateRelayEnvironment } from 'relay-nextjs';
import { withHydrateDatetime } from 'relay-nextjs/date';
import { Environment, Network, Store, RecordSource } from 'relay-runtime';

export function createClientNetwork() {
return (await composeClient.executeQuery(request.text!, variables)) as any;
  /*return Network.create(async (params, variables) => {
    const response = await fetch('/api/graphql', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Content-Type': 'application/json',
      body: JSON.stringify({
        query: params.text,

    const json = await response.text();
    return JSON.parse(json, withHydrateDatetime);

let clientEnv: Environment | undefined;
export function getClientEnvironment() {
  if (typeof window === 'undefined') return null;

  if (clientEnv == null) {
    clientEnv = new Environment({
      network: createClientNetwork(),
      store: new Store(new RecordSource()),
      isServer: false,


  return clientEnv;
Any opinions?

Hey @dabuchera. Technically, you can use React Relay or Apollo for you GrapqhQL client.
We have a little bit more documentation and an example on it here: Using Relay GraphQL Client | ComposeDB on Ceramic

1 Like