Graphql-code-generator: Watch mode not working as expected

Created on 28 Dec 2018  ·  4Comments  ·  Source: dotansimha/graphql-code-generator

Describe the bug
Watch mode is either not watching or not overwriting over the changes made

To Reproduce
Steps to reproduce the behavior:

Clone repository:
git clone -b graphql-ts https://github.com/swcarlosrj/SpaceX-API.git
Install deps & start server:
yarn && yarn start
Generate types:
yarn generate
Change any file into schema folder

Expected behavior
Auto generate types & overwrite the current types everytime that I change any file

Environment:

OS: macOS Mojave 10.14.2 (18C54)
Codegen: 0.15.2
Node: 10.10.0

Additional context
With the current codegen.yml config, it doesn't watch although it generated correctly the types

schema: src/graphql/schema/index.ts
overwrite: true
watch: true
require:
  - ts-node/register
generates:
  ./src/graphql/types/types.d.ts:
    config:
      contextType: ./context#MyContext
    plugins:
      - typescript-common
      - typescript-server
      - typescript-resolvers

Instead with this codegen.yml config, it doesn't generate correctly the types although it seems to be watching

schema: src/graphql/schema/**/*.ts
overwrite: true
watch: true
require:
  - ts-node/register
generates:
  ./src/graphql/types/types.d.ts:
    config:
      contextType: ./context#MyContext
    plugins:
      - typescript-common
      - typescript-server
      - typescript-resolvers
bug core

Most helpful comment

@dotansimha I've just tried, it works great both overwriting new generated types & watching mode, I think that I was using documents config field before, thats why I was not getting the desired generated types.

If it's useful for someone, I leave here the current config that I'm using to generate types for the GraphQL Schema & Resolvers, working 100% as expected!

schema: src/graphql/schema/**/*.ts
overwrite: true
watch: true
require:
  - ts-node/register
generates:
  ./src/graphql/types/types.d.ts:
    config:
      contextType: ./context#MyContext
    plugins:
      - typescript-common
      - typescript-server
      - typescript-resolvers

Incredible tool & better work, thanks for such amazing contribution 😍

All 4 comments

cc @kamilkisiela

FYI I tried via the CLI flag and watch mode doesn't work either. It exits immediately:

$ npx gql-gen --config graphql/codegen.yml -w
  ✔ Parse configuration
  ✔ Generate outputs
  ℹ Watching for changes...
$ _

@swcarlosrj Can you please explain what was the difference in the output between schema: src/graphql/schema/**/*.ts and src/graphql/schema/index.ts? why does the output it not correct with schema: src/graphql/schema/**/*.ts?

Also, what src/graphql/schema/index.ts contains? I'm not sure we are watching the files loaded by src/graphql/schema/index.ts (or maybe it's just require cache in this case).

@dotansimha I've just tried, it works great both overwriting new generated types & watching mode, I think that I was using documents config field before, thats why I was not getting the desired generated types.

If it's useful for someone, I leave here the current config that I'm using to generate types for the GraphQL Schema & Resolvers, working 100% as expected!

schema: src/graphql/schema/**/*.ts
overwrite: true
watch: true
require:
  - ts-node/register
generates:
  ./src/graphql/types/types.d.ts:
    config:
      contextType: ./context#MyContext
    plugins:
      - typescript-common
      - typescript-server
      - typescript-resolvers

Incredible tool & better work, thanks for such amazing contribution 😍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SimenB picture SimenB  ·  3Comments

dotansimha picture dotansimha  ·  3Comments

fvisticot picture fvisticot  ·  3Comments

RIP21 picture RIP21  ·  3Comments

rogerg93 picture rogerg93  ·  3Comments