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

Improved deno run --watch support, watch support inside Docker #79

Merged
merged 13 commits into from
Nov 30, 2023
Merged
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Dockerfile
.dockerignore
.dockerignore
.gitkeep
2 changes: 1 addition & 1 deletion .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Setup Deno
# uses: denoland/setup-deno@v1
uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2
uses: denoland/setup-deno@0df5d9c641efdff149993c321fc27c11c5df8623 # v1.1.3
with:
deno-version: v1.x

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This changelog documents the changes between release versions.

## main

Changes to be included in the next upcoming releaase.
Changes to be included in the next upcoming release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doy.


## v0.19

Expand Down
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM denoland/deno:alpine-1.37.1
FROM denoland/deno:alpine-1.38.3

COPY ./src /app
COPY ./functions /functions
WORKDIR /functions
RUN deno cache /app/mod.ts

RUN ls /app
COPY ./functions /functions/src

# Pre-cache inference results and dependencies
RUN EARLY_ENTRYPOINT_EXIT=true sh /app/entrypoint.sh
RUN PRECACHE_ONLY=true /app/entrypoint.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just split the initial actions into a seperate script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What, and call it from this script? It still needs to happen on container start for those volume-mounting their functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call the build actions from the dockerfile directly or via a build script, then remove them from the entrypoint script

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right... yeah this would work on connector create, but not for people doing local docker... bummer


ENTRYPOINT [ "sh", "/app/entrypoint.sh" ]
EXPOSE 8080

ENTRYPOINT [ "/app/entrypoint.sh" ]

CMD [ ]
50 changes: 19 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/9f139964-d0ed-4c92-b01f-9fda255717d4)

The Typescript (Deno) Connector allows a running connector to be inferred from a Typescript file (optionally with dependencies).
The TypeScript (Deno) Connector allows a running connector to be inferred from a TypeScript file (optionally with dependencies).

![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/fb7f4afd-0302-432b-b7ce-3cc7d1f3546b)

Useful Links:

