graphql-code-generator: Watch mode not working with JavaScript export schema type

I have the following working config file which generates types correctly.

schema: ./server/config/gql-gen/schema.js
overwrite: true
generates:
  # using .ts instead of .d.ts so we can import enums from it
  ./server/types/graphql.ts:
    config:
      noNamespaces: true
      contextType: ../graphql#GqlContext
      fieldResolverNamePrefix: Field
      # see https://graphql-code-generator.com/docs/plugins/typescript-resolvers#mappers-overwrite-parents-and-resolved-values
      mappers:
        Product: ../graphql/product/product-model#ProductParent
      scalars:
        Date: Date
    plugins:
      - add: "/**\n * THIS IS A GENERATED FILE, DO NOT MODIFY DIRECTLY\n */\n"
      - typescript-common
      - typescript-server
      - typescript-resolvers

However, when running the CLI with --watch, it does not see any changes to the schema files (which are imported in schema.js).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

You are right @minheq . I managed to reproduce it locally, it caused by require cache. Fixed in graphql-toolkit 😃

Looks still relevant to me, so I created new issue.

I am actually still seeing this behavior (watching files works, but output is untouched on change) in 1.8.3.

Here is my codegen.yml

schema: src/graph/schema.ts
require:
    - ts-node/register
watch:
    - src/graph/nodes/**/*.ts
overwrite: true
generates:
    src/graph/gen-types.ts:
        plugins:
            - typescript
            - typescript-resolvers
        config:
            contextType: ./context#IContext