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 #755

Merged
merged 3 commits into from
Jun 22, 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
130 changes: 36 additions & 94 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

First off, thanks for taking the time to contribute! ❤️

All types of contributions are encouraged and valued. Please make sure to read
the relevant section before making your contribution. It will make it a lot
easier for us and smooth out the experience for all involved. The community
looks forward to your contributions. 🎉

> And if you like the project, but just don't have time to contribute, that's
> fine. There are other easy ways to support the project and show your
> appreciation, which we would also be very happy about:
All types of contributions are encouraged and valued. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us and smooth out the experience for all involved. The community looks forward to your contributions. 🎉

> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
>
> - Star the project
> - Tweet about it
Expand All @@ -27,23 +22,15 @@ looks forward to your contributions. 🎉

## Code of Conduct

This project and everyone participating in it is governed by our
[Code of Conduct](https://github.com/metatypedev/metatype/blob/main/CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code.
This project and everyone participating in it is governed by our [Code of Conduct](https://github.com/metatypedev/metatype/blob/main/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.

## I Have a Question

> If you want to ask a question, we assume that you have read the available
> [documentation](https://metatype.dev/docs).
> If you want to ask a question, we assume that you have read the available [documentation](https://metatype.dev/docs).

Before you ask a question, it is best to search for existing
[Issues](https://github.com/metatypedev/metatype/issues) that might help you. In
case you have found a suitable issue and still need clarification, you can write
your question in this issue. It is also advisable to search the internet for
answers first.
Before you ask a question, it is best to search for existing [Issues](https://github.com/metatypedev/metatype/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.

If you then still feel the need to ask a question and need clarification, we
recommend the following:
If you then still feel the need to ask a question and need clarification, we recommend the following:

- Open an [Issue](https://github.com/metatypedev/metatype/issues/new).
- Provide as much context as you can about what you're running into.
Expand All @@ -53,101 +40,59 @@ recommend the following:

> ### Legal Notice
>
> When contributing to this project, you must agree that you have authored 100%
> of the content, that you have the necessary rights to the content and that the
> content you contribute may be provided under the project license.
> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.

### Reporting Bugs

#### Before Submitting a Bug Report

A good bug report shouldn't leave others needing to chase you up for more
information. Therefore, we ask you to investigate carefully, collect information
and describe the issue in detail in your report. Please complete the following
steps in advance to help us fix any potential bug as fast as possible.
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.

- Make sure that you are using the latest version.
- Determine if your bug is really a bug and not an error on your side e.g. using
incompatible environment components/versions (Make sure that you have read the
[documentation](https://metatype.dev/docs). If you are looking for support,
you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the
same issue you are having, check if there is not already a bug report existing
for your bug or error in the
[bug tracker](https://github.com/metatypedev/metatype/issues?q=label%3Abug).
- Also make sure to search the internet (including Stack Overflow) to see if
users outside the GitHub community have discussed the issue.
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://metatype.dev/docs). If you are looking for support, you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/metatypedev/metatype/issues?q=label%3Abug).
- Also make sure to search the internet (including Stack Overflow) to see if users outside the GitHub community have discussed the issue.
- Collect information about the bug:
- Stack trace
- OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
- Version of the interpreter, compiler, SDK, runtime environment, package
manager, depending on what seems relevant.
- Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
- Possibly your input and the output
- Can you reliably reproduce the issue? And can you also reproduce it with older
versions?
- Can you reliably reproduce the issue? And can you also reproduce it with older versions?

#### How Do I Submit a Good Bug Report?

> You must never report security related issues, vulnerabilities or bugs
> including sensitive information to the issue tracker, or elsewhere in public.
> Instead sensitive bugs must be reported according to the
> [Security Policy](https://github.com/metatypedev/metatype/blob/main/SECURITY.md).
> You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be reported according to the [Security Policy](https://github.com/metatypedev/metatype/blob/main/SECURITY.md).

We use GitHub issues to track bugs and errors. If you run into an issue with the
project:
We use GitHub issues to track bugs and errors. If you run into an issue with the project:

- Open an [Issue](https://github.com/metatypedev/metatype/issues/new). (Since we
can't be sure at this point whether it is a bug or not, we ask you not to talk
about a bug yet and not to label the issue.)
- Open an [Issue](https://github.com/metatypedev/metatype/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
- Explain the behavior you would expect and the actual behavior.
- Please provide as much context as possible and describe the _reproduction
steps_ that someone else can follow to recreate the issue on their own. This
usually includes your code. For good bug reports you should isolate the
problem and create a reduced test case.
- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
- Provide the information you collected in the previous section.

### Suggesting Enhancements

This section guides you through submitting an enhancement suggestion for
Metatype, **including completely new features and minor improvements to existing
functionality**. Following these guidelines will help us and the community to
understand your suggestion and find related suggestions.
This section guides you through submitting an enhancement suggestion for Metatype, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help us and the community to understand your suggestion and find related suggestions.

#### Before Submitting an Enhancement

- Make sure that you are using the latest version.
- Read the [documentation](https://metatype.dev/docs) carefully and find out if
the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/metatypedev/metatype/issues) to see if
the enhancement has already been suggested. If it has, add a comment to the
existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's
up to you to make a strong case to convince the project's developers of the
merits of this feature. Keep in mind that we want features that will be useful
to the majority of our users and not just a small subset. If you're just
targeting a minority of users, consider writing an add-on/plugin library.
- Read the [documentation](https://metatype.dev/docs) carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/metatypedev/metatype/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.

#### How Do I Submit a Good Enhancement Suggestion?

Enhancement suggestions are tracked as
[GitHub issues](https://github.com/metatypedev/metatype/issues).
Enhancement suggestions are tracked as [GitHub issues](https://github.com/metatypedev/metatype/issues).

- Use a **clear and descriptive title** for the issue to identify the
suggestion.
- Provide a **step-by-step description of the suggested enhancement** in as many
details as possible.
- **Describe the current behavior** and **explain which behavior you expected to
see instead** and why. At this point you can also tell which alternatives do
not work for you.
- **Explain why this enhancement would be useful** to most Metatype users. You
may also want to point out the other projects that solved it better and which
could serve as inspiration.
- Use a **clear and descriptive title** for the issue to identify the suggestion.
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
- **Explain why this enhancement would be useful** to most Metatype users. You may also want to point out the other projects that solved it better and which could serve as inspiration.

### Your First Code Contribution

Metatype is using a mono-repository approach. This means that all code is
centralized and requires many different tools to work with. The following
sections will guide you through the setup process.
Metatype is using a mono-repository approach. This means that all code is centralized and requires many different tools to work with. The following sections will guide you through the setup process.

#### Dependencies

Expand Down Expand Up @@ -198,21 +143,19 @@ deno run -A dev/test.ts runtimes/prisma/full_prisma_mapping_test.ts # isolated t
deno run -A dev/env.ts # shutdown all envs
```

There are many more developer scripts in the `dev` folder, however most of them
should only be needed for advanced tasks.
There are many more developer scripts in the `dev` folder, however most of them should only be needed for advanced tasks.

#### Commit Messages

Pre-commit hooks enforce some basic checks, namely that all commit messages
follow the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/)
format. This is a simple set of rules that makes review easier and help us to
generate a changelog.
Pre-commit hooks enforce some basic checks, namely that all commit messages follow the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format. This is a simple set of rules that makes review easier and help us to generate a changelog.

#### Faster compilation

We recommend using [sccache](https://github.com/mozilla/sccache) giving a roughly 2x speedup in compilation time once warm.

#### Faster linking

We recommend using [mold](https://github.com/rui314/mold) for Linux targets and
macOS new parallel linker for faster linking. You can use them as aliases or
configure them in your `~/.cargo/config.toml` file.
We recommend using [mold](https://github.com/rui314/mold) for Linux targets and macOS new parallel linker for faster linking. You can use them as aliases or configure them in your `~/.cargo/config.toml` file.

```toml
[target.aarch64-apple-darwin]
Expand All @@ -229,8 +172,7 @@ rustflags = [

#### Local typegraph with Nodejs

Currently, the `typegraph/sdk/node/dist` project is generated dynamically.
Depending on your package manager, the protocol used may differ.
Currently, the `typegraph/sdk/node/dist` project is generated dynamically. Depending on your package manager, the protocol used may differ.

```bash
# uses the `file:..` protocol
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions examples/typegraphs/microservice-orchestration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# skip:start
from os import environ

from typegraph import typegraph, Policy, t, Graph
from typegraph import Graph, Policy, t, typegraph
from typegraph.graph.params import Cors
from typegraph.runtimes import DenoRuntime, GraphQLRuntime

Expand All @@ -25,17 +25,15 @@ def team_a(g: Graph):
)


# @typegraph(
# # skip:next-line
# cors=Cors(allow_origin=["https://metatype.dev", "http://localhost:3000"]),
# )
# def team_b(g: Graph):
# public = Policy.public()
#
# deno = DenoRuntime()
#
# g.expose(
# public,
# version=deno.static(t.integer(), 12),
# record=deno.static(t.struct({"weight": t.integer()}), {"weight": 100}),
# )
@typegraph(
# skip:next-line
cors=Cors(allow_origin=["https://metatype.dev", "http://localhost:3000"]),
)
def team_b(g: Graph):
public = Policy.public()
deno = DenoRuntime()
g.expose(
public,
version=deno.static(t.integer(), 12),
record=deno.static(t.struct({"weight": t.integer()}), {"weight": 100}),
)
61 changes: 44 additions & 17 deletions examples/typegraphs/microservice-orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,47 @@ function getEnvOrDefault(key: string, defaultValue: string) {
}
// skip:end

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

const deno = new DenoRuntime();
const records = new GraphQLRuntime(
getEnvOrDefault("TG_URL", "http://localhost:7890" + "/team-b"),
);

g.expose({
version_team_b: records.query(t.struct({}), t.integer(), ["version"]),
version_team_a: deno.static(t.integer(), 3),
}, pub);
});
typegraph(
{
name: "team-a",
// skip:next-line
cors: { allowOrigin: ["https://metatype.dev", "http://localhost:3000"] },
},
(g) => {
const pub = Policy.public();

const deno = new DenoRuntime();
const records = new GraphQLRuntime(
getEnvOrDefault("TG_URL", "http://localhost:7890" + "/team-b")
);

g.expose(
{
version_team_b: records.query(t.struct({}), t.integer(), ["version"]),
version_team_a: deno.static(t.integer(), 3),
},
pub
);
}
);

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

const deno = new DenoRuntime();

g.expose(
{
version: deno.static(t.integer(), 12),
record: deno.static(t.struct({ weight: t.integer() }), { weight: 100 }),
},
pub
);
}
);
17 changes: 13 additions & 4 deletions website/packages/code-loader-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@ module.exports = async function (source) {
const prefix = commentsPrefix[ext];

if (ext === "py") {
source = await new Promise((resolve) => {
source = await new Promise((resolve, reject) => {
const child = spawn("ruff", ["format", "--line-length", "70", "-"]);
child.stdin.write(source);
child.stdin.end();
let buffer = "";
let stdout = "";
let stderr = "";
child.stdout.on("data", (data) => {
buffer += data;
stdout += data;
});
child.stderr.on("data", (data) => {
stderr += data;
});
child.on("exit", function () {
resolve(buffer);
if (stderr.length > 0) {
reject(new Error(`Failed to format python code: ${stderr}`));
} else {
resolve(stdout);
}
});
});
console.log(this.resourcePath, source);
}

const ret = [];
Expand Down
Loading