Skip to content

Commit c5728b4

Browse files
Added yeoman template generator to help people get started
1 parent 4821ef7 commit c5728b4

File tree

11 files changed

+6303
-27
lines changed

11 files changed

+6303
-27
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "generator-hasura-ndc-nodejs-lambda npm package"
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- 'main'
9+
tags:
10+
- v**
11+
12+
defaults:
13+
run:
14+
working-directory: ./yeoman-generator
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version-file: .nvmrc
24+
registry-url: https://registry.npmjs.org
25+
cache: npm
26+
cache-dependency-path: ./yeoman-generator/package-lock.json
27+
- run: npm ci
28+
- run: npm run build
29+
30+
publish:
31+
needs: build
32+
runs-on: ubuntu-latest
33+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-node@v4
37+
with:
38+
node-version-file: .nvmrc
39+
registry-url: https://registry.npmjs.org
40+
cache: npm
41+
cache-dependency-path: ./yeoman-generator/package-lock.json
42+
- run: |
43+
PACKAGE_VERSION=`npm version | sed -rn "2 s/.*: '([^']*)'.*/\1/g; 2 p"`
44+
TAG=`echo "$GITHUB_REF"| sed -r "s#.*/##g"`
45+
echo '$TAG' = "$TAG"
46+
echo '$GITHUB_REF' = "$GITHUB_REF"
47+
echo '$PACKAGE_VERSION' = "$PACKAGE_VERSION"
48+
if [ "$TAG" = "v$PACKAGE_VERSION" ]
49+
then
50+
echo "Success! Versions match."
51+
else
52+
echo "Package version (v$PACKAGE_VERSION) must match tag (GITHUB_REF: $GITHUB_REF) in order to publish" 1>&2
53+
exit 1
54+
fi
55+
- run: npm ci
56+
- run: npm run build
57+
- run: npm publish --access public
58+
env:
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,14 @@
33
The NodeJS Lambda connector allows you to expose TypeScript functions as NDC functions/procedures for use in your Hasura DDN subgraphs.
44

55
# How to Use
6-
First create a `functions.ts` that contains your functions, for example:
7-
```typescript
8-
/**
9-
* @pure Exposes the function as an NDC function (the function should only query data without making modifications)
10-
*/
11-
export function hello(name?: string) {
12-
return `hello ${name ?? "world"}`;
13-
}
14-
```
15-
Then add a `configuration.json` file that simply contains an empty configuration object:
16-
```json
17-
{}
18-
```
6+
First, ensure you have NodeJS v18+ installed. Then, create a directory into which you will create your functions using the `hasura-ndc-nodejs-lambda` Yeoman template.
197

20-
Now add a `package.json` file that depends on the `ndc-lambda-sdk` like so:
21-
```json
22-
{
23-
"private": true,
24-
"scripts": {
25-
"start": "ndc-lambda-sdk host -f functions.ts serve --configuration configuration.json",
26-
"watch": "ndc-lambda-sdk host -f functions.ts --watch serve --configuration configuration.json"
27-
},
28-
"dependencies": {
29-
"@hasura/ndc-lambda-sdk": "0.2.0"
30-
}
31-
}
8+
```bash
9+
mkdir my-functions
10+
cd my-functions
11+
npx yo hasura-ndc-nodejs-lambda
3212
```
33-
Now run `npm install` to install all the packages.
3413

35-
Notice the `start` and `watch` scripts in the `package.config`. These use the SDK to host your `functions.ts` file. You can start your connector with `npm start`, or if you'd like it to automatically restart as you change your code, use `npm run watch`.
14+
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.
15+
16+
The `package.config` has been created with `start` and `watch` scripts. These use the SDK to host your `functions.ts` file. You can start your connector with `npm start`, or if you'd like it to automatically restart as you change your code, use `npm run watch`.

yeoman-generator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generators/

0 commit comments

Comments
 (0)