Skip to content

Commit

Permalink
wip: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Aug 1, 2024
1 parent bfee2f2 commit a48203a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
61 changes: 61 additions & 0 deletions examples/stuff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { fx, Policy, t, typegraph } from "@typegraph/sdk/index.ts";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.ts";

const genUser = () => ({
id: "69099108-e48b-43c9-ad02-c6514eaad6e3",
email: "yuse@mail.box",
});

const genPosts = () => [
{ slug: "hair", title: "I dyed my hair!" },
{ slug: "hello", title: "Hello World!" },
];

await typegraph({
name: "sample",
builder(g) {
const deno = new DenoRuntime();
const post = t.struct({
slug: t.string(),
title: t.string(),
}, { name: "Post" });

const getPosts = deno.func(
t.struct({ filter: t.string().optional() }).rename("GetPostsInput"),
t.list(post),
{
code: genPosts,
effect: fx.read(),
},
).withPolicy(Policy.public());

const user = t.struct({
id: t.uuid(),
email: t.email(),
posts: getPosts,
}, { name: "User" });

g.expose(
{
getUser: deno.func(
t.struct({ id: t.string() }).rename("GetUserInput"),
user,
{
code: genUser,
effect: fx.read(),
},
),
getPosts,

noArgs: deno.func(t.struct({}), user, { code: genUser }),
scalar: deno.func(t.struct({ name: t.string() )}), t.string(), {
code: ({name}) => `hello ${name}`,
}),
},
Policy.public(),
);
},
}).catch((err) => {
console.log(err);
throw err;
});
14 changes: 7 additions & 7 deletions libs/metagen/src/client_py/static/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NodeArgValue:
value: Any

NodeArgs = Dict[str, NodeArgValue]
Out = TypeVar("Out")
Out = TypeVar("Out", covariant=True)


@dataclass
Expand Down Expand Up @@ -462,17 +462,17 @@ def __init__(self):
"Optional4": "Any",
}

def get_user(self, args: UserArgs, select: UserSelectParams):
def get_user(self, args: UserArgs, select: UserSelectParams) -> QueryNode[User]:
node = selection_to_nodes(
{"getUser": (args, select)}, {"getUser": NodeDescs.Func19()}, "$q"
)
return node[0]
)[0]
return QueryNode(name=node.name, args=node.args, sub_nodes=node.sub_nodes)

def get_post(self, args: PostArgs, select: PostSelectParams):
def get_post(self, args: PostArgs, select: PostSelectParams) -> QueryNode[Post]:
node = selection_to_nodes(
{"getPosts": (args, select)}, {"getPosts": NodeDescs.Func9()}, "$q"
)
return node[0]
)[0]
return QueryNode(name=node.name, args=node.args, sub_nodes=node.sub_nodes)


qg = QueryGraph()
Expand Down

0 comments on commit a48203a

Please sign in to comment.