fix(generate-schema): load typescript files properly #322
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
start using same load module everywhere
When starting new vue-apollo typescript project I've found out that
vue-cli-service apollo:schema:generate
command fails with errorERROR Error: Cannot find module '/Users/jakubfreisler/Projects/Web/scrabbio/apollo-server/type-defs'
when type-defs file gotts
extension (with js file everything've worked as expected).Also, at the same time,
vue-cli-service apollo:dev
was working (which I was weird for me).So, after some investigation I found out that:
index.js
andutils/generate-schema.js
modules are using copy-pasted implementation ofload
function, but placed in two different places in the codebase (one was directly inindex.js
file, second one inutils/load.js
),load
function which was available withinutils/load.js
module was not working with typescript files (raised the error above).First of all I've pointed both
index.js
andutils/generate-schema.js
to use the sameload
function fromutils/load.js
.Then, I've figured out that this function was never working with typescript files properly because
ts-node/register/transpile-only
module was never required in the context of the fileutils/load.js
. The same load implementation contained inindex.js
have worked before, becausets-node/register/transpile-only
module was required in theindex.js
before load function was used (and load function was in the same file = in the same context). And in case ofutils/load
thets-node/register/transpile-only
was always required in the file which required alsoutils/load.js
(but never inutils/load.js
itself).Fix was quite easy - I've just moved
require('ts-node/register/transpile-only')
to theutils/load.js
. This change fixed the problem and de-duplicated codebase a bit.@Akryum do you want me to do any additional work before this PR could be merged?