Is your feature request related to a problem? Please describe.
Sorry if this duplicates another issue - I couldn't find something which matched this particular problem that was still open.
My team is using graphql-codegen to generate types from our node service. As part of generating types we are transpiling our typescript code using ts-node/register.
If there is any compilation issue / or an issue actually running the code the code generation command fails without actually showing the error. Instead it shows the following:
$ graphql-codegen
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/types.d.ts
✖ Load GraphQL schemas
→ All found files for glob expression "./src/schema.ts" are not valid or empty, please check it and try again!
Load GraphQL documents
Generate
Found 1 error
✖ ./src/types.d.ts
Error: All found files for glob expression "./src/schema.ts" are not valid or empty, please check it and try again!
Something went wrong
Describe the solution you'd like
If an error is encountered when trying to load the schema it'd be great if it was displayed.
Describe alternatives you've considered
We have considered running tsc with no emit turned on as part of our command to actually run the codegen command. This is much slower as it means we are effectively compiling everything twice.
Additional context
Our config is:
overwrite: true
schema: ./src/schema.ts
require:
- ts-node/register/transpile-only
generates:
./src/types.d.ts:
plugins:
- add: '/* tslint:disable */'
- typescript
- typescript-resolvers
...
Hi @Myrannas !
We are using graphql-toolkit to load schemas and operations easily. It currently supports code files as schema and loads it using require (and not as ast). It means that your schema.ts file must export default or export an object with schema field (GraphQLSchema object).
Can you please share your schema.ts file? it will make it easier to resolve this issue.
I can't share our GraphQL schema - but I will try and create an example in a separate repository.
Thank you @Myrannas ! Waiting for it.
I have this same issue with the same config file. It appears that going through multiple import/export files causes the problem, but I am not 100% sure on that yet. My schemas are split into directories roughly related to the models. For example: there is a User directory with a schema.ts file in there. Each directory has an index.ts file that just consolidates and re-exports everything that is needed in the directory.
Then my root schema.ts imports all those pieces and stitches them together, via imports from those index files.
If I instead bypass the index files and directly import each schema file, the code generation works. But, my root schema.ts is a little messier.
Yep, I think you are correct @bopfer.
I have created a minimal example of this issue in https://github.com/Myrannas/graphql-codegen-error.
Instructions to reproduce are in the readme, but in short, any errors in imported files are hidden. Errors in the root file are correctly reported.
This is particularly problematic when using libraries like the graphql-modules library - as you are generally importing a lot of code even if it isn't being used.
I managed to reproduce the issue in graphql-toolkit. Working on a fix now.
Thanks @Myrannas @bopfer !
Fixed in: https://github.com/ardatan/graphql-toolkit/pull/102
Now the complete JS/TS error is being displayed (as-is, without changing it):

Awesome! Thanks for looking at that @dotansimha - the fix looks great.
Fixed in 1.2.0.
Most helpful comment
Yep, I think you are correct @bopfer.
I have created a minimal example of this issue in https://github.com/Myrannas/graphql-codegen-error.
Instructions to reproduce are in the readme, but in short, any errors in imported files are hidden. Errors in the root file are correctly reported.
This is particularly problematic when using libraries like the
graphql-moduleslibrary - as you are generally importing a lot of code even if it isn't being used.