-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): from_random injection (#593)
<!-- Pull requests are squash merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog and understand when they need to update his code and how. --> <!-- Explain WHAT the change is --> This change includes changes in StringFormats(added some string formats), logic to provide random values for type nodes and tests to validate the changes. The changes are mostly in the typegraph sdk. #### Motivation and context <!-- Explain WHY the was made or link an issue number --> This feature enables the user to inject random values for a field(**Type Node**) when defining a **Typegraph**. #### Migration notes _No changes needed_. <!-- Explain HOW users should update their code when required --> ### Checklist - [x] The change come with new or modified tests - [x] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change
- Loading branch information
Showing
28 changed files
with
461 additions
and
53 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typegraph.policy import Policy | ||
from typegraph.runtimes.deno import DenoRuntime | ||
|
||
from typegraph import Graph, t, typegraph | ||
|
||
|
||
@typegraph() | ||
def random_injection(g: Graph): | ||
pub = Policy.public() | ||
deno = DenoRuntime() | ||
|
||
user = t.struct( | ||
{ | ||
"id": t.uuid().from_random(), | ||
"ean": t.ean().from_random(), | ||
"name": t.string(config={"gen": "name"}).from_random(), | ||
"age": t.integer(config={"gen": "age", "type": "adult"}).from_random(), | ||
"married": t.boolean().from_random(), | ||
"birthday": t.datetime().from_random(), | ||
"friends": t.list(t.string(config={"gen": "first"})).from_random(), | ||
"phone": t.string(config={"gen": "phone"}).from_random(), | ||
"gender": t.string(config={"gen": "gender"}).from_random(), | ||
"firstname": t.string(config={"gen": "first"}).from_random(), | ||
"lastname": t.string(config={"gen": "last"}).from_random(), | ||
"occupation": t.string(config={"gen": "profession"}).from_random(), | ||
"street": t.string(config={"gen": "address"}).from_random(), | ||
"city": t.string(config={"gen": "city"}).from_random(), | ||
"postcode": t.string(config={"gen": "postcode"}).from_random(), | ||
"country": t.string( | ||
config={"gen": "country", "full": "true"} | ||
).from_random(), | ||
"uri": t.uri().from_random(), | ||
"hostname": t.string(format="hostname").from_random(), | ||
} | ||
) | ||
|
||
random_list = t.struct( | ||
{ | ||
"names": t.list(t.string(config={"gen": "name"})).from_random(), | ||
} | ||
) | ||
# Configure random injection seed value or the default will be used | ||
g.configure_random_injection(seed=1) | ||
g.expose( | ||
pub, | ||
randomUser=deno.identity(user), | ||
randomList=deno.identity(random_list), | ||
) |
Oops, something went wrong.