Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing typegraphs #741

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/typegraphs/http-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// skip:start
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";

// isort: off
// skip:end
// highlight-next-line
import { HttpRuntime } from "@typegraph/sdk/runtimes/http.js";

await typegraph(
{
name: "http-example",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
},
(g) => {
// highlight-next-line
const facts = new HttpRuntime("https://uselessfacts.jsph.pl/api/v2/facts");
const pub = Policy.public();

g.expose(
{
facts: facts.get(
t.struct({
language: t.enum_(["en", "de"]),
}),
t.struct({
id: t.string(),
text: t.string(),
source: t.string(),
source_url: t.string(),
language: t.string(),
permalink: t.string(),
}),
{
path: "/random",
}
),
facts_as_text: facts.get(
t.struct({
header_accept: t.string().set("text/plain"),
language: t.enum_(["en", "de"]),
}),
t.string(),
{ path: "/random", headerPrefix: "header_" }
),
},
pub
);
}
);
2 changes: 1 addition & 1 deletion website/docs/concepts/features-overview/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ We're taking any and all kinds of feature requests, suggestions and recommendati
rows={[
[
<TGExample
python={require("../../../../examples/typegraphs/first-typegraph.py")}
python={require("!!code-loader!../../../../examples/typegraphs/first-typegraph.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/first-typegraph.ts")}
disablePlayground
/>,
Expand Down
4 changes: 2 additions & 2 deletions website/docs/concepts/mental-model/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This computing model brings numerous advantages:
**Types** are the building block of typegraphs. They define a type system describing all data objects processed in Metatype. They can be easily extended to support new data types according to the needs of the application.

<CodeBlock language="python">
{require("../../../../examples/typegraphs/types.py").content}
{require("!!code-loader!../../../../examples/typegraphs/types.py").content}
</CodeBlock>

**Analogy in SQL**: types are similar to the Data Definition Language (DDL) with the extended capacity of describing any type of data.
Expand Down Expand Up @@ -101,7 +101,7 @@ The policy decision can be:
Triggers are events launching the execution of one or multiple functions. They fire when a GraphQL request is received for the specific typegraph.

<CodeBlock language="python">
{require("../../../../examples/typegraphs/triggers.py").content}
{require("!!code-loader!../../../../examples/typegraphs/triggers.py").content}
</CodeBlock>

**Analogy in SQL**: a trigger is similar to receiving a new query.
2 changes: 1 addition & 1 deletion website/docs/reference/runtimes/deno/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The DenoRuntime allows you to run lightweight and short-lived typescript functio

<TGExample
typegraph="deno"
python={require("../../../../../examples/typegraphs/deno.py")}
typescript={require("!!code-loader!../../../../../examples/typegraphs/deno.ts")}
python={require("!!code-loader!../../../../../examples/typegraphs/deno.py")}
query={require("./deno.graphql")}
/>

Expand Down
1 change: 1 addition & 0 deletions website/docs/reference/runtimes/http/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Common use cases (but not limited to):
Example:
<TGExample
typegraph="http-runtime"
typescript={require("!!code-loader!../../../../../examples/typegraphs/http-runtime.ts")}
python={require("../../../../../examples/typegraphs/http-runtime.py")}
query={require("./http.graphql")}
/>
Expand Down
2 changes: 1 addition & 1 deletion website/docs/reference/runtimes/random/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The `seed` parameter ensures repeatability if set.
Another use case is to inject random values to a function input
<TGExample
typegraph="random-field"
python={require("../../../../../examples/typegraphs/random-field.py")}
python={require("!!code-loader!../../../../../examples/typegraphs/random-field.py")}
typescript={require("!!code-loader!../../../../../examples/typegraphs/random-field.ts")}
query={require("./random-field.graphql")}
/>
Expand Down
10 changes: 7 additions & 3 deletions website/docs/reference/runtimes/random/random-field.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
query {
bonus1: get_bonus(performance: 200)
bonus2: get_bonus(performance: 27)
}
bonus1: get_bonus(
performance: 200
)
bonus2: get_bonus(
performance: 27
)
}
2 changes: 1 addition & 1 deletion website/docs/reference/typegate/synchronization/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- a Redis database and a s3-compatible object store. -->
The typegate run in either on of the following modes:
- _Single instance mode:_ a single typegate instance runs all the workloads;
- _Synchronized mode:_ the workloads can be shared accross multiple typegraph instances.
- _Synchronized mode:_ the workloads can be shared accross multiple typegate instances.

## System setup

Expand Down
12 changes: 6 additions & 6 deletions website/docs/tutorials/metatype-basics/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Or, you can mess around on the playground below.

<TGExample
typegraph="first-typegraph"
python={require("../../../../examples/typegraphs/first-typegraph.py")}
python={require("!!code-loader!../../../../examples/typegraphs/first-typegraph.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/first-typegraph.ts")}
query={require("./query.graphql")}
/>
Expand Down Expand Up @@ -576,7 +576,7 @@ We should be able to add a few buckets and ideas now.

<TGExample
typegraph="roadmap-prisma"
python={require("../../../../examples/typegraphs/prisma.py")}
python={require("!!code-loader!../../../../examples/typegraphs/prisma.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/prisma.ts")}
query={require("./prisma.graphql")}
/>
Expand Down Expand Up @@ -691,8 +691,8 @@ If you are using the GraphiQl interface from earlier, there should be a panel in

<TGExample
typegraph="roadmap-policies"
python={require("../../../../examples/typegraphs/policies.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/policies.ts")}
python={require("../../../../examples/typegraphs/roadmap-policies.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/roadmap-policies.ts")}
query={require("./policies.graphql")}
/>

Expand Down Expand Up @@ -830,7 +830,7 @@ mutation {

<TGExample
typegraph="roadmap-reduce"
python={require("../../../../examples/typegraphs/reduce.py")}
python={require("!!code-loader!../../../../examples/typegraphs/reduce.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/reduce.ts")}
query={require("./reduce.graphql")}
/>
Expand Down Expand Up @@ -913,7 +913,7 @@ Our query is exposed like any other function in the GraphQl api.

<TGExample
typegraph="roadmap-execute"
python={require("../../../../examples/typegraphs/execute.py")}
python={require("!!code-loader!../../../../examples/typegraphs/execute.py")}
typescript={require("!!code-loader!../../../../examples/typegraphs/execute.ts")}
query={require("./execute.graphql")}
/>
Expand Down