Skip to content

Commit 2711113

Browse files
Exit during startup if functions fail to compile (#50)
1 parent b8e329e commit 2711113

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This changelog documents the changes between release versions.
44
## [Unreleased]
55
Changes to be included in the next upcoming release
66

7+
## [1.10.0] - 2024-11-21
8+
- The connector now exits during startup if there are compiler errors in the functions code. The compiler errors are printed to stderr. Previously the connector would print the errors and start "successfully", but with an empty schema. The new behaviour ensures that when the connector is used with `ddn connector introspect`, `ddn` is aware that a problem has occurred (because the connector fails to start) and will prompt the user to print the logs to see the compiler errors.
9+
710
## [1.9.0] - 2024-10-24
811

912
### Added

ndc-lambda-sdk/package-lock.json

Lines changed: 5 additions & 5 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hasura/ndc-lambda-sdk",
3-
"version": "1.9.0",
3+
"version": "1.10.0",
44
"description": "SDK that can automatically expose TypeScript functions as Hasura NDC functions/procedures",
55
"author": "Hasura",
66
"license": "Apache-2.0",

ndc-lambda-sdk/src/connector.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,21 @@ export function createConnector(options: ConnectorOptions): sdk.Connector<Config
2323
parseConfiguration: async function (configurationDir: string): Promise<Configuration> {
2424
// We need to try imporing the functions code via require before doing schema inference because
2525
// during watch mode we need it to be registered in the watching system so when the files are
26-
// changed we reload. If the files fail to compile, ts-node will print the diagnostic errors on the
27-
// terminal for us
28-
let runtimeFunctions: RuntimeFunctions | undefined = undefined;
29-
try {
30-
runtimeFunctions = require(functionsFilePath);
31-
} catch (e) {
32-
console.error(`${e}`); // Print the compiler errors produced by ts-node
33-
runtimeFunctions = undefined;
34-
}
26+
// changed we reload. If the files fail to compile, require with throw and the exception will
27+
// result in the diagnostic errors being printed on the terminal for us
28+
let runtimeFunctions: RuntimeFunctions = require(functionsFilePath);;
3529

3630
// If the functions successfully loaded (ie. compiled), let's derive the schema.
3731
// Unfortunately this means we've typechecked everything twice, but that seems unavoidable without
3832
// implementing our own hot-reloading system instead of using ts-node-dev.
39-
if (runtimeFunctions !== undefined) {
40-
const schemaResults = deriveSchema(functionsFilePath);
41-
printCompilerDiagnostics(schemaResults.compilerDiagnostics); // Should never have any of these, since we've already tried compiling the code above
42-
printFunctionIssues(schemaResults.functionIssues);
43-
printRelaxedTypesWarning(schemaResults.functionsSchema);
44-
45-
return {
46-
functionsSchema: schemaResults.functionsSchema,
47-
runtimeFunctions,
48-
}
49-
}
50-
// If the functions did not compile, just have an empty schema, the user will need to correct
51-
// their code before we can derive a schema
52-
else {
53-
return {
54-
functionsSchema: {
55-
functions: {},
56-
objectTypes: {},
57-
scalarTypes: {},
58-
},
59-
runtimeFunctions: {}
60-
}
33+
const schemaResults = deriveSchema(functionsFilePath);
34+
printCompilerDiagnostics(schemaResults.compilerDiagnostics); // Should never have any of these, since we've already tried compiling the code above
35+
printFunctionIssues(schemaResults.functionIssues);
36+
printRelaxedTypesWarning(schemaResults.functionsSchema);
37+
38+
return {
39+
functionsSchema: schemaResults.functionsSchema,
40+
runtimeFunctions,
6141
}
6242
},
6343

0 commit comments

Comments
 (0)