* [Typescript Deno Connector on the NDC Hub](https://hasura.io/connectors/typescript-deno)
* [Typescript Deno Connector on deno.com](https://deno.land/x/hasura_typescript_connector)
* [TypeScript Deno Connector on the NDC Hub](https://hasura.io/connectors/typescript-deno)
* [TypeScript Deno Connector on deno.com](https://deno.land/x/hasura_typescript_connector)
* [Hasura V3 Documentation](https://hasura.io/docs/3.0)
* [Hasura CLI](https://github.com/hasura/v3-cli#hasura-v3-cli)
* [CLI Connector Plugin](https://hasura.io/docs/latest/hasura-cli/connector-plugin/)
* [Hasura VSCode Extension](https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura)
* [Deno](https://deno.com)
* [Native Data Connector Specification](https://hasura.github.io/ndc-spec/)
* [Typescript NDC SDK](https://github.com/hasura/ndc-sdk-typescript/)
* [TypeScript NDC SDK](https://github.com/hasura/ndc-sdk-typescript/)
* [DDN Limited Alpha Access Form](https://forms.gle/zHTrVEbsQoBK8ecr5)


## Overview

The connector runs in the following manner:

* Typescript sources are assembled (with `index.ts` acting as your interface definition)
* TypeScript sources are assembled (with `index.ts` acting as your interface definition)
* Dependencies are fetched
* Inference is performed and made available via the `/schema` endpoint
* Functions are served via the connector protocol
Expand Down Expand Up @@ -54,7 +54,7 @@ Once the Hasura DDN is generally available this will no longer be required.
Your functions should be organised into a directory with one file acting as the entrypoint.

<details>
<summary> An example Typescript entrypoint: </summary>
<summary> An example TypeScript entrypoint: </summary>

```typescript

Expand Down Expand Up @@ -123,7 +123,6 @@ Limitations:
* All numbers are exported as `Float`s
* Unrecognised types will become opaque scalars, for example: union types.
* Optional object fields are not currently supported
* Complex input types are supported by the connector, but are not supported in "commands" in Hasura3 projects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

* Functions can be executed via both the `/query` and `/mutation` endpoints
* Conflicting type names in dependencies will be namespaced with their relative path
* Generic type parameters will be treated as scalars when referenced
Expand All @@ -145,52 +144,41 @@ In order to develop your functions locally the following is the recommended prac
{
"functions": "./functions/index.ts",
"vendor": "./vendor",
"preVendor": true,
"schemaMode": "INFER"
}
```
* (Optionally) If you want your development vendor and inference resources to be used to speed up deployment, add the following to your `./config.json`:
```json
{
"functions": "./functions/index.ts",
"vendor": "./functions/vendor",
"preVendor": true,
"schemaLocation": "./functions/schema.json",
"schemaMode": "INFER"
}
```
* Make sure to .gitignore your computed `vendor` and `schema.json` files.
Comment on lines -152 to -162
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* Make sure to .gitignore your computed `vendor` files.
* Start the connector
```sh
deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json
deno run -A --watch=./functions --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json
```
* (Optionally) Add a test-suite to your functions. See [Deno Testing Basics](https://docs.deno.com/runtime/manual/basics/testing).
* (Optionally) Add a test-suite for your functions. See [Deno Testing Basics](https://docs.deno.com/runtime/manual/basics/testing).


## Config Format

The configuration object has the following properties:

```
functions (string): Location of your functions entrypoint (default: ./functions/index.ts)
functions (string): Location of your functions entrypoint
Comment on lines -175 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no documented default for functions, but present for preVendor, schemaMode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't default functions any more, you must specify it as something yourself, so there is no default. You will get an error if you leave it out or put in a blank string. In all the places where we control the locations of the functions (ie. in docker) we specify it. We specify it in all the documentation. We also generate a value in a blank configuration object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this? I thought it was an advantage minimise boilerplate in the config.

vendor (string): Location of dependencies vendor folder (optional)
preVendor (boolean): Perform vendoring prior to inference in a sub-process (default: false)
schemaMode (string): INFER the schema from your functions, or READ it from a file.
schemaLocation (string): Location of your schema file. schemaMode=READ reads the file, schemaMode=INFER writes the file (optional)
preVendor (boolean): Perform vendoring prior to inference in a sub-process (default: true)
schemaMode (string): INFER the schema from your functions, or READ it from a file. (default: INFER)
schemaLocation (string): Location of your schema file. schemaMode=READ reads the file (required), schemaMode=INFER writes the file (optional)
```

NOTE: When deploying the connector with the `connector create` command your config is currently replaced with:

```
```json
{
"functions": "/functions/index.ts",
"functions": "/functions/src/index.ts",
"vendor": "/functions/vendor",
"schemaMode": "READ",
"schemaLocation": "/functions/schema.json"
}
```

This means that your functions volume will have to be mounted to `/functions`.
This means that your functions volume will have to be mounted to `/functions/src`.

## Deployment for Hasura Users

Expand All @@ -203,7 +191,7 @@ You will need:

Create the connector:

```
```bash
hasura3 connector create my-cool-connector:v1 \
--github-repo-url https://github.com/hasura/ndc-typescript-deno/tree/main \
--config-file <(echo '{}') \
Expand All @@ -220,7 +208,7 @@ Monitor the deployment status by name - This will indicate in-progress, complete
List all your connectors with their deployed URLs:

> hasura3 connector list

View logs from your running connector:

> hasura3 connector logs my-cool-connector:v1
Expand Down Expand Up @@ -343,7 +331,7 @@ In order to perform local development on this codebase:

* Check out the repository: `git clone https://github.com/hasura/ndc-typescript-deno.git`
* This assumes that you will be testing against function in `./functions`
* Serve your functions with `deno run -A --watch --check ./src/mod.ts serve --configuration <(echo '{"functions": "./functions/index.ts", "vendor": "./functions/vendor", "schemaMode": "INFER"}')`
* Serve your functions with `deno run -A --watch=./functions --check ./src/mod.ts serve --configuration <(echo '{"functions": "./functions/index.ts", "vendor": "./vendor", "schemaMode": "INFER"}')`
* The connector should now be running on localhost:8100 and respond to any changes to the your functions and the connector source
* Use the `hasura3` tunnel commands to reference this connector from a Hasura Cloud project

Expand Down
Empty file added functions/.gitkeep
Empty file.
6 changes: 0 additions & 6 deletions functions/index.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Hasura NDC Typescript (Deno) Connector
# Hasura NDC TypeScript (Deno) Connector

![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/9f139964-d0ed-4c92-b01f-9fda255717d4)

The Typescript (Deno) Connector allows a running connector to be inferred from a Typescript file (optionally with dependencies).
The TypeScript (Deno) Connector allows a running connector to be inferred from a TypeScript file (optionally with dependencies).

![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/fb7f4afd-0302-432b-b7ce-3cc7d1f3546b)

Expand All @@ -19,14 +19,13 @@ Once your project is set up, run locally with:
{
"functions": "./functions/index.ts",
"vendor": "./vendor",
"preVendor": true,
"schemaMode": "INFER"
}

> deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json
> deno run -A --watch=./functions --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json
```

## Typescript Functions Format
## TypeScript Functions Format

Your functions should be organised into a directory with one file acting as the entrypoint.

Expand Down
Loading