Graphql-code-generator: Typescript Plugin throws an error

Created on 12 Apr 2019  路  4Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
The Typescript example given in the docs doesn't work. Instead it throws this error:
Plugin typescript does not export a valid JS object with "plugin" function.

I'm just using the built-in typescript plugin.

To Reproduce
Follow the quickstart, use the config from the Typescript example in the documentation

  1. My GraphQL schema:
    Not schema related. Try any schema.

  2. My GraphQL operations:

N/A

  1. My codegen.yml config file:
schema: http://localhost:1337/graphql
documents: ./src/**/*.graphql
generates:
  ./src/types.ts:
    plugins:
      - typescript

Expected behavior
The library should work as advertised, doing what it claims to do in the docs.

Please stop with the radical changes. This library was working wonderfully a few months ago. It's eating valuable dollars and time right now.

When I download a library, I expect the docs on the library's website to be for the same version of the current release. However, the docs are clearly out of touch. Notice the Programmatic usage section.

Environment:
Node v10.10.0 on a 2018 Macbook pro
Lib version: 1.0.7, the current release.

Additional context
It was working before 1.0 broke everything.

Most helpful comment

Hi @robbyemmert ,

A few notes regarding the issues you had:

  • It looks like something is wrong with the yml you used, I'm not sure what it is, because I couldn't reproduce it, and you didn't provide a repository than reproduces it.
  • The docs are updated, if there is a mistake with the docs, then that's something else, but it's updated.
  • The CLI does not require graphql to be globally installed. If you install the codegen as global dependency, than yes, you need graphql to be global as well. We do not recommend to install it globally.
  • The programmatic API is updated and working, and the docs are updated. If you think that it doesn't work, please open a new issue with more information.

Regarding the API changes:

  • The API has changed in 1.0, that's why it called 1.0, because we introduced breaking changed, and we follow semver.
  • The core library has changed because we wanted to make it agnostic, and remove all the NodeJS dependencies. This way it's now possible to run the codegen in browsers, with a minimal bundle size and tree-shaking. That's why the programmatic API has changed as well. And again - only in 1.0, according to the semver standard.

Regarding the output changes:

  • There was an issue from 7 months ago, and we started to discuss the changes we did in 1.0, there is nothing new in it. https://github.com/dotansimha/graphql-code-generator/issues/713
  • The new API changes and the breaking changes was announced, in a pinned issue, for over a month. https://github.com/dotansimha/graphql-code-generator/issues/1350
  • The work on the refactor took over a month, of multiple people, and we did it gradually with alpha and beta versions before the release. We are also doing projects for clients, and we tested it comprehensively before releasing it to the public.
  • The output is much more optimized and has less issues, and not it's very easy to find issues before they happen.

Also, a note about open-source:
This project is an open-source, and we are a team of developers, putting our best efforts to make this library free, reliable, customizable and easy-to-use. We are constantly upgrading it and adding more plugins and more features. Sometimes things breaks, but that's the beauty of open-source - you can always participate and contribute.
If you think something is not right or not updated - you can always open a PR that fixes it and not just open an issue and complain.

And in a more personal manner - if you thing that we are wasting your "valuable dollars and time" - please do not use this library at all. There are other solution for generating code from GraphQL.

We will always introduce "radical changes" because GraphQL (and software, in general) evolves all the time, and we must stay on top of it if we want this package to remain relevant.
I know not all your expectations are met with the 1.0 release, but my expectations from the community is to take an active part on developing it, and not just complaining about it.

All 4 comments

I ran through everything again from scratch, this time using the cli init command instead of copying the yml file from the Typescript example in the docs. It worked. Seems the docs are out of date...

For reference, here are a few parts of my old workflow that the 1.0.X updates have broken:

  • The docs for the programmatic api are out of date, making it impossible to use the programmatic api anymore (I assume it actually does work, I just have no way of knowing how)
  • The new 'core' module lacks a bunch of basic functionality (such as pulling schema from a remote server) that was standard in the old library
  • The CLI requires a globally installed graphql package. As a rule, I NEVER rely on globally installed packages, and run everything using the locally installed copy via an NPM script. This makes sure my team members stay in sync.

All in all, I feel that 1.0 has been released prematurely.

Hi @robbyemmert ,

A few notes regarding the issues you had:

  • It looks like something is wrong with the yml you used, I'm not sure what it is, because I couldn't reproduce it, and you didn't provide a repository than reproduces it.
  • The docs are updated, if there is a mistake with the docs, then that's something else, but it's updated.
  • The CLI does not require graphql to be globally installed. If you install the codegen as global dependency, than yes, you need graphql to be global as well. We do not recommend to install it globally.
  • The programmatic API is updated and working, and the docs are updated. If you think that it doesn't work, please open a new issue with more information.

Regarding the API changes:

  • The API has changed in 1.0, that's why it called 1.0, because we introduced breaking changed, and we follow semver.
  • The core library has changed because we wanted to make it agnostic, and remove all the NodeJS dependencies. This way it's now possible to run the codegen in browsers, with a minimal bundle size and tree-shaking. That's why the programmatic API has changed as well. And again - only in 1.0, according to the semver standard.

Regarding the output changes:

  • There was an issue from 7 months ago, and we started to discuss the changes we did in 1.0, there is nothing new in it. https://github.com/dotansimha/graphql-code-generator/issues/713
  • The new API changes and the breaking changes was announced, in a pinned issue, for over a month. https://github.com/dotansimha/graphql-code-generator/issues/1350
  • The work on the refactor took over a month, of multiple people, and we did it gradually with alpha and beta versions before the release. We are also doing projects for clients, and we tested it comprehensively before releasing it to the public.
  • The output is much more optimized and has less issues, and not it's very easy to find issues before they happen.

Also, a note about open-source:
This project is an open-source, and we are a team of developers, putting our best efforts to make this library free, reliable, customizable and easy-to-use. We are constantly upgrading it and adding more plugins and more features. Sometimes things breaks, but that's the beauty of open-source - you can always participate and contribute.
If you think something is not right or not updated - you can always open a PR that fixes it and not just open an issue and complain.

And in a more personal manner - if you thing that we are wasting your "valuable dollars and time" - please do not use this library at all. There are other solution for generating code from GraphQL.

We will always introduce "radical changes" because GraphQL (and software, in general) evolves all the time, and we must stay on top of it if we want this package to remain relevant.
I know not all your expectations are met with the 1.0 release, but my expectations from the community is to take an active part on developing it, and not just complaining about it.

@dotansimha It will be great to provide a solution to this issue. I am facing the same error using the library out of the box. My codegen.yml is:

overwrite: true
schema: "./schema.graphql"
documents: null
generates:
  ./types.ts:
    plugins:
      - "typescript"

I get the error Plugin typescript does not export a valid JS object with "plugin" function.

Was this page helpful?
0 / 5 - 0 ratings