-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
548 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
from typegraph import TypeGraph, policies, t | ||
from typegraph.runtimes.random import RandomMat, RandomRuntime | ||
from typegraph_next import t, typegraph | ||
from typegraph_next.graph.typegraph import Graph | ||
from typegraph_next.policy import Policy | ||
from typegraph_next.runtimes.random import RandomRuntime | ||
|
||
with TypeGraph(name="random") as g: | ||
runtime_1 = RandomRuntime(seed=1) | ||
runtime_2 = RandomRuntime(seed=1) | ||
rec = t.struct( | ||
{ | ||
"uuid": t.uuid(), | ||
"int": t.integer(), | ||
"str": t.string(), | ||
"email": t.email(), | ||
} | ||
) | ||
|
||
rec = t.struct( | ||
{ | ||
"uuid": t.uuid(), | ||
"int": t.integer(), | ||
"str": t.string(), | ||
"email": t.email(), | ||
} | ||
) | ||
users = t.struct( | ||
{ | ||
"id": t.uuid(), | ||
"name": t.string(config={"gen": "name"}), | ||
"age": t.integer(config={"gen": "age", "type": "adult"}), | ||
"address": t.struct( | ||
{ | ||
"street": t.string(config={"gen": "address"}), | ||
"city": t.string(config={"gen": "city"}), | ||
"postcode": t.string(config={"gen": "postcode"}), | ||
"country": t.string(config={"gen": "country", "full": True}), | ||
} | ||
), | ||
} | ||
) | ||
|
||
users = t.struct( | ||
{ | ||
"id": t.uuid(), | ||
"name": t.string().config(gen="name"), | ||
"age": t.integer().config(gen="age", type="adult"), | ||
"address": t.struct( | ||
{ | ||
"street": t.string().config(gen="address"), | ||
"city": t.string().config(gen="city"), | ||
"postcode": t.string().config(gen="postcode"), | ||
"country": t.string().config(gen="country", full=True), | ||
} | ||
), | ||
} | ||
).named("User") | ||
list = t.struct( | ||
{ | ||
"array_of_array_of_names": t.array(t.array(t.string(config={"gen": "name"}))), | ||
} | ||
) | ||
|
||
list = t.struct( | ||
{ | ||
"array_of_array_of_names": t.array(t.array(t.string().config(gen="name"))), | ||
} | ||
).named("RandomList") | ||
|
||
public = policies.public() | ||
@typegraph() | ||
def test_random(g: Graph): | ||
runtime_1 = RandomRuntime(seed=1) | ||
runtime_2 = RandomRuntime(seed=1) | ||
|
||
pub = Policy.public() | ||
|
||
g.expose( | ||
randomRec=t.gen(rec, RandomMat(runtime=runtime_1)).add_policy(public), | ||
randomUser=t.gen(g("User"), RandomMat(runtime=runtime_1)).add_policy(public), | ||
randomList=t.gen(g("RandomList"), RandomMat(runtime=runtime_2)).add_policy( | ||
public | ||
), | ||
randomRec=runtime_1.gen(rec).with_policy(pub), | ||
randomUser=runtime_1.gen(users).with_policy(pub), | ||
randomList=runtime_2.gen(list).with_policy(pub), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
import { Policy, t, typegraph } from "@typegraph/deno/src/mod.ts"; | ||
import { RandomRuntime } from "@typegraph/deno/src/runtimes/random.ts"; | ||
|
||
typegraph("random", (g) => { | ||
const random = new RandomRuntime({ seed: 1, reset: "" }); | ||
const pub = Policy.public(); | ||
|
||
g.expose({ | ||
test1: random.gen( | ||
t.struct({ | ||
email: t.email(), | ||
country: t.string({}, { config: { gen: "country", full: true } }), | ||
}), | ||
).withPolicy(pub), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
import { gql, Meta } from "../utils/mod.ts"; | ||
|
||
Meta.test("Random", async (t) => { | ||
Meta.test("Python: Random", async (t) => { | ||
const e = await t.engine("random/random.py"); | ||
|
||
await t.should("work", async () => { | ||
|
@@ -67,34 +67,80 @@ Meta.test("Random", async (t) => { | |
array_of_array_of_names | ||
} | ||
} | ||
`.expectData( | ||
{ | ||
randomList: { | ||
array_of_array_of_names: [ | ||
[ | ||
"Clayton Tate", | ||
"Martin Neal", | ||
"Charlie Soto", | ||
"Jared Ramirez", | ||
"Hilda Bowers", | ||
"Derek French", | ||
], | ||
[ | ||
"Jessie Garza", | ||
"Ricardo Maxwell", | ||
"Phillip Curtis", | ||
"Wesley Sparks", | ||
"Russell Lucas", | ||
"Tillie Cohen", | ||
"Herman Burgess", | ||
"Carolyn Potter", | ||
"Howard Patton", | ||
"Ethan Brady", | ||
` | ||
.expectData( | ||
{ | ||
randomList: { | ||
array_of_array_of_names: [ | ||
[ | ||
"Olivia Smith", | ||
"Sean Atkins", | ||
"Arthur Parker", | ||
"Jack Chavez", | ||
"Hunter Franklin", | ||
"Betty Gill", | ||
"Louis Reeves", | ||
"Rosa Hansen", | ||
"Blanche White", | ||
"Essie Marsh", | ||
], | ||
[ | ||
"Caleb Meyer", | ||
"Glen Hayes", | ||
"Bernice Delgado", | ||
"Bernice Rose", | ||
"Ronnie Vargas", | ||
], | ||
[ | ||
"Marguerite Tyler", | ||
"Erik Robinson", | ||
"Gregory King", | ||
"Essie Collins", | ||
"Henrietta Cummings", | ||
"Esther Wade", | ||
"Shane Holmes", | ||
"Jacob Warner", | ||
"Gussie Castillo", | ||
], | ||
["Julian Curry"], | ||
[ | ||
"Lelia Daniels", | ||
"Gabriel Webster", | ||
"Ronald Baker", | ||
"Dale Owen", | ||
"Harry Poole", | ||
"Frank Ward", | ||
"Margaret Perez", | ||
"Verna Wallace", | ||
"Flora Daniels", | ||
"Derek Allen", | ||
], | ||
], | ||
], | ||
}, | ||
}, | ||
) | ||
.on(e); | ||
}); | ||
}); | ||
|
||
Meta.test("Deno: Random", async (t) => { | ||
const e = await t.engine("random/random.ts"); | ||
|
||
await t.should("work", async () => { | ||
await gql` | ||
query { | ||
test1 { | ||
country | ||
} | ||
} | ||
` | ||
.expectData({ | ||
test1: { | ||
email: "[email protected]", | ||
country: "Guyana", | ||
}, | ||
}, | ||
) | ||
}) | ||
.on(e); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.