diff --git a/website/docs/guides/programmatic-deployment/index.mdx b/website/docs/guides/programmatic-deployment/index.mdx index fd85589d05..8a601e313d 100644 --- a/website/docs/guides/programmatic-deployment/index.mdx +++ b/website/docs/guides/programmatic-deployment/index.mdx @@ -11,19 +11,25 @@ Common use cases: ## Deploy typegraphs -This can be done using the `tgRemove`/`tg_remove` function.\ +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). ```python +import os from os import path -from typegraph import Graph, Policy, t, typegraph + +from typegraph.gen.exports.core import MigrationAction +from typegraph.graph.shared_types import BasicAuth +from typegraph.graph.tg_deploy import ( + TypegraphDeployParams, + tg_deploy, + TypegateConnectionOptions, +) from typegraph.runtimes.deno import DenoRuntime -from typegraph.wit import ArtifactResolutionConfig, MigrationAction, MigrationConfig -from typegraph.utils import unpack_tarb64 -from typegraph.graph.tg_deploy import BasicAuth, TypegraphDeployParams, tg_deploy +from typegraph import Graph, Policy, t, typegraph # Your typegraph @typegraph() @@ -42,41 +48,31 @@ def example(g: Graph): ) # Configure your deployment -tg = example() - -config_params = MigrationConfig( - migration_dir=path.join("prisma-migrations", tg.name), - global_action=MigrationAction( - create=True, - reset=True # allow destructive migrations - ), - runtime_actions=None, -) -artifacts_config = ArtifactResolutionConfig( - prisma_migration=config_params, - prefix=None, - dir=None, # artifacts are resolved relative to this path - disable_artifact_resolution=None, -) -config = TypegraphDeployParams( - base_url="", - auth=BasicAuth(username="", password=""), - artifacts_config=artifacts_config, - secrets={"POSTGRES": ""}, -) - -# Deploy to typegate -res = tg_deploy(tg, config) +def deploy(): + cwd = os.getcwd() + + config: TypegraphDeployParams = TypegraphDeployParams( + typegate=TypegateConnectionOptions( + url="", + auth=BasicAuth("", "") + ), + typegraph_path=os.path.join(cwd, "path/to/typegraph"), + prefix="", + secrets={}, + migrations_dir=path.join("prisma-migrations", example.name), + migration_actions=None, + default_migration_action=MigrationAction( + apply=True, + reset=True, # allow destructive migrations + create=True + ), + ), -migrations = res.typegate["data"]["addTypegraph"]["migrations"] or [] -for item in migrations: - base_dir = artifacts_config.prisma_migration.migration_dir - # Convention, however if migration_dir is absolute then you might want to use that instead - # cwd + tg_name + runtime_name - full_path = path.join(base_dir, item["runtime"]) - unpack_tarb64(item["migrations"], full_path) - print(f"Unpacked migrations at {full_path}") + # Deploy to typegate + result = tg_deploy(example, config) # pass your typegraph function name + return result +res = deploy() ``` @@ -103,44 +99,21 @@ const tg = await typegraph("example", (g) => { }); // Configure your deployment -const artifactsConfig = { - prismaMigration: { - globalAction: { - create: true, - reset: true, // allow destructive migrations - }, - migrationDir: path.join("prisma-migrations", tg.name), - }, - // dir: "." // artifacts are resolved relative to this path -}; const config = { - baseUrl: "", - auth: new BasicAuth("", "");, - secrets: { POSTGRES: "" }, - artifactsConfig, -}; + typegate: { url: "", auth: new BasicAuth("", ""), }, + typegraphPath: "", + prefix: "", + secrets: {}, + migrationsDir: path.join("prisma-migrations", tg.name), + defaultMigrationAction: { + create: true, + reset: true, // allow destructive migrations + }, +} // Deploy to typegate -tgDeploy(tg, config).then(({ typegate }) => { - const selection = typegate?.data?.addTypegraph; - if (selection) { - const { migrations, messages } = selection; - migrations.map(({ runtime, migrations }) => { - // Convention, however if migrationDir is absolute then you might want to use that instead - // cwd + tg_name - const baseDir = artifactsConfig.prismaMigration.migrationDir; - // cwd + tg_name + runtime_name - const fullPath = path.join(baseDir, runtime); - wit_utils.unpackTarb64(migrations, fullPath); - console.log(`Unpacked migrations at ${fullPath}`); - }); - } else { - throw new Error(JSON.stringify(typegate)); - } -}) - .catch(console.error); - +const deployResult = await tgDeploy(tg, config); ``` @@ -153,19 +126,32 @@ Similarly to the above, you can undeploy typegraphs using the `tgRemove`/`tg_rem ```python # .. -from typegraph.graph.tg_deploy import BasicAuth, TypegraphRemoveParams, tg_remove +from typegraph.graph.tg_deploy import ( + TypegateConnectionOptions, + TypegraphDeployParams, + TypegraphRemoveParams, + tg_remove, +) # Your typegraph @typegraph() def example(g: Graph): # .. -tg = example() -res = tg_remove(tg, TypegraphRemoveParams( - base_url="", - auth=BasicAuth(username="", password=""), -)) +def remove(): + result = tg_remove( + example, + params=TypegraphRemoveParams( + typegate=TypegateConnectionOptions( + url = "", + auth = BasicAuth("", "") + ) + ) + ) + + return result +res = remove() # Response from typegate print(res.typegate) ``` @@ -173,7 +159,7 @@ print(res.typegate) ```typescript // .. -import { BasicAuth, tgDeploy } from "@typegraph/sdk/tg_deploy.js"; +import { BasicAuth, tgRemove } from "@typegraph/sdk/tg_deploy.js"; // Your typegraph const tg = await typegraph("example", (g) => { @@ -181,7 +167,7 @@ const tg = await typegraph("example", (g) => { }); const { typegate } = await tgRemove(tg, { - baseUrl: "", + url: "", auth: new BasicAuth("", ""), }); diff --git a/website/shared/projects/tab-first-project-python.mdx b/website/shared/projects/tab-first-project-python.mdx index ae02e9ec69..5872a70ac1 100644 --- a/website/shared/projects/tab-first-project-python.mdx +++ b/website/shared/projects/tab-first-project-python.mdx @@ -97,7 +97,10 @@ With these simple steps, you were able to build a basic backend with database ca {require("../../../examples/typegraphs/quick-start-project.py").content} -You are almost there to test your first `Metatype` application. You now need to spin a [Tyepgate](/docs/reference/typegate) and deploy your typegraph to the instance. You can leverage the embedded typegate that comes with the _Meta_CLI_. To run the embedded typegate, you can follow this [reference](/docs/reference/meta-cli/embedded-typegate). +You are almost there to test your first `Metatype` application. You now need to spin a [Tyepgate](/docs/reference/typegate) and deploy your typegraph to the instance. You can leverage the embedded typegate that comes with the _Meta_CLI_. To run the [embedded typegate](/docs/reference/meta-cli/embedded-typegate), execute the following command from your terminal. +```shell +meta typegate +``` Once you started your typegate instance using one of the available choice, if you open [localhost:7890](http://localhost:7890) in your browser, you will get a webpage similar to this one. diff --git a/website/shared/projects/tab-first-project-ts.mdx b/website/shared/projects/tab-first-project-ts.mdx index f09564d46a..7b1f0026eb 100644 --- a/website/shared/projects/tab-first-project-ts.mdx +++ b/website/shared/projects/tab-first-project-ts.mdx @@ -105,7 +105,9 @@ With these three simple steps, you were able to build a basic backend with datab } -You are almost there to test your first `Metatype` application. You now need to spin a [Tyepgate](/docs/reference/typegate) and deploy your typegraph to the instance. You can leverage the embedded typegate that comes with the _Meta_CLI_. To run the embedded typegate, you can follow this [reference](/docs/reference/meta-cli/embedded-typegate). +You are almost there to test your first `Metatype` application. You now need to spin a [Tyepgate](/docs/reference/typegate) and deploy your typegraph to the instance. You can leverage the embedded typegate that comes with the _Meta_CLI_. To run the [embedded typegate](/docs/reference/meta-cli/embedded-typegate), execute the following command from your terminal. +```shell +meta typegate Once you started your typegate instance using one of the available choice, if you open [localhost:7890](http://localhost:7890) in your browser, you will get a webpage similar to this one.