Graphql-code-generator: Not generating Components or Documents

Created on 19 Mar 2019  路  16Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
After upgrading from 0.18.0 to 1.0.0 Documents and Components are no longer generating. It is generating types and enums.

To Reproduce
Steps to reproduce the behavior:

  1. Updated the package.json from:
 "graphql-code-generator": "^0.18.0",
 "graphql-codegen-add": "^0.18.0",
 "graphql-codegen-typescript-client": "^0.18.0",
 "graphql-codegen-typescript-common": "^0.18.0",
 "graphql-codegen-typescript-react-apollo": "^0.18.0",

to

 "@graphql-codegen/cli": "^1.0.0",
 "@graphql-codegen/add": "^1.0.0",
 "@graphql-codegen/typescript": "^1.0.0",
 "@graphql-codegen/typescript-operations": "^1.0.0",
 "@graphql-codegen/typescript-react-apollo": "^1.0.0",
  1. Update codegen.yml from: (NOTE: generates section has been simplified)
sharedPlugins: &sharedPlugins
  plugins:
    - add: /* THIS IS A GENERATED FILE - DO NOT MODIFY */
    - add: // tslint:disable
    - typescript-common
    - typescript-client
    - typescript-react-apollo

sharedDocuments: &sharedDocuments src/apollo/shared/*.graphql

schema: https://domain.com/api/graphql
config:
  noNamespaces: true
overwrite: true
generates:
  src/apollo/contacts/index.tsx:
    <<: *sharedPlugins
    schema: src/apollo/contacts/client/schema.graphql
    documents:
      - *sharedDocuments
      - src/apollo/contacts/**/!(schema).graphql

to

sharedPlugins: &sharedPlugins
  plugins:
    - add: /* THIS IS A GENERATED FILE - DO NOT MODIFY */
    - add: // tslint:disable
    - typescript
    - typescript-operations
    - typescript-react-apollo

sharedDocuments: &sharedDocuments src/apollo/shared/*.graphql

schema: https://domain.com/api/graphql
overwrite: true
generates:
  src/apollo/contacts/index.tsx:
    <<: *sharedPlugins
    schema: src/apollo/contacts/client/schema.graphql
    documents:
      - *sharedDocuments
      - src/apollo/contacts/**/!(schema).graphql
  1. Run gql-gen

Expected behavior
Types, Enums, Components and Documents to be in the generated files

Actual behavior
Generated files contain only Types and Enums.

Schema/Documents
src/apollo/contacts/queries.graphql

fragment ContactMaster on Contact {
  id
  firstName
  lastName
  image {
    id
  }
  category
  address {
    type
    loc {
      addr
      lat
      lon
    }
  }
  description
  tag
}

query ContactEntry($id: String!) {
  contact(id: $id) {
    ...ContactMaster
  }
}

Environment:

  • OS: Windows 10
  • Codegen: 1.0.0
  • Node: 10.8.0

Additional context
I have tried to simplify this down as much as I can. I have tried removing the advanced yaml features from the codegen.yml file and stripping out all but a basic query.

When generating into a single file, it seems to properly generate everything. Using this:

schema: https://domain.com/api/graphql
overwrite: true
documents: src/apollo/contacts/queries.graphql
generates:
  components.tsx:
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
bug core waiting-for-release

Most helpful comment

Fixed in 1.0.3 馃帀

@stramel

All 16 comments

Found the issue after some more debugging but I'm not sure why this is breaking it where as it previously worked fine.

  plugins:
    - add: /* THIS IS A GENERATED FILE - DO NOT MODIFY */
    - add: // tslint:disable

When I remove - add: //tslint:disable it works as expected.

@stramel any chance you can create a reproduction repo for it? I couldn't reproduce it locally :(

@stramel I was experiencing the same, but if I quote the values it works.

  plugins:
    - add: "/* THIS IS A GENERATED FILE - DO NOT MODIFY */"
    - add: "// tslint:disable"

Quotes only seem to be required when there are more than one add definition.

@ctrlplusb I think you are right, it might be related to the characters in the string there, I think it effects the way js-yaml parses it.
@stramel can you please try it?

@dotansimha I'm working on a reproducible case for you.

@ctrlplusb I was unable to get it to work even when quoting the values of - add:

Also, @stramel , can you please try without the <<: *sharedPlugins ? just with plugins directly.

Actually, just checked again; adding quotes only partially resolved the issue. i.e. the generation is still broken. Just noticed half the expected types are missing.

@dotansimha I tried in the reproduction which didn't have the yaml merge.

@dotansimha

I have a reproducible repo here: https://github.com/stramel/graphql-code-generator-issue-1499

I have run the generate already and the file is observable at src/apollo/contacts/index.tsx

Steps to Reproduce:

  1. Clone this repo: https://github.com/stramel/graphql-code-generator-issue-1499
  2. Install dependencies: yarn
  3. Generate an OAuth token from GitHub (Permissions I used, read:user). https://github.com/settings/tokens
  4. Replace OAUTH-TOKEN with the OAuth token in the codegen.yml
  5. Generate the file: yarn generate

Expected Result:
There should be a Component and Document in this file.

To observe the expected result, do the following:

  1. Remove - add: "// tslint:disable" from the codegen.yml
  2. Re-run the generation, yarn generate

Actual Result:
No Component or Document are present.

Hope this helps!

Thanks @stramel . It's not an issue with YML parsing, I'm looking into it now.

@stramel found the bug, there was an issue when specifying the same plugin twice, it ignored some other plugins. Fixed in: https://github.com/dotansimha/graphql-code-generator/pull/1534

Fixed in 1.0.3 馃帀

@stramel

Thank you for the help, quick responses, and fix!

@dotansimha with 1.0.3 im having the same issue where its not creating documents or components.

here is my config:

schema:
  - http://localhost:4000/
overwrite: true
documents:
  - "src/**/graphql.ts"
generates:
  src/generated/apolloComponents.tsx:
    plugins:
      - add: "/* tslint:disable */"
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      withComponent: true
      withHooks: true
      withHOC: false

@wrod7 , can you please open a new issue? I'm not sure it's related to the same bug.

@dotansimha Having same issue with .ts file. I will open a new issue.

Was this page helpful?
0 / 5 - 0 ratings