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(generate-schema): load typescript files properly #322

Merged
merged 1 commit into from
Jun 8, 2020

Conversation

FRSgit
Copy link
Contributor

@FRSgit FRSgit commented Apr 19, 2020

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 error ERROR Error: Cannot find module '/Users/jakubfreisler/Projects/Web/scrabbio/apollo-server/type-defs' when type-defs file got ts 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 and utils/generate-schema.js modules are using copy-pasted implementation of load function, but placed in two different places in the codebase (one was directly in index.js file, second one in utils/load.js),
  • implementation of load function which was available within utils/load.js module was not working with typescript files (raised the error above).

First of all I've pointed both index.js and utils/generate-schema.js to use the same load function from utils/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 file utils/load.js. The same load implementation contained in index.js have worked before, because ts-node/register/transpile-only module was required in the index.js before load function was used (and load function was in the same file = in the same context). And in case of utils/load the ts-node/register/transpile-only was always required in the file which required also utils/load.js (but never in utils/load.js itself).

Fix was quite easy - I've just moved require('ts-node/register/transpile-only') to the utils/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?

start using same load module everywhere
@Akryum Akryum merged commit f9e4129 into Akryum:master Jun 8, 2020
@FRSgit
Copy link
Contributor Author

FRSgit commented Jun 8, 2020

Thx for merging this one! ❤️

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