Graphql-code-generator: 1.6.0 breaks meteor support

Created on 5 Sep 2019  路  8Comments  路  Source: dotansimha/graphql-code-generator

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.

Unable to load schema from file "c:/dev/my-project/src/server/api/connectors.ts" due to import error: Cannot find module 'meteor/meteor'
Error: Unable to load schema from file "c:/dev/my-project/src/server/api/connectors.ts" due to import error: Cannot find module 'meteor/meteor'
    at tryToLoadFromExport (c:\dev\my-project\node_modules\graphql-toolkit\src\loaders\load-from-code-file.ts:74:11)
    at Object.loadFromCodeFile (c:\dev\my-project\node_modules\graphql-toolkit\src\loaders\load-from-code-file.ts:105:20)

To Reproduce
Steps to reproduce the behavior:

  1. Create a meteor project
  2. Add import statement like import { Meteor } from 'meteor/meteor'
  3. Try generate files

Environment:

  • OS: Windows 10
  • @graphql-codegen/1.6.0:
  • NodeJS: 8.16.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?

bug core waiting-for-release

Most helpful comment

Fixed in 1.8.0 馃殌

All 8 comments

@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/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected] @graphql-codegen/[email protected]

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.

See https://github.com/ardatan/graphql-toolkit/issues/260

@jbaranski we fixed that in graphql-toolkit, and updated here, a fix will be available in the next stable version.

Was this page helpful?
0 / 5 - 0 ratings