Closed smeijer closed 5 years ago
@smeijer I think your glob pattern might be too broad, because it causes to load this file, and it fails because Meteor has it's own import system that injects meteor/meteor
.
Can you please share you codegen config file?
Also, can you try to add noRequire
as described here: https://github.com/dotansimha/graphql-code-generator/blob/1b2f538dc9ea9f8fa10cf76ecf9171484107fc87/docs/getting-started/schema-field.md#glob-expression ?
@dotansimha, you're right. Making my glob pattern more strict fixes this issue. Strange thing is, it was working in 1.5.0.
- src/server/api/**/*.ts
+ src/server/api/**/typeDef.ts
The config above, works in 1.6.1
. Next step, upgrade 1.6.1
to 1.7.0
:
npm install --save-dev @graphql-codegen/add@1.7.0 @graphql-codegen/cli@1.7.0 @graphql-codegen/fragment-matcher@1.7.0 @graphql-codegen/introspection@1.7.0 @graphql-codegen/schema-ast@1.7.0 @graphql-codegen/typescript@1.7.0 @graphql-codegen/typescript-document-nodes@1.7.0 @graphql-codegen/typescript-graphql-files-modules@1.7.0 @graphql-codegen/typescript-mongodb@1.7.0 @graphql-codegen/typescript-resolvers@1.7.0
npm run codegen
× generated/introspection-result.ts
Failed to load schema from src/server/api/**/typeDef.ts:
Unable to load from file "c:\dev\my-project\src\server\api\typeDef.ts": Cannot find module 'c:devmy-projectsrcserverapi ypeDef.ts'
Error: Unable to load from file "c:\dev\my-project\src\server\api\typeDef.ts": Cannot find module 'c:devmy-projectsrcserverapi ypeDef.ts'
at tryToLoadFromExport (c:\dev\my-project\node_modules\graphql-toolkit\src\loaders\load-from-code-file.ts:85:11)
at Object.loadFromCodeFile (c:\dev\my-project\node_modules\graphql-toolkit\src\loaders\load-from-code-file.ts:116:20)
at <anonymous>
GraphQL Code Generator supports:
- ES Modules and CommonJS exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type definitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
config:
definitions:
add: &top-comment
content: >
/**
* NOTE: THIS IS AN AUTO-GENERATED FILE. DO NOT MODIFY IT DIRECTLY.
*/
/* eslint-disable */
scalars: &scalars
Date: Date
Long: number
JSON: '{ [key: string]: any }'
namingConvention: &namingConvention
enumValues: change-case#upperCase
overwrite: true
schema:
- src/server/api/**/typeDef.ts
require:
- ts-node/register
generates:
generated/introspection-result.ts:
plugins:
- add: *top-comment
- 'fragment-matcher'
I think that bug in 1.7.0 is related to https://github.com/ardatan/graphql-toolkit/issues/231
@smeijer I got the same kind of error you did in your stack trace, the paths get mangled on the require call in tryToLoadFromExport
because the Windows paths have changed from 1.6.1
.
Fixed in graphql-toolkit
, we'll release a new version of the codegen soon.
Fixed in 1.8.0 🚀
This still doesn't work for me on Windows.
@jbaranski we fixed that in graphql-toolkit
, and updated here, a fix will be available in the next stable version.
Describe the bug Using version 1.5.0 works fine in meteor. Imports like
import { Meteor } from 'meteor/meteor'
do not interfere with codegen.Starting from 1.6.0 however, these import statements make the generator crash.
To Reproduce Steps to reproduce the behavior:
import { Meteor } from 'meteor/meteor'
Environment:
@graphql-codegen/1.6.0
:Additional context
The error is correct, this 'module' doesn't exists, as Meteor handles imports differently. The thing is, this wasn't an issue in 1.5. Did something here change? Can we undo it?