Skip to content

Commit

Permalink
feat(website): remove unnecessary awaits + fix random + add title to …
Browse files Browse the repository at this point in the history
…importing-external-modules
  • Loading branch information
afmika committed Apr 25, 2024
1 parent f31b451 commit faab2e4
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/typegraphs/faas-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PythonRuntime } from "@typegraph/sdk/runtimes/python.js";

// skip:end

await typegraph({
typegraph({
name: "faas-runner",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand All @@ -20,7 +20,7 @@ await typegraph({

g.expose({
pycumsum: python.fromLambda(inp, out, {
code: `lambda inp: sum(range(inp["n"])`,
code: `lambda inp: sum(range(inp["n"]))`,
}),
tscumsum: deno.func(
inp,
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/iam-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getEnvOrDefault(key: string, defaultValue: string) {
}
// skip:end

await typegraph({
typegraph({
name: "iam-provider",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { HttpRuntime } from "@typegraph/sdk/runtimes/http.js";

// skip:end

await typegraph({
typegraph({
name: "homepage",
// skip:start
rate: { windowLimit: 2000, windowSec: 60, queryLimit: 200, localExcess: 0 },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

// skip:end

await typegraph({
typegraph({
name: "jwt-authentication",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
// skip:end
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

await typegraph({
typegraph({
name: "math",
// skip:start
rate: { windowLimit: 2000, windowSec: 60, queryLimit: 200, localExcess: 0 },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/microservice-orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getEnvOrDefault(key: string, defaultValue: string) {
}
// skip:end

await typegraph({
typegraph({
name: "team-a",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

// skip:end

await typegraph({
typegraph({
name: "oauth2-authentication",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Auth } from "@typegraph/sdk/params.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";
import { RandomRuntime } from "@typegraph/sdk/runtimes/random.js";

await typegraph({
typegraph({
name: "policies",
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
}, (g) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/prisma-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";

// skip:end

await typegraph({
typegraph({
name: "prisma-runtime",
cors: {
// skip:start
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";

await typegraph({
typegraph({
name: "roadmap-prisma",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/programmable-api-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

// skip:end

await typegraph({
typegraph({
name: "programmable-api-gateway",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/quick-start-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";
import { PythonRuntime } from "@typegraph/sdk/runtimes/python.js";
import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";

await typegraph("example", (g) => {
typegraph("example", (g) => {
// access control
const pub = Policy.public();

Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/random-field.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
name="random-field",
# skip:end
)
def roadmap(g: Graph):
def random_field(g: Graph):
deno = DenoRuntime()
pub = Policy.public()

Expand Down
37 changes: 37 additions & 0 deletions examples/typegraphs/random-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// skip:start
import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

// skip:end

typegraph({
name: "random-field",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
}, (g) => {
const deno = new DenoRuntime();
const pub = Policy.public()

const bonus = t.list(t.enum_(["+1 gold", "+1 metal"]))
const dailyBonus = t.struct(
{
performance: t.integer(),
bonus: bonus.fromRandom(), // this field is now generated randomly
}
)

const seed = Date.now() % 1000;
g.configureRandomInjection({ seed })

g.expose({
get_bonus: deno.func(
dailyBonus,
t.string(),
{
code: ({ performance, bonus }) => `Daily bonus: ${
(performance > 100 ? bonus : ['none']).join(', ')
}`
}
)
}, pub);
});
2 changes: 1 addition & 1 deletion examples/typegraphs/rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RandomRuntime } from "@typegraph/sdk/runtimes/random.js";

// skip:end

await typegraph({
typegraph({
name: "rate",
// highlight-next-line
rate: {
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Auth } from "@typegraph/sdk/params.js";
import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

await typegraph({
typegraph({
name: "roadmap-reduce",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Auth } from "@typegraph/sdk/params.js";
import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

await typegraph({
typegraph({
name: "roadmap-rest",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/roadmap-policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Auth } from "@typegraph/sdk/params.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";
import { PrismaRuntime } from "@typegraph/sdk/providers/prisma.js";

await typegraph({
typegraph({
name: "roadmap-policies",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/roadmap-random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RandomRuntime } from "@typegraph/sdk/runtimes/random.js";
// skip:next-line
/* eslint-disable @typescript-eslint/no-unused-vars */

await typegraph({
typegraph({
name: "roadmap-random",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/typegraphs/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpRuntime } from "@typegraph/sdk/runtimes/http.js";

// skip:end

await typegraph({
typegraph({
name: "triggers",
}, (g) => {
// skip:start
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/import-external-modules/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TGExample from "@site/src/components/TGExample";
import CodeBlock from "@theme-original/CodeBlock";


### Importing External Modules
# Importing External Modules

So far, the materializers we've looked at have been generated by helpers like the CRUD helpers from the Prisma runtime or the the Random runtime's `generate` helper.
The `deno.policy` function we used for authoring policies was also based on function objects.
Expand Down
6 changes: 4 additions & 2 deletions website/docs/reference/runtimes/random/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ One use case is to use this runtime as way of testing, for example you can rapid
The `seed` parameter ensures repeatability if set.

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



Another use case is to inject random values to a materializer input
<TGExample
typegraph="random-field"
python={require("../../../../../examples/typegraphs/random-field.py")}
typescript={require("!!code-loader!../../../../../examples/typegraphs/random-field.ts")}
query={require("./random-field.graphql")}
/>

Expand Down

0 comments on commit faab2e4

Please sign in to comment.