graphql-engine/v3
dependabot[bot] e6407fabc8 Bump serde from 1.0.204 to 1.0.206 (#949)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.204 to
1.0.206.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/serde-rs/serde/releases">serde's
releases</a>.</em></p>
<blockquote>
<h2>v1.0.206</h2>
<ul>
<li>Improve support for <code>flatten</code> attribute inside of enums
(<a
href="https://redirect.github.com/serde-rs/serde/issues/2567">#2567</a>,
thanks <a
href="https://github.com/Mingun"><code>@​Mingun</code></a>)</li>
</ul>
<h2>v1.0.205</h2>
<ul>
<li>Use serialize_entry instead of serialize_key + serialize_value when
serialize flattened newtype enum variants (<a
href="https://redirect.github.com/serde-rs/serde/issues/2785">#2785</a>,
thanks <a
href="https://github.com/Mingun"><code>@​Mingun</code></a>)</li>
<li>Avoid triggering a collection_is_never_read lint in the
deserialization of enums containing flattened fields (<a
href="https://redirect.github.com/serde-rs/serde/issues/2791">#2791</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="85c73ef8de"><code>85c73ef</code></a>
Release 1.0.206</li>
<li><a
href="5ba1796a7e"><code>5ba1796</code></a>
Resolve doc_markdown pedantic lint on regression test function</li>
<li><a
href="e52b7b380f"><code>e52b7b3</code></a>
Touch up PR 2567</li>
<li><a
href="84c7419652"><code>84c7419</code></a>
Merge pull request <a
href="https://redirect.github.com/serde-rs/serde/issues/2794">#2794</a>
from dtolnay/neverread</li>
<li><a
href="536221b1f9"><code>536221b</code></a>
Temporarily ignore collection_is_never_read on
FlattenSkipDeserializing</li>
<li><a
href="fc55ac70d3"><code>fc55ac7</code></a>
Merge pull request <a
href="https://redirect.github.com/serde-rs/serde/issues/2567">#2567</a>
from Mingun/fix-2565</li>
<li><a
href="2afe5b4ef9"><code>2afe5b4</code></a>
Add regression test for issue <a
href="https://redirect.github.com/serde-rs/serde/issues/2792">#2792</a></li>
<li><a
href="b4ec2595c9"><code>b4ec259</code></a>
Correctly process flatten fields in enum variants</li>
<li><a
href="c3ac7b675a"><code>c3ac7b6</code></a>
Add regression test for issue <a
href="https://redirect.github.com/serde-rs/serde/issues/1904">#1904</a></li>
<li><a
href="24614e44bf"><code>24614e4</code></a>
Add regression test for issue <a
href="https://redirect.github.com/serde-rs/serde/issues/2565">#2565</a></li>
<li>Additional commits viewable in <a
href="https://github.com/serde-rs/serde/compare/v1.0.204...v1.0.206">compare
view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=serde&package-manager=cargo&previous-version=1.0.204&new-version=1.0.206)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
V3_GIT_ORIGIN_REV_ID: 50cd5a67d87a37060b2197f1355699d5701df396
2024-08-12 08:23:53 +00:00
..
.cargo v3: open-source hasura v3 engine 2023-12-19 09:05:39 +00:00
crates if no plugins make middleware no-op (#948) 2024-08-09 15:33:20 +00:00
docs Update architecture to reflect ir crate (#910) 2024-07-31 06:50:57 +00:00
nix Add cacert to docker image (#782) 2024-06-28 10:06:18 +00:00
rfcs RFC | OpenDD changes for field arguments (#682) 2024-06-10 10:29:26 +00:00
static/auth add AuthConfig v2 example (#937) 2024-08-07 06:51:17 +00:00
.dockerignore Include the dev-auth-webhook crate in the workspace. (#500) 2024-04-24 08:12:37 +00:00
.envrc Add instructions for using the Nix Flake (#547) 2024-05-10 12:27:48 +00:00
.envrc.local.example Add instructions for using the Nix Flake (#547) 2024-05-10 12:27:48 +00:00
.gitignore Set the crate properties once, to improve the Nix build. (#334) 2024-03-06 17:15:13 +00:00
.prettierignore Use "dev" as the version in development for Nix builds. (#665) 2024-06-05 08:20:49 +00:00
.prettierrc Format everything with Prettier. (#530) 2024-04-30 14:58:57 +00:00
Cargo.lock Bump serde from 1.0.204 to 1.0.206 (#949) 2024-08-12 08:23:53 +00:00
Cargo.toml CI: Fix the Rust cache. (#942) 2024-08-07 15:34:22 +00:00
changelog.md [changelog] release v2024.08.07 (#940) 2024-08-07 10:18:59 +00:00
ci.docker-compose.yaml Remove old Docker based building stuff (#876) 2024-07-25 16:16:49 +00:00
CONTRIBUTING.md Add UNSTABLE_FEATURES env var (#652) 2024-06-03 08:50:43 +00:00
custom-connector.Dockerfile Move "test" job to Github Actions (#872) 2024-07-24 13:41:40 +00:00
dev-auth-webhook.Dockerfile Use Rust 1.79.0 (#751) 2024-06-27 22:22:01 +00:00
docker-compose.yaml add AuthConfig v2 example (#937) 2024-08-07 06:51:17 +00:00
Dockerfile Use Rust 1.79.0 (#751) 2024-06-27 22:22:01 +00:00
flake.lock Use Rust 1.79.0 (#751) 2024-06-27 22:22:01 +00:00
flake.nix Fix custom connector schema and update all tests to use up-to-date schema (#826) 2024-07-11 14:15:58 +00:00
justfile CI: Fix the Rust cache. (#942) 2024-08-07 15:34:22 +00:00
README.md add AuthConfig v2 example (#937) 2024-08-07 06:51:17 +00:00
rust-toolchain.toml Use Rust 1.79.0 (#751) 2024-06-27 22:22:01 +00:00

Hasura GraphQL Engine V3

Docs

Hasura V3 is the API execution engine, based over the Open Data Domain Specification (OpenDD spec) and Native Data Connector Specifications (NDC spec), which powers the Hasura Data Delivery Network (DDN). The v3-engine expects to run against an OpenDDS metadata file and exposes a GraphQL endpoint according to the specified metadata. The v3-engine needs a data connector to run alongside, for the execution of data source specific queries.

Data connectors

Hasura v3-engine does not execute queries directly - instead it sends IR (abstracted, intermediate query) to NDC agents (aka data connectors). To run queries on a database, we'll need to run the data connector that supports the database.

Available data connectors are listed at the Connector Hub

For local development, we use the reference agent implementation that is a part of the NDC spec.

To start the reference agent only, you can do:

docker compose up reference_agent

Run v3-engine (with reference agent)

Building locally using cargo

Hasura v3-engine is written in Rust, hence cargo is required to build and run the v3-engine locally.

To start the v3-engine locally, we need a metadata.json file and an auth config file.

Following are steps to run v3-engine with a reference agent (read only, in memory, relational database with sample tables), and an sample metadata file, exposing a fixed GraphQL schema. This can be used to understand the build setup and the new V3 concepts.

RUST_LOG=DEBUG cargo run --release --bin engine -- \
  --metadata-path crates/open-dds/examples/reference.json \
 --authn-config-path static/auth/auth_config.json

A dev webhook implementation is provided in crates/auth/dev-auth-webhook, that exposes the POST /validate-request which accepts converts the headers present in the incoming request to a object containing session variables, note that only headers that start with x-hasura- will be returned in the response.

The dev webhook can be run using the following command:

docker compose up auth_hook

and point the host name auth_hook to localhost in your /etc/hosts file.

Open http://localhost:3000 for GraphiQL.

Use --port option to start v3-engine on a different port.

RUST_LOG=DEBUG cargo run --release --bin engine -- \
     --port 8000 --metadata-path crates/open-dds/examples/reference.json

Now, open http://localhost:8000 for GraphiQL.

Run v3-engine (with Postgres)

Building with Docker

You can also start v3-engine, along with a Postgres data connector and Jaeger for tracing using Docker:

METADATA_PATH=crates/engine/tests/schema.json AUTHN_CONFIG_PATH=static/auth/auth_config.json docker compose up

Open http://localhost:3001 for GraphiQL, or http://localhost:4002 to view traces in Jaeger.

Note: you'll need to add {"x-hasura-role": "admin"} to the Headers section to run queries from GraphiQL.

NDC Postgres is the official connector by Hasura for Postgres Database. For running V3 engine for GraphQL API on Postgres, you need to run NDC Postgres Connector and have a metadata.json file that is authored specifically for your Postgres database and models (tables, views, functions).

The recommended way to author metadata.json for Postgres, is via Hasura DDN.

Follow the Hasura DDN Guide to create a Hasura DDN project, connect your cloud or local Postgres Database (Hasura DDN provides a secure tunnel mechanism to connect your local database easily), and model your GraphQL API. You can then download the authored metadata.json and use the following steps to run GraphQL API on your local Hasura V3 engine.

Steps to run metadata with V3 engine locally

  1. Download metadata from DDN project, using Hasura V3 CLI

    hasura3 build create --dry-run > ddn-metadata.json
    
  2. Following steps are to generate Postgres metadata object and run the Postgres Connector. These steps refer to the NDC Postgres repository:

    1. Start the Postgres connector in configuration mode (Config server). A config server provides additional endpoints for database instrospection and provide the schema of the database. Output of the config server will form the Postgres Metadata object.

    2. Run the following command in the ndc-postgres repository:

      just run-config
      
    3. Generate the postgres configuration using the new-configuration.sh script by running the following command (in another terminal) in the ndc-postgres repository:

      ./scripts/new-configuration.sh localhost:9100 '<postgres database url>' > pg-config.json
      
    4. Now shutdown the postgres config server and start the Postgres Connector using the pg-config.json generated in the above step, by running the following command:

      Please specify different PORT for different data connectors:

      PORT=8100 \
      RUST_LOG=INFO \
          cargo run --bin ndc-postgres --release -- serve --configuration pg-config.json > /tmp/ndc-postgres.log
      
    5. Fetch the schema for the data connector object by running the following command:

      curl -X GET http://localhost:8100/schema | jq . > pg-schema.json
      
    6. Finally, generate the DataConnector object:

      jq --null-input --arg name 'default' --arg port '8100' --slurpfile schema pg-schema.json '{"kind":"DataConnector","version":"v2","definition":{"name":"\($name)","url":{"singleUrl":{"value":"http://localhost:\($port)"}},"schema":$schema[0]}}' > pg-metadata.json
      
  3. Now you have the NDC Postgres connector running, and have obtained the Postgres metadata (pg-metadata.json) which is required for the V3 engine.

  4. In ddn-metadata.json (from step 1.), replace the HasuraHubDataConnector objects with DataConnector objects generated inside the pg-metadata.json file.

  5. Remove the object for kind: AuthConfig from ddn-metadata.json, move it to a separate file auth_config.json, and remove the kind field from it.

  6. Remove the object for kind: CompatibilityConfig from ddn-metadata.json. If desired, a flags field can be added to the OSS metadata to enable the flags corresponding to that compatibility date in the DDN metadata.

  7. Finally, start the v3-engine using the modified metadata using the following command (using the modified ddn-metadata.json and auth_config.json from Step 5):

    RUST_LOG=DEBUG cargo run --release --bin engine -- \
     --metadata-path ddn-metadata.json auth_config.json
    

    You should have the v3-engine up and running at http://localhost:3000

Note: We understand that these steps are not very straightforward, and we intend to continuously improve the developer experience of running OSS V3 Engine.

Running tests

To run the test suite, you need to docker login to ghcr.io first:

docker login -u <username> -p <token> ghcr.io

where username is your github username, and token is your github PAT. The PAT needs to have the read:packages scope and Hasura SSO configured. See this for more details.

Next run the postgres NDC locally using docker compose up postgres_connector and point the host name postgres_connector to localhost in your /etc/hosts file.

Next run the custom NDC locally using docker compose up custom_connector and point the host name custom_connector to localhost in your /etc/hosts file OR you can run cargo run --bin agent and then do cargo test.

Testing/Development with the chinook database

The crates/engine/tests/chinook contains static files required to run v3-engine run with the chinook database as a data connector.

To get this running, you can run the following command:

METADATA_PATH=crates/engine/tests/schema.json AUTHN_CONFIG_PATH=static/auth/auth_config.json docker compose up postgres_connector engine

Running tests with a single command

Alternatively, the tests can be run in the same Docker image as CI:

just test

Updating goldenfiles

There are some tests where we compare the output of the test against an expected golden file. If you make some changes which expectedly change the goldenfile, you can regenerate them like this:

Locally

  UPDATE_GOLDENFILES=1 cargo test

Docker:

  just update-golden-files

Run benchmarks

The benchmarks operate against the reference agent using the same test cases as the test suite, and need a similar setup.

To run benchmarks for the lexer, parser and validation:

cargo bench -p lang-graphql "lexer"
cargo bench -p lang-graphql "parser"
cargo bench -p lang-graphql "validation/.*"