Graphql-code-generator: Using type with name `Subscription` results in funky behaviour.

Created on 28 Nov 2018  路  7Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
When defining a ObjectType with the name Subscription, and either having no Subscriptions definitions or having a Subscription root with a different Subscription root type results in errors.

To Reproduce
Steps to reproduce the behavior:

  1. Use the following schema file:
schema {
  query: QueryRoot
}

type Subscription {
  name: String
  rank: Float
}

type QueryRoot {
  commander: Commander
}
  1. Use the following document:
query getWelcomeGreet {
  welcome {
    hello
  }
}
  1. Run gql-gen with the following codegen.yml:
schema:
  - 'src/app/**/*.graphqls'
documents:
  - 'src/**/*.graphql'
config: {}
generates:
  src/app/graphql/queries.ts:
    config: {}
    plugins:
      - 'typescript-common'
      - 'typescript-client'
      - 'typescript-apollo-angular'
watch: true
overwrite: true
require: []

Expected behavior
Expected a normal generation of types, queries etc.

bug

All 7 comments

I was in the same situation, and I figured out the reason.

Since v0.14.4, it depends on @graphql-modules/epoxy version 0.2.12. But it has a bug around Subscription since v0.2.10.

https://github.com/Urigo/graphql-modules/issues/202

I sent a patch to fix that, and it was merged. After it will be released, graphql-code-generator have to upgrade the dependency.

workaround:

@wesselvdv you can avoid using @graphql-modules/epoxy broken version with yarn's resolutions.

  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "~6.1.2",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@graphql-modules/epoxy": "0.2.9", // Lock to 0.2.9
    "@types/node": "~8.9.4",
    "graphql-code-generator": "0.14.4",
    "graphql-codegen-apollo-angular-template": "0.14.4",
    "graphql-codegen-introspection-template": "0.14.4",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.9.2"
  },
  "resolutions": {
    "@graphql-modules/epoxy": "0.2.9" // Force to use 0.2.9 in graphql-code-generator
  }

@dotansimha could you revert the @graphql-modules/epoxy version to 0.2.9 or before, and release v0.14.5?
I think this is a degradation of v0.14.4.
cc/ @kamilkisiela

Could you try the canary version ?

Changes:
 - graphql-code-generator: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-core: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - codegen-templates-scripts: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-plugin-handlebars-helpers: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-plugin-helpers: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-add: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-introspection: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-schema-ast: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-time: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-apollo-angular: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-client: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-common: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-graphql-files-modules: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-mongodb: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-react-apollo: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-resolvers: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-server: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-apollo-angular-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-graphql-files-typescript-modules: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-introspection-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-mongodb-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-react-apollo-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-resolvers-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9
 - graphql-codegen-typescript-template: 0.14.4 => 0.15.0-alpha.8ecaa8b9

@ardatan It works!

my case

  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "~6.1.2",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/node": "~8.9.4",
    "graphql-code-generator": "0.15.0-alpha.8ecaa8b9",
    "graphql-codegen-apollo-angular-template": "0.15.0-alpha.8ecaa8b9",
    "graphql-codegen-introspection-template": "0.15.0-alpha.8ecaa8b9",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.9.2"
schema: ...
documents: ./src/**/*.gql
overwrite: true
generates:
  ./src/app/generated/graphql.ts:
    plugins:
      - typescript-common
      - typescript-client
      - typescript-apollo-angular

Great!

v0.14.5 looks good! I confirmed it has been solved in my situation.

v0.14.5 is out :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steebchen picture steebchen  路  3Comments

rogerg93 picture rogerg93  路  3Comments

dotansimha picture dotansimha  路  3Comments

bastman picture bastman  路  3Comments

edorivai picture edorivai  路  3Comments