Skip to content

Commit 089e447

Browse files
Update to TS SDK v4.4.0 (NDC Spec v0.1.2) (#29)
1 parent b752aab commit 089e447

File tree

11 files changed

+176
-60
lines changed

11 files changed

+176
-60
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changes to be included in the next upcoming release
99

1010
- Fixed watch mode not reloading after files with compiler errors are changed [#27](https://github.com/hasura/ndc-nodejs-lambda/pull/27)
1111
- Fixed functions that are imported then re-exported causing a crash [#28](https://github.com/hasura/ndc-nodejs-lambda/pull/28)
12+
- Support for NDC Spec v0.1.2 via the NDC TypeScript SDK v4.4.0 ([#29](https://github.com/hasura/ndc-nodejs-lambda/pull/29)).
13+
- Built-in scalar types that support equality now define it in the NDC schema.
14+
- Built-in scalar types now have an explicit type representation defined in the NDC schema.
1215

1316
## [1.2.0] - 2024-03-18
1417
- Improved error messages when unsupported enum types or unions of literal types are found, and allow these types to be used in relaxed types mode ([#17](https://github.com/hasura/ndc-nodejs-lambda/pull/17))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Node.js Lambda connector allows you to expose TypeScript functions as NDC fu
66
> Hasura DDN Alpha users should use 0.x versions of the `ndc-lambda-sdk`. v1.x versions of the `ndc-lambda-sdk` support the forthcoming Hasura DDN Beta.
77
88
## How to Use
9-
First, ensure you have Node.js v18+ installed. Then, create a directory into which you will create your functions using the `hasura-ndc-nodejs-lambda` Yeoman template.
9+
First, ensure you have Node.js v20+ installed. Then, create a directory into which you will create your functions using the `hasura-ndc-nodejs-lambda` Yeoman template.
1010

1111
```bash
1212
mkdir my-functions

connector-definition/template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"engines": {
4-
"node": ">=18"
4+
"node": ">=20"
55
},
66
"scripts": {
77
"start": "ndc-lambda-sdk host -f functions.ts serve --configuration ./",

ndc-lambda-sdk/package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ndc-lambda-sdk/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
"url": "git+https://github.com/hasura/ndc-nodejs-lambda.git"
3131
},
3232
"dependencies": {
33-
"@hasura/ndc-sdk-typescript": "^4.2.1",
34-
"@tsconfig/node20": "^20.1.2",
33+
"@hasura/ndc-sdk-typescript": "^4.4.0",
34+
"@tsconfig/node20": "^20.1.3",
3535
"commander": "^11.1.0",
3636
"cross-spawn": "^7.0.3",
3737
"p-limit": "^3.1.0",
38-
"ts-api-utils": "^1.0.3",
38+
"ts-api-utils": "^1.3.0",
3939
"ts-node": "^10.9.2",
4040
"ts-node-dev": "^2.0.0",
41-
"typescript": "^5.4.2"
41+
"typescript": "^5.4.3"
4242
},
4343
"devDependencies": {
4444
"@types/chai": "^4.3.11",

ndc-lambda-sdk/src/connector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function createConnector(options: ConnectorOptions): sdk.Connector<Config
6767

6868
getCapabilities: function (configuration: Configuration): sdk.CapabilitiesResponse {
6969
return {
70-
version: "0.1.0",
70+
version: "0.1.2",
7171
capabilities: {
7272
query: {
7373
variables: {}

ndc-lambda-sdk/src/schema.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as sdk from "@hasura/ndc-sdk-typescript";
2-
import { mapObjectValues, unreachable } from "./util";
2+
import { mapObjectValues, throwError, unreachable } from "./util";
33

44
export type FunctionsSchema = {
55
functions: FunctionDefinitions
@@ -242,10 +242,19 @@ export function getNdcSchema(functionsSchema: FunctionsSchema): sdk.SchemaRespon
242242
}
243243
});
244244

245-
const scalarTypes = mapObjectValues(functionsSchema.scalarTypes, _scalar_def => {
246-
return {
247-
aggregate_functions: {},
248-
comparison_operators: {},
245+
const scalarTypes: Record<string, sdk.ScalarType> = mapObjectValues(functionsSchema.scalarTypes, (scalarDef, scalarTypeName) => {
246+
switch (scalarDef.type) {
247+
case "built-in":
248+
return isTypeNameBuiltInScalar(scalarTypeName)
249+
? convertBuiltInScalarTypeIntoSdkSchemaType(scalarTypeName)
250+
: throwError(`built-in scalar type with unexpected name: ${scalarTypeName}`);
251+
case "relaxed-type":
252+
return {
253+
aggregate_functions: {},
254+
comparison_operators: {},
255+
};
256+
default:
257+
return unreachable(scalarDef["type"]);
249258
}
250259
})
251260

@@ -271,6 +280,42 @@ function convertTypeReferenceToSdkType(typeRef: TypeReference): sdk.Type {
271280
}
272281
}
273282

283+
function convertBuiltInScalarTypeIntoSdkSchemaType(typeName: BuiltInScalarTypeName): sdk.ScalarType {
284+
switch (typeName) {
285+
case BuiltInScalarTypeName.String: return {
286+
representation: { type: "string" },
287+
aggregate_functions: {},
288+
comparison_operators: { "_eq": { type: "equal" } },
289+
};
290+
case BuiltInScalarTypeName.Float: return {
291+
representation: { type: "float64" },
292+
aggregate_functions: {},
293+
comparison_operators: { "_eq": { type: "equal" } },
294+
};
295+
case BuiltInScalarTypeName.Boolean: return {
296+
representation: { type: "boolean" },
297+
aggregate_functions: {},
298+
comparison_operators: { "_eq": { type: "equal" } },
299+
};
300+
case BuiltInScalarTypeName.BigInt: return {
301+
representation: { type: "int64" }, // NDC doesn't have a good representation for this type as at v0.1.2, so this is the best representation in the meantime
302+
aggregate_functions: {},
303+
comparison_operators: { "_eq": { type: "equal" } },
304+
};
305+
case BuiltInScalarTypeName.DateTime: return {
306+
representation: { type: "timestamp" },
307+
aggregate_functions: {},
308+
comparison_operators: { "_eq": { type: "equal" } },
309+
};
310+
case BuiltInScalarTypeName.JSON: return {
311+
representation: { type: "json" },
312+
aggregate_functions: {},
313+
comparison_operators: {},
314+
};
315+
default: return unreachable(typeName);
316+
}
317+
}
318+
274319
function convertFunctionDefinitionToSdkSchemaType(function_name: string, definition: FunctionDefinition): sdk.FunctionInfo | sdk.ProcedureInfo {
275320
const args =
276321
definition.arguments

0 commit comments

Comments
 (0)