diff --git a/CHANGELOG.md b/CHANGELOG.md index ec4bf7e..b469bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This changelog documents the changes between release versions. ## [Unreleased] Changes to be included in the next upcoming release +## [1.10.0] - 2024-11-21 +- 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. + ## [1.9.0] - 2024-10-24 ### Added diff --git a/ndc-lambda-sdk/package-lock.json b/ndc-lambda-sdk/package-lock.json index d6fda51..68e5697 100644 --- a/ndc-lambda-sdk/package-lock.json +++ b/ndc-lambda-sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hasura/ndc-lambda-sdk", - "version": "1.9.0", + "version": "1.10.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hasura/ndc-lambda-sdk", - "version": "1.9.0", + "version": "1.10.0", "license": "Apache-2.0", "dependencies": { "@hasura/ndc-sdk-typescript": "^7.0.0", @@ -2234,9 +2234,9 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", diff --git a/ndc-lambda-sdk/package.json b/ndc-lambda-sdk/package.json index 2c306cc..c7b6c57 100644 --- a/ndc-lambda-sdk/package.json +++ b/ndc-lambda-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hasura/ndc-lambda-sdk", - "version": "1.9.0", + "version": "1.10.0", "description": "SDK that can automatically expose TypeScript functions as Hasura NDC functions/procedures", "author": "Hasura", "license": "Apache-2.0", diff --git a/ndc-lambda-sdk/src/connector.ts b/ndc-lambda-sdk/src/connector.ts index 9a56591..2d7fa3b 100644 --- a/ndc-lambda-sdk/src/connector.ts +++ b/ndc-lambda-sdk/src/connector.ts @@ -23,41 +23,21 @@ export function createConnector(options: ConnectorOptions): sdk.Connector { // We need to try imporing the functions code via require before doing schema inference because // during watch mode we need it to be registered in the watching system so when the files are - // changed we reload. If the files fail to compile, ts-node will print the diagnostic errors on the - // terminal for us - let runtimeFunctions: RuntimeFunctions | undefined = undefined; - try { - runtimeFunctions = require(functionsFilePath); - } catch (e) { - console.error(`${e}`); // Print the compiler errors produced by ts-node - runtimeFunctions = undefined; - } + // changed we reload. If the files fail to compile, require with throw and the exception will + // result in the diagnostic errors being printed on the terminal for us + let runtimeFunctions: RuntimeFunctions = require(functionsFilePath);; // If the functions successfully loaded (ie. compiled), let's derive the schema. // Unfortunately this means we've typechecked everything twice, but that seems unavoidable without // implementing our own hot-reloading system instead of using ts-node-dev. - if (runtimeFunctions !== undefined) { - const schemaResults = deriveSchema(functionsFilePath); - printCompilerDiagnostics(schemaResults.compilerDiagnostics); // Should never have any of these, since we've already tried compiling the code above - printFunctionIssues(schemaResults.functionIssues); - printRelaxedTypesWarning(schemaResults.functionsSchema); - - return { - functionsSchema: schemaResults.functionsSchema, - runtimeFunctions, - } - } - // If the functions did not compile, just have an empty schema, the user will need to correct - // their code before we can derive a schema - else { - return { - functionsSchema: { - functions: {}, - objectTypes: {}, - scalarTypes: {}, - }, - runtimeFunctions: {} - } + const schemaResults = deriveSchema(functionsFilePath); + printCompilerDiagnostics(schemaResults.compilerDiagnostics); // Should never have any of these, since we've already tried compiling the code above + printFunctionIssues(schemaResults.functionIssues); + printRelaxedTypesWarning(schemaResults.functionsSchema); + + return { + functionsSchema: schemaResults.functionsSchema, + runtimeFunctions, } },