Skip to main content

Programmatic deployment

The SDKs are complete enough to enable deploying typegraphs without using meta cli, the later being built as a convenience tool for everyday use.

Common use cases:

  • Testing
  • Manage everything programmatically

Deploy typegraphs

This can be done using the tgDeploy/tg_deploy function.
You are required to provide the configurations and also handle migrations by yourself (if any).

import { Policy, t, typegraph } from "@typegraph/sdk/index.ts";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.ts";
// deno-lint-ignore no-external-import
import * as path from "node:path";
import { BasicAuth, tgDeploy } from "@typegraph/sdk/tg_deploy.ts";

// Your typegraph
export const tg = await typegraph("example", (g) => {
const deno = new DenoRuntime();
const pub = Policy.public();

g.expose(
{
sayHello: deno.import(t.struct({ name: t.string() }), t.string(), {
module: "scripts/say_hello.ts",
name: "sayHello",
}),
},
pub,
);
});

// Configure your deployment
let baseUrl = "<TYPEGATE_URL>";
let auth = new BasicAuth("<USERNAME>", "<PASSWORD>");

const config = {
typegate: {
url: baseUrl,
auth: auth,
},
typegraphPath: path.join(cwd, "path-to-typegraph.ts"),
prefix: "",
secrets: {},
migrationsDir: path.join("prisma-migrations", tg.name),
defaultMigrationAction: {
apply: true,
create: true,
reset: true, // allow destructive migrations
},
};

// Deploy to typegate
const deployResult = await tgDeploy(tg, config);

Undeploy typegraphs

Similarly to the above, you can undeploy typegraphs using the tgRemove/tg_remove function.

import { typegraph } from "@typegraph/sdk/index.ts";
import { BasicAuth, tgRemove } from "@typegraph/sdk/tg_deploy.ts";

// Your typegraph
const tg = await typegraph("example", (_g) => {
// ...
});


// Response from typegate,
const result = await tgRemove(tg.name, {
// pass the typegraph name
typegate: {
url: baseUrl,
auth: auth,
},
});