Skip to content

Commit 357758e

Browse files
authored
Merge branch 'main' into MET-432--Uploading-PythonRuntime-files-
2 parents 94e72cb + 6054534 commit 357758e

File tree

5 files changed

+69
-59
lines changed

5 files changed

+69
-59
lines changed

examples/typegraphs/temporal.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typegraph import t, typegraph, Policy, Graph
2+
from typegraph.providers.temporal import TemporalRuntime
3+
import os
4+
5+
6+
@typegraph()
7+
def temporal(g: Graph):
8+
public = Policy.public()
9+
temporal = TemporalRuntime(
10+
"<name>", "<host_secret>", namespace_secret="<ns_secret>"
11+
)
12+
13+
workflow_id = os.getenv("ID_FROM_ENV")
14+
arg = t.struct({"some_field": t.string()})
15+
16+
g.expose(
17+
public,
18+
start=temporal.start_workflow("<workflow_type>", arg),
19+
query=temporal.query_workflow("<query_type>", arg, t.string()),
20+
signal=temporal.signal_workflow("<signal_name>", arg),
21+
describe=temporal.describe_workflow().reduce({"workflow_id": workflow_id})
22+
if workflow_id
23+
else temporal.describe_workflow(),
24+
)

examples/typegraphs/temporal.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
2+
import { TemporalRuntime } from "@typegraph/sdk/providers/temporal.js";
3+
4+
// skip:start
5+
function getEnvVariable(key: string, defaultValue?: string): string | undefined {
6+
const glob = globalThis as any;
7+
const value = glob?.process
8+
? glob?.process.env?.[key]
9+
: glob?.Deno.env.get(key);
10+
return value ?? defaultValue;
11+
}
12+
// skip:end
13+
14+
typegraph({ name: "temporal" }, (g: any) => {
15+
const pub = Policy.public();
16+
const temporal = new TemporalRuntime({
17+
name: "<name>",
18+
hostSecret: "<host_secret>",
19+
namespaceSecret: "<ns_secret>",
20+
});
21+
22+
const workflow_id = getEnvVariable("ID_FROM_ENV");
23+
const arg = t.struct({ some_field: t.string() });
24+
25+
g.expose({
26+
start: temporal.startWorkflow("<workflow_type>", arg),
27+
query: temporal.queryWorkflow("<query_type>", arg, t.string()),
28+
signal: temporal.signalWorkflow("<signal_name>", arg),
29+
describe: workflow_id
30+
? temporal.describeWorkflow().reduce({ workflow_id })
31+
: temporal.describeWorkflow(),
32+
}, pub);
33+
});

website/docs/reference/runtimes/graphql/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import TGExample from "@site/src/components/TGExample";
44

55
## GraphQL runtime
66

7-
You currently have a single model to describe messages sent in the chat-based app. A reasonable next step is to add a user model and make a link between the two. While you can store users in the same database, it's wiser to avoid data duplication and re-use your service for user management available at [GraphQLZero](https://graphqlzero.almansi.me) endpoint. Let's introduce the [GraphQL](https://spec.graphql.org/October2021/) runtime that allows remote GraphQL queries.
7+
While you can store users in the same database, it's wiser to avoid data duplication and re-use your service for user management available at [GraphQLZero](https://graphqlzero.almansi.me) endpoint. Let's introduce the [GraphQL](https://spec.graphql.org/October2021/) runtime that allows remote GraphQL queries.
88

99
Update `typegraph.py` with the highlighted lines below:
1010

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
import SDKTabs from "@site/src/components/SDKTabs";
3-
import TabItem from "@theme/TabItem";
2+
import TGExample from "@site/src/components/TGExample";
43

54
# Temporal
65

@@ -20,63 +19,15 @@ An interesting use case is to dynamically describe the operations you want to ex
2019

2120
Here is a simple example of a typegraph that takes some value from an environment variable.
2221

23-
<SDKTabs>
24-
<TabItem value="python">
25-
```python
26-
from typegraph import t, typegraph, Policy, Graph
27-
from typegraph.providers.temporal import TemporalRuntime
28-
import os
2922

30-
@typegraph()
31-
def temporal(g: Graph):
32-
public = Policy.public()
33-
temporal = TemporalRuntime(
34-
"<name>", "<host_secret>", namespace_secret="<ns_secret>"
35-
)
23+
<TGExample
24+
typegraph="temporal"
25+
python={require("../../../../../examples/typegraphs/temporal.py")}
26+
typescript={require("!!code-loader!../../../../../examples/typegraphs/temporal.ts")}
27+
disablePlayground={true}
28+
query={{content: ""}}
29+
/>
3630

37-
workflow_id = os.getenv("ID_FROM_ENV")
38-
arg = t.struct({"some_field": t.string()})
39-
40-
g.expose(
41-
public,
42-
start=temporal.start_workflow("<workflow_type>", arg),
43-
query=temporal.query_workflow("<query_type>", arg, t.string()),
44-
signal=temporal.signal_workflow("<signal_name>", arg),
45-
describe=temporal.describe_workflow().reduce(
46-
{"workflow_id": workflow_id }
47-
) if id else temporal.describe_workflow(),
48-
)
49-
50-
```
51-
</TabItem>
52-
<TabItem value="typescript">
53-
```typescript
54-
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
55-
import { TemporalRuntime } from "@typegraph/sdk/providers/temporal.js";
56-
57-
typegraph({ name: "temporal" }, (g) => {
58-
const public = Policy.public();
59-
const temporal = new TemporalRuntime({
60-
name: "<name>",
61-
hostSecret: "<host_secret>",
62-
namespaceSecret: "<ns_secret>",
63-
});
64-
65-
const workflow_id = process.env.ID_FROM_ENV;
66-
const arg = t.struct({ some_field: t.string() });
67-
68-
g.expose({
69-
start: temporal.startWorkflow("<workflow_type>", arg),
70-
query: temporal.queryWorkflow("<query_type>", arg, t.string()),
71-
signal: temporal.signalWorkflow("<signal_name>", arg),
72-
describe: workflow_id
73-
? temporal.describeWorkflow().reduce({ workflow_id })
74-
: temporal.describeWorkflow(),
75-
}, public);
76-
});
77-
```
78-
</TabItem>
79-
</SDKTabs>
8031

8132

8233
<!-- TODO: setup a test temporal cluster and workflow for demo purposes -->

website/src/components/MiniQL/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface MiniQLProps {
3434
panel?: Panel;
3535
noTool?: boolean;
3636
defaultMode?: keyof typeof modes | null;
37+
disablePlayground: boolean
3738
}
3839

3940
function Loader() {
@@ -55,6 +56,7 @@ function MiniQLBrowser({
5556
panel = "",
5657
noTool = false,
5758
defaultMode = null,
59+
disablePlayground = false,
5860
}: MiniQLProps) {
5961
const {
6062
siteConfig: {
@@ -125,7 +127,7 @@ function MiniQLBrowser({
125127
</ChoicePicker>
126128
</div>
127129
) : null}
128-
{!defaultMode || mode === "playground" ? (
130+
{!disablePlayground && (!defaultMode || mode === "playground") ? (
129131
<div className="flex flex-col graphiql-container">
130132
<div className="flex-1 graphiql-session">
131133
<GraphiQLInterface defaultTab={panel} noTool={noTool} />

0 commit comments

Comments
 (0)