Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix watch mode not reloading after files with compiler errors are fixed #27

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

daniel-chambers
Copy link
Collaborator

This PR fixes a bug in watch mode, where, if you had compile errors in your functions TypeScript code, after fixing the compile errors, the connector would not be restarted to reload your changes. Now, when you change your (broken) files, the connector will reload and retry to compile your code.

This was caused by an optimisation where we performed schema inference and if we got TS compiler errors, we skipped require-ing the function code into the app. We did this because we wanted to avoid compiling the code twice, and also because the compilation via require would produce extra error output in the terminal. Unfortunately, because we skipped require, we skipped the registration of the function code into the hot-reloading watching system provided by ts-node-dev.

To fix this, I've removed this optimisation. We now always require the functions code, and we let ts-node do a full type-checked compile (not just a transpile), so if it fails, we get the full compiler errors and output those to the terminal and then skip schema inference. If there are no compiler errors and the code successfully imports via require, we then do schema inference.

@daniel-chambers daniel-chambers self-assigned this Apr 10, 2024
@@ -7,6 +7,8 @@ This changelog documents the changes between release versions.
## [Unreleased]
Changes to be included in the next upcoming release

- Fixed watch mode not reloading after files with compiler errors are changed [#27](https://github.com/hasura/ndc-nodejs-lambda/pull/27)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 7 to 10
export type Configuration = {
functionsSchema: FunctionsSchema
runtimeFunctions: RuntimeFunctions
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this move out of state?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pass in functions in config, or conversely, export them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is purely an internal type now, it doesn't really represent precisely what the user configures any more. The files on disk do.
RuntimeFunctions needed to move into config from state because importation (ie require) needs to be run before schema inference, as per the PR description. And schema inference can't be done in state, since getSchema doesn't access state.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that makes sense. I guess the name still throws me off but the implementation is obviously fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. I think the State and Configuration style of doing things is kinda a holdover from the old configuration server. In practice now, we really could combine State and Configuration in the SDK and let the connector authors draw a distinction inside the one type if they want. c'est la vie.

@daniel-chambers daniel-chambers merged commit 050d99a into main Apr 10, 2024
6 checks passed
@daniel-chambers daniel-chambers deleted the daniel/fix-watching-errored-files branch April 10, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants