Skip to main content

Working with Relay

Relay provides @dstack-js/transport compatible scalable signaling server and GraphQL API

Public Relay

Public relay has multi-regional and blue-green deploy to provide as higher as possible SLA and latencies

It is accesible here: https://relay.dstack.dev

You can check status and uptime here: https://status.dstack.dev

Getting Bootstrap data

As of version v0.2.46 no need to bootstrap

you can provide an GraphQL endpoint to your relay directly in @dstack-js/lib

import { Stack } from '@dstack-js/lib';

const stack = await Stack.create({
  namespace: 'namespace',
  relay: 'https://relay.dstack.dev:443/graphql'
});
How to get bootstrap data

Relay provides necessary GraphQL resolvers for initializing the Stack instance

import { request, gql } from "graphql-request";
import { Stack } from "@dstack-js/lib";
import { create } from "@dstack-js/ipfs";

export const createStack = async () => {
  const endpoint = "https://relay.dstack.dev:443/graphql";
  const url = new URL(endpoint);

  const query = gql`
    query Bootstrap($protocol: Protocol!, $hostname: String!, $port: Int!) {
      listen(protocol: $protocol, hostname: $hostname, port: $port)
      peers(randomize: true)
    }
  `;

  const {listen, peers} = await request<{ listen: string[]; peers: string[] }>(
    endpoint,
    query,
    {
      protocol: url.protocol.replace(":", ""),
      hostname: url.hostname,
      port: Number(url.port || "443")
    }
  );

  const ipfs = await create({
    config: {
      Addresses: {
        Swarm: listen
      },
      Bootstrap: peers
    }
  });
};

Endpoints

PathDescription
/GraphQL Playground
/graphqlGraphQL Endpoint