Skip to content

Commit

Permalink
Merge branch 'main' into kc/test-registry-automation
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik authored Jul 16, 2024
2 parents b3521ad + a501e37 commit 435c203
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 1 deletion.
18 changes: 17 additions & 1 deletion registry/mongodb/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tags": [
"database"
],
"latest_version": "v0.1.0"
"latest_version": "v1.0.0"
},
"author": {
"support_email": "[email protected]",
Expand All @@ -17,6 +17,17 @@
"is_verified": true,
"is_hosted_by_hasura": false,
"packages": [
{
"version": "1.0.0",
"uri": "https://github.com/hasura/ndc-mongodb/releases/download/v1.0.0/connector-definition.tgz",
"checksum": {
"type": "sha256",
"value": "0dc038620f40911a2c5662b61d8e2ac9605876c80b3eb3cbae5cc1ebcd5b611f"
},
"source": {
"hash": "4beb7ddabddc3035ca5cc7bd85493a71a2e34147"
}
},
{
"version": "0.1.0",
"uri": "https://github.com/hasura/ndc-mongodb/releases/download/v0.1.0/connector-definition.tgz",
Expand Down Expand Up @@ -99,6 +110,11 @@
"is_open_source": true,
"repository": "https://github.com/hasura/ndc-mongodb/",
"version": [
{
"tag": "v1.0.0",
"hash": "4beb7ddabddc3035ca5cc7bd85493a71a2e34147",
"is_verified": true
},
{
"tag": "v0.1.0",
"hash": "175272912b86a11359a9b6b7fd72c7a6e2326bf1",
Expand Down
169 changes: 169 additions & 0 deletions registry/mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# MySQL Connector

[![Docs](https://img.shields.io/badge/docs-v3.x-brightgreen.svg?style=flat)](https://hasura.io/docs/3.0/getting-started/overview/)
[![ndc-hub](https://img.shields.io/badge/ndc--hub-sqlserver-blue.svg?style=flat)](https://hasura.io/connectors/sqlserver)
[![License](https://img.shields.io/badge/license-Apache--2.0-purple.svg?style=flat)](LICENSE.txt)
[![Status](https://img.shields.io/badge/status-alpha-yellow.svg?style=flat)](./readme.md)

With this connector, Hasura allows you to instantly create a real-time GraphQL API on top of your data models in
MySQL. This connector supports MySQL's functionalities listed in the table below, allowing for
efficient and scalable data operations. Additionally, users benefit from all the powerful features of Hasura’s Data
Delivery Network (DDN) platform, including query pushdown capabilities that delegate query operations to the database,
thereby enhancing query optimization and performance.

This connector implements the [Data Connector Spec](https://github.com/hasura/ndc-spec).

- [Connector information in the Hasura Hub](https://hasura.io/connectors/mysql)
- [Hasura V3 Documentation](https://hasura.io/docs/3.0)

## Features

Below, you'll find a matrix of all supported features for the MySQL connector:

| Feature | Supported | Notes |
| ------------------------------- | --------- | ----- |
| Native Queries + Logical Models || |
| Native Mutations || |
| Simple Object Query || |
| Filter / Search || |
| Simple Aggregation || |
| Sort || |
| Paginate || |
| Table Relationships || |
| Views || |
| Remote Relationships || |
| Custom Fields || |
| Mutations || |
| Distinct || |
| Enums || |
| Naming Conventions || |
| Default Values || |
| User-defined Functions || |

## Before you get Started

1. Create a [Hasura Cloud account](https://console.hasura.io)
2. Install the [CLI](https://hasura.io/docs/3.0/cli/installation/)
3. Install the [Hasura VS Code extension](https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura)
4. [Create a supergraph](https://hasura.io/docs/3.0/getting-started/init-supergraph)
5. [Create a subgraph](https://hasura.io/docs/3.0/getting-started/init-subgraph)

## Using the connector

To use the MySQL connector, follow these steps in a Hasura project:
(Note: for more information on the following steps, please refer to the Postgres connector
documentation [here](https://hasura.io/docs/3.0/getting-started/connect-to-data/connect-a-source))

### 1. Init the connector

(Note: here and following we are naming the subgraph "my_subgraph" and the connector "my_mysql")

```bash
ddn connector init my_mysql --subgraph my_subgraph --hub-connector hasura/MySQL
```

### 2. Add your MySQL credentials:

Add your credentials to `my_subgraph/connector/my_sql/.env.local`

```env title="my_subgraph/connector/my_mysql/.env.local"
JDBC_URL="jdbc:MySQL:thin:@//host.docker.internal:1521/XE?user=<user>&password=<password>"
```

### 3. Introspect your indices

```bash title="From the root of your project run:"
ddn connector introspect --connector my_subgraph/connector/my_mysql/connector.yaml
```

If you look at the `configuration.json` for your connector, you'll see metadata describing your MySQL mappings.

### 4. Create the Hasura metadata

```bash title="Run the following from the root of your project:"
ddn connector-link add my_mysql --subgraph my_subgraph
```

The generated file has two environment variables — one for reads and one for writes — that you'll need to add to your
subgraph's `.env.my_subgraph` file. Each key is prefixed by the subgraph name, an underscore, and the name of the
connector. Ensure the port value matches what is published in your connector's docker compose file.

```env title="my_subgraph/.env.my_subgraph"
MY_SUBGRAPH_my_mysql_READ_URL=http://local.hasura.dev:8081
MY_SUBGRAPH_my_mysql_WRITE_URL=http://local.hasura.dev:8081
```

### 5. Start the connector's docker compose

Let's start our connector's docker compose file.

```bash title="Run the following from the connector's subdirectory inside a subgraph:"
docker compose -f docker-compose.my_mysql.yaml up
```

This starts our MySQL connector on the specified port. We can navigate to the following address, with the port
modified, to see the schema of our MySQL data source:

```bash
http://localhost:8081/schema
```

### 6. Include the connector in your docker compose

Kill the connector by pressing `CTRL+C` in the terminal tab in which the connector is running.

Then, add the following inclusion to the docker compose `docker-compose.hasura.yaml` in your project's root directory,
taking care to modify the
subgraph's name.

```yaml title="docker-compose.hasura.yaml"
include:
- path: my_subgraph/connector/my_mysql/docker-compose.my_mysql.yaml
```
Now, whenever running the following, you'll bring up the GraphQL engine, observability tools, and any connectors you've
included:
```bash title="From the root of your project, run:"
HASURA_DDN_PAT=$(ddn auth print-pat) docker compose -f docker-compose.hasura.yaml watch
```

### 7. Update the new DataConnectorLink object

Finally, now that our `DataConnectorLink` has the correct environment variables configured for the MySQL connector,
we can run the update command to have the CLI look at the configuration JSON and transform it to reflect our database's
schema in `hml` format. In a new terminal tab, run:

```bash title="From the root of your project, run:"
ddn connector-link update my_mysql --subgraph my_subgraph
```

After this command runs, you can open your `my_subgraph/metadata/my_mysql.hml` file and see your metadata completely
scaffolded out for you 🎉

### 8. Import _all_ your indices

You can do this in one convenience command.

```bash title="From the root of your project, run:"
ddn connector-link update my_mysql --subgraph my_subgraph --add-all-resources
```

### 9. Create a supergraph build

Pass the `local` subcommand along with specifying the output directory as `./engine` in the root of the project. This
directory is used by the docker-compose file to serve the engine locally:

```bash title="From the root of your project, run:"
ddn supergraph build local --output-dir ./engine
```

You can now navigate to
[`https://console.hasura.io/local/graphql?url=http://localhost:3000`](https://console.hasura.io/local/graphql?url=http://localhost:3000)
and interact with your API using the Hasura Console.


## License

The Hasura MySQL connector is available under the [Apache License
2.0](https://www.apache.org/licenses/LICENSE-2.0).
2 changes: 2 additions & 0 deletions registry/mysql/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions registry/mysql/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"overview": {
"namespace": "hasura",
"description": "Connect to a MySQL database and expose it to Hasura v3 Project",
"title": "MySQL Connector",
"logo": "logo.svg",
"tags": [
"database"
],
"latest_version": "v0.1.0"
},
"author": {
"support_email": "[email protected]",
"homepage": "https://hasura.io",
"name": "Hasura"
},
"is_verified": true,
"is_hosted_by_hasura": true,
"packages": [
{
"version": "0.1.0",
"uri": "https://github.com/hasura/ndc-jvm-mono/releases/download/mysql%2Fv0.1.0/package.tar.gz",
"checksum": {
"type": "sha256",
"value": "09b51f9be725099345159880d21efb712776bfd09291a0daa81d7e7b1418ca2c"
},
"source": {
"hash": "145792746281b606bcef2dfe20d1f0ad69efe01e"
}
}
],
"source_code": {
"is_open_source": true,
"repository": "https://github.com/hasura/ndc-jvm-mono",
"version": [
{
"tag": "mysql/v0.1.0",
"hash": "145792746281b606bcef2dfe20d1f0ad69efe01e",
"is_verified": true
}
]
}
}
Loading

0 comments on commit 435c203

Please sign in to comment.