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

Updates for DDN Alpha and TypeScript Deno connector compatibility #1

Merged
merged 3 commits into from
Nov 30, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.vscode/
vendor/
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"HasuraHQ.hasura",
"denoland.vscode-deno"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": false
Copy link
Contributor

Choose a reason for hiding this comment

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

We're using unstable features in the connector to support the NPM modules so should we try to match this with the dev tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that refers to that, I think this enables access to Deno's unstable APIs. I've used an NPM package (for testing) in this project with that set to false and it works just fine.

}
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

# See https://github.com/hasura/ndc-typescript-deno/tags for the latest tag to use via FROM
# It is recommended that you pin a release tag rather than using `main`

FROM ghcr.io/hasura/ndc-typescript-deno:main

COPY ./functions:/functions
RUN EARLY_ENTRYPOINT_EXIT=true ./entrypoint.sh /app/ndc-typescript-deno --configuration /placeholder-config.json
COPY ./functions /functions/src

# Pre-cache inference results and dependencies
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.

👍

36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ This repository provides a example Typescript function that can be used with the

To deploy from the Hasura CLI do

```
```bash
hasura3 connector create sendgrid:deno:v1 \
--github-repo-url https://github.com/hasura/ndc-typescript-deno/tree/main \
--config-file config.json \
--config-file <(echo '{}') \
--volume ./functions:/functions \
--env SENDGRID_API_KEY='YOUR_SENDGRID_API_KEY' \
--env SERVICE_TOKEN_SECRET='MY-PRESHARED-HASURA-TOKEN'
```

Note that you will need the `connector` plugin installed into Hasura CLI to do the above.

```bash
hasura3 plugin install connector
```

## Deploying to Hasura Cloud

Update your `metadata.hml` using the [Hasura VSCode LSP](https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura)
First, create a Hasura DDN project if you don't have one already:

```bash
hasura3 project create
```

Take the project name returned by that command (or use your existing project name) and set it in the `hasura.yaml` file.

Then, update your `subgraphs/default/sendgrid.hml` using the [Hasura VSCode LSP](https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura)

Add your deployed connector's URL to the `DataSource` section.

Expand All @@ -28,16 +42,10 @@ Run the code actions:
> Hasura: Track all collections...
```

Find an existing project or create one:

```
hasura3 cloud project create
```

Then use your metadata referencing your connector to create a build:

```
hasura3 cloud build create --project-id MY-PROJECT-ID --metadata-file metadata.hml
```bash
hasura3 build create
```

## Using as a Stand-Alone Connector
Expand All @@ -51,10 +59,10 @@ This means that you don't need to specify any functions, etc.
This can be a pattern you can use to quickly provide connectors that can be shared
by the Hasura community and on the [Connector Hub](https://hasura.io/connectors)

```
```bash
hasura3 connector create sendgrid:deno:standalone:v1 \
--github-repo-url https://github.com/hasura/ndc-sendgrid-deno/tree/main \
--config-file config.json \
--config-file <(echo '{}') \
--env SENDGRID_API_KEY='YOUR_SENDGRID_API_KEY' \
--env SERVICE_TOKEN_SECRET='MY-PRESHARED-HASURA-TOKEN'
```
```
19 changes: 19 additions & 0 deletions build-profile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
spec:
environment: default
mode: replace
supergraph:
resources:
- supergraph/*

# Subgraphs can be used to group certain objects of your metadata
# in a way that makes sense for you and your team
# You can have multiple HML files belong to a subgraph
# and you can have multiple subgraphs in a project
# We have created a default subgraph for you, and added a HML file to it to get you started
# Please note that default is a special subgraph that is created for every project
# and it cannot be deleted
subgraphs:
- name: default
resources:
- subgraphs/default/**/*.hml
1 change: 0 additions & 1 deletion config.json

This file was deleted.

16 changes: 12 additions & 4 deletions functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { sendSimpleMail, IResult } from 'https://deno.land/x/[email protected]/mod.ts';
import { sendSimpleMail } from 'https://deno.land/x/[email protected]/mod.ts';

type Result = {
success: boolean,
errors: string[]
}

/**
* Uses the SendGrid API to send an email.
*
*
* @param subject The email subject
* @param to The address to send the email to
* @param from Who to list as the sender of the email
* @param plain The plaintext content of the email
* @param html The HTML content of the email
* @returns Success or errors
*/
export async function send(subject: string, to: string, from: string, plain: string, html: string ): Promise<IResult> {
export async function send(subject: string, to: string, from: string, plain: string, html: string ): Promise<Result> {
const API_KEY = Deno.env.get("SENDGRID_API_KEY");

if(! API_KEY) {
Expand All @@ -32,5 +37,8 @@ export async function send(subject: string, to: string, from: string, plain: str
},
);

return response;
return {
success: response.success,
errors: response.errors ?? []
};
}
15 changes: 15 additions & 0 deletions hasura.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 1
# TODO: Put your project name here
project: your-project-name

# A build profile specifies your projects environment
# and the association of subgraphs to HML files
# You can create different build profiles for different environments,
# like production and staging, which may reference environment specific auth configs
# We have created one for you to get you started
buildProfiles:
- build-profile.yaml

# Default build profile refers to build profile
# that is used when you create a build and don't specify the build profile
defaultBuildProfile: build-profile.yaml
15 changes: 0 additions & 15 deletions metadata.hml

This file was deleted.

12 changes: 12 additions & 0 deletions subgraphs/default/sendgrid.hml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: DataConnector
version: v1
definition:
name: sendgrid
url:
singleUrl: 'http://my-connector-url'
headers:
Authentication:
value: Bearer MY-PRESHARED-HASURA-TOKEN

# Run> Hasura: Refresh data connector
# Run> Hasura: Track all collections...
8 changes: 8 additions & 0 deletions supergraph/auth-config.hml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: AuthConfig
version: v1
definition:
allowRoleEmulationBy: admin
mode:
webhook:
method: Post
url: https://auth.pro.hasura.io/webhook/ddn?role=admin
2 changes: 2 additions & 0 deletions supergraph/compatibility-config.hml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kind: CompatibilityConfig
date: 2023-11-29