Skip to content

Commit 2d992a3

Browse files
committed
chore(sdk, test): python sdk wasm refactor, fix python wasm and python_wasi tests
1 parent e77e815 commit 2d992a3

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

typegate/tests/runtimes/python_wasi/python_wasi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def python_wasi(g: Graph):
9797
TypegraphDeployParams(
9898
base_url=gate,
9999
auth=auth,
100-
typegraph_path=os.path.join(cwd, "wasmedge.py"),
100+
typegraph_path=os.path.join(cwd, "python_wasi.py"),
101101
artifacts_config=ArtifactResolutionConfig(
102102
dir=cwd,
103103
prefix=None,

typegate/tests/runtimes/wasm/wasm.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import os
2+
import sys
3+
4+
from typegraph.gen.exports.core import (
5+
ArtifactResolutionConfig,
6+
MigrationAction,
7+
MigrationConfig,
8+
)
9+
from typegraph.graph.shared_types import BasicAuth
10+
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
111
from typegraph.graph.typegraph import Graph
212
from typegraph.policy import Policy
313
from typegraph.runtimes.wasm import WasmRuntime
@@ -18,3 +28,32 @@ def wasm_py(g: Graph):
1828
func="add",
1929
).with_policy(pub),
2030
)
31+
32+
33+
cwd = sys.argv[1]
34+
PORT = sys.argv[2]
35+
gate = f"http://localhost:{PORT}"
36+
auth = BasicAuth("admin", "password")
37+
38+
wasm_tg = wasm_py()
39+
deploy_result = tg_deploy(
40+
wasm_tg,
41+
TypegraphDeployParams(
42+
base_url=gate,
43+
auth=auth,
44+
typegraph_path=os.path.join(cwd, "wasm.py"),
45+
artifacts_config=ArtifactResolutionConfig(
46+
dir=cwd,
47+
prefix=None,
48+
disable_artifact_resolution=None,
49+
codegen=None,
50+
prisma_migration=MigrationConfig(
51+
migration_dir="prisma-migrations",
52+
global_action=MigrationAction(reset=False, create=True),
53+
runtime_actions=None,
54+
),
55+
),
56+
),
57+
)
58+
59+
print(deploy_result.serialized)

typegate/tests/runtimes/wasm/wasm_test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ const auth = new BasicAuth("admin", "password");
1313
Meta.test(
1414
{
1515
name: "Wasm runtime",
16+
port: true,
17+
systemTypegraphs: true,
1618
},
1719
async (t) => {
1820
const e = await t.engineFromTgDeployPython("runtimes/wasm/wasm.py", cwd);
1921

2022
await t.should("works", async () => {
2123
await gql`
22-
query {
23-
test(a: 1, b: 2)
24-
}
25-
`
24+
query {
25+
test(a: 1, b: 2)
26+
}
27+
`
2628
.expectData({
2729
test: 3,
2830
})

typegraph/python/typegraph/runtimes/wasm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from dataclasses import dataclass
44
from typing import List, Optional
55

6-
from typegraph import t
76
from typegraph.gen.exports.runtimes import (
87
BaseMaterializer,
98
Effect,
@@ -14,6 +13,8 @@
1413
from typegraph.runtimes.base import Materializer, Runtime
1514
from typegraph.wit import runtimes, store
1615

16+
from typegraph import t
17+
1718

1819
class WasmRuntime(Runtime):
1920
def __init__(self):
@@ -29,12 +30,11 @@ def from_wasm(
2930
effect: Optional[Effect] = None,
3031
):
3132
effect = effect or EffectRead()
32-
wasm = f"file:{wasm}"
3333

3434
mat_id = runtimes.from_wasm_module(
3535
store,
3636
BaseMaterializer(runtime=self.id.value, effect=effect),
37-
MaterializerWasm(module=wasm, func_name=func),
37+
MaterializerWasm(wasm_artifact=wasm, func_name=func),
3838
)
3939

4040
if isinstance(mat_id, Err):

0 commit comments

Comments
 (0)