Skip to content

Commit

Permalink
Update to NDC TypeScript SDK v5.2.0, remove yeoman generator, update …
Browse files Browse the repository at this point in the history
…readme instructions (#38)

* Update TypeScript SDK version
* Delete unused yeoman generator
* Update readme with latest instructions
* Update changelog
  • Loading branch information
daniel-chambers authored Jul 30, 2024
1 parent 9b5f795 commit 2a9a04d
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 6,428 deletions.
61 changes: 0 additions & 61 deletions .github/workflows/generator-hasura-ndc-nodejs-lambda.yaml

This file was deleted.

9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Node.js Lambda Connector Changelog
This changelog documents the changes between release versions.

> [!IMPORTANT]
> Hasura DDN Alpha users should use 0.x versions of the `ndc-lambda-sdk`. v1.x versions of the `ndc-lambda-sdk` support the Hasura DDN Beta.
## [Unreleased]
Changes to be included in the next upcoming release

## [1.5.0] - 2024-07-30
- Updated the NDC TypeScript SDK to v5.2.0 ([#38](https://github.com/hasura/ndc-nodejs-lambda/pull/38))
- The connector now listens on both ipv4 and ipv6 interfaces

## [1.4.1] - 2024-06-06

- Added a default .gitignore that ignores node_modules in the connector template ([#34](https://github.com/hasura/ndc-nodejs-lambda/pull/34))
- Updated to NDC TypeScript SDK to v5.0.0 ([#35](https://github.com/hasura/ndc-nodejs-lambda/pull/35))
- Updated the NDC TypeScript SDK to v5.0.0 ([#35](https://github.com/hasura/ndc-nodejs-lambda/pull/35))
- The BigInt scalar type now uses the biginteger type representation
- Added `dotenv-cli` to the dev dependencies of the connector's default package.json to help with using .env files ([#36](https://github.com/hasura/ndc-nodejs-lambda/pull/36))

Expand Down
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,60 @@ The Node.js Lambda connector allows you to expose TypeScript functions as NDC fu
> [!TIP]
> The following instructions are just a quick summary of how to use the Node.js Lambda connector.
> To see it in use in a wider Hasura DDN project, and to understand the underlying DDN concepts, please check out the [Hasura DDN Getting Started Guide](https://hasura.io/docs/3.0/getting-started/overview/).
> The Node.js Lambda connector is used in the business logic part of that tutorial.
> The Node.js Lambda connector is used in the [business logic](https://hasura.io/docs/3.0/getting-started/build/add-business-logic?db=TypeScript) part of that tutorial.
First, ensure you have Node.js v20+ installed and an existing Hasura DDN project created (see the [Hasura DDN Getting Started Guide](https://hasura.io/docs/3.0/getting-started/overview/)). Then, initialize the connector into that project:
First, ensure you have Node.js v20+ installed and an existing Hasura DDN project created (see the [Hasura DDN Getting Started Guide](https://hasura.io/docs/3.0/getting-started/overview/)). Then, initialize the connector into that project on an unused port of your choosing:

```bash
ddn connector init my_ts --subgraph my_subgraph --hub-connector hasura/nodejs
ddn connector init my_ts --subgraph my_subgraph/subgraph.yaml --hub-connector hasura/nodejs --configure-port 8085
```

This will generate the necessary files into the `my_subgraph/connector/my_ts` directory. This creates a `functions.ts` file in which you will write your functions, and a `package.json` with the `ndc-lambda-sdk` installed into it.

Restore all the npm packages required to run the connector by running inside the connector's directory:
To add a `DataConnectorLink` to link the connector into the wider Hasura DDN project, run:

```bash
npm install
ddn connector-link add my_ts \
--subgraph my_subgraph/subgraph.yaml \
--configure-host http://local.hasura.dev:8085 \
--target-env-file my_subgraph/.env.my_subgraph.local
```

You may wish to change the port the connector runs on to one that is unused (the default is 8080). You can do so by changing the `.env.local` file and adding:
Restore all the npm packages required to run the connector by running inside the connector's directory:

```
HASURA_CONNECTOR_PORT=<port>
```bash
npm install
```

To run the connector with these environment environment variables applied, you can run the following command:
To run the connector with the required environment variables applied, you can run the following command:

```bash
npx dotenv -e .env.local -- npm run watch
```

This starts the connector in watch mode, which watches for code changes and restarts the connector when they are detected. `npm run start` can be used instead to just start the connector without watching for changes. Both `start` and `watch` are defined in the `package.json`'s scripts section and use the `ndc-lambda-sdk` to host your `functions.ts` file.

To add a `DataConnectorLink` to link the connector into the wider Hasura DDN project, run:

```bash
ddn connector-link add my_ts
```

Then, update the values in your subgraph's `.env.my_subgraph` file to include this connector.

```
MY_SUBGRAPH_MY_TS_READ_URL=http://local.hasura.dev:<port>
MY_SUBGRAPH_MY_TS_WRITE_URL=http://local.hasura.dev:<port>
```

Once you have written your functions, and while the connector is running, you can update that `DataConnectorLink` and add all the new functions to your subgraph by running:

```bash
ddn connector-link update my_ts --subgraph my_subgraph --add-all-resources
ddn connector-link update my_ts \
--subgraph my_subgraph/subgraph.yaml \
--env-file my_subgraph/.env.my_subgraph.local \
--add-all-resources
```

To make a local build of your supergraph you can run:

```bash
ddn supergraph build local --output-dir ./engine
ddn supergraph build local \
--output-dir engine \
--subgraph-env-file my_subgraph:my_subgraph/.env.my_subgraph.local
```

You can then run that build locally for testing by starting the engine and other connectors in the DDN project using Docker Compose:

```bash
HASURA_DDN_PAT=$(ddn auth print-pat) docker compose -f docker-compose.hasura.yaml watch
HASURA_DDN_PAT=$(ddn auth print-pat) docker compose up --build --watch
```

You can view and query that local instance using the Hasura Graphiql Explorer by navigating to `https://console.hasura.io/local/graphql?url=http://localhost:3000`.
Expand Down
32 changes: 16 additions & 16 deletions ndc-lambda-sdk/package-lock.json

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

4 changes: 2 additions & 2 deletions ndc-lambda-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hasura/ndc-lambda-sdk",
"version": "1.4.1",
"version": "1.5.0",
"description": "SDK that can automatically expose TypeScript functions as Hasura NDC functions/procedures",
"author": "Hasura",
"license": "Apache-2.0",
Expand Down Expand Up @@ -30,7 +30,7 @@
"url": "git+https://github.com/hasura/ndc-nodejs-lambda.git"
},
"dependencies": {
"@hasura/ndc-sdk-typescript": "^5.0.0",
"@hasura/ndc-sdk-typescript": "^5.2.0",
"@tsconfig/node20": "^20.1.3",
"commander": "^11.1.0",
"cross-spawn": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion ndc-lambda-sdk/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function createConnector(options: ConnectorOptions): sdk.Connector<Config

getCapabilities: function (configuration: Configuration): sdk.CapabilitiesResponse {
return {
version: "0.1.3",
version: "0.1.5",
capabilities: {
query: {
variables: {},
Expand Down
1 change: 0 additions & 1 deletion yeoman-generator/.gitignore

This file was deleted.

Loading

0 comments on commit 2a9a04d

Please sign in to comment.