cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

gatsby-types.d.ts is not generated #159

Closed marcus13371337 closed 2 years ago

marcus13371337 commented 3 years ago

Hello!

I'm trying to install and set up this plugin, but I'm unable to get the types-file generated (gatsby-types.d.ts).

This is my config for this plugin:

  {
    resolve: 'gatsby-plugin-typegen',
    options: {
      outputPath: 'src/__generated__/gatsby-types.d.ts',
      includeResolvers: false,
      emitSchema: {
        'src/__generated__/gatsby-schema.graphql': true,
        'src/__generated__/gatsby-introspection.json': true,
      },
      emitPluginDocuments: {
        'src/__generated__/gatsby-plugin-documents.graphql': true,
      },
    },
  },

After I run either gatsby develop or gatsby build, the only files that end up in the __generated__ folder is:

gatsby-introspection.json
gatsby-schema.graphql

These are some relevant plugins that I'm are using:

    "gatsby-plugin-ts": "^2.7.1",
    "gatsby-plugin-typegen": "^2.2.4",
    "gatsby": "^2.32.4",

I did some digging into your code, and it seems as QUERY_EXTRACTION_BABEL_SUCCESS is never triggered. Added a debug log where it checks for that action. These are the actions types that it was able to pick up:

CREATE_TYPES
CREATE_NODE
TOUCH_NODE
DELETE_NODE
BUILD_TYPE_METADATA
START_INCREMENTAL_INFERENCE
DISABLE_TYPE_INFERENCE
SET_SCHEMA_COMPOSER
SET_SCHEMA
CREATE_REDIRECT
CREATE_PAGE
API_FINISHED

These are the typegen logs:

[typegen] Successfully validate your configuration.
{
  "language": "typescript",
  "namespace": "GatsbyTypes",
  "outputPath": "src/__generated__/gatsby-types.d.ts",
  "includeResolvers": false,
  "autoFix": true,
  "emitSchema": {
    "src/__generated__/gatsby-schema.graphql": {
      "format": "sdl",
      "commentDescriptions": true
    },
    "src/__generated__/gatsby-introspection.json": {
      "format": "introspection",
      "commentDescriptions": true
    }
  },
  "emitPluginDocuments": {
    "src/__generated__/gatsby-plugin-documents.graphql": true
  },
  "scalars": {}
}

[typegen] Listen on query extraction
[typegen] End-up listening on query extraction.
[typegen] Watching schema/query changes and re-run workers
[typegen] Emit Gatsby schema into src/__generated__/gatsby-schema.graphql
[typegen] Emit Gatsby schema into src/__generated__/gatsby-introspection.json

Any ideas?

marcus13371337 commented 3 years ago

Just wanted to give some more information. It seems as QUERY_EXTRACTION_BABEL_SUCCESS is actually triggered on gatsby build. Here are the gatsby build logs: Action types.

ACTIVITY_END
LOG
SET_PROGRAM_EXTENSIONS
ACTIVITY_START
CREATE_TYPES
CREATE_NODE
TOUCH_NODE
DELETE_NODE
BUILD_TYPE_METADATA
START_INCREMENTAL_INFERENCE
DISABLE_TYPE_INFERENCE
SET_SCHEMA_COMPOSER
SET_SCHEMA
CREATE_REDIRECT
CREATE_PAGE
API_FINISHED
REMOVE_STATIC_QUERIES_BY_TEMPLATE
QUERY_EXTRACTION_BABEL_SUCCESS
SET_GRAPHQL_DEFINITIONS
QUERY_EXTRACTED

typegen logs

verbose [typegen] Successfully validate your configuration.
{
  "language": "typescript",
  "namespace": "GatsbyTypes",
  "outputPath": "src/__generated__/gatsby-types.d.ts",
  "includeResolvers": false,
  "autoFix": true,
  "emitSchema": {
    "src/__generated__/gatsby-schema.graphql": {
      "format": "sdl",
      "commentDescriptions": true
    },
    "src/__generated__/gatsby-introspection.json": {
      "format": "introspection",
      "commentDescriptions": true
    }
  },
  "emitPluginDocuments": {
    "src/__generated__/gatsby-plugin-documents.graphql": true
  },
  "scalars": {}
}
verbose [typegen] Listen on query extraction
verbose [typegen] End-up listening on query extraction.
verbose [typegen] Emit Gatsby schema into src/__generated__/gatsby-schema.graphql
verbose [typegen] Emit Gatsby schema into src/__generated__/gatsby-introspection.json
cometkim commented 3 years ago

yeah... I actually have been tracking and have noticed the lifecycle difference on gatsby develop vs gatsby build

https://github.com/cometkim/gatsby-lifecycle-watcher

I have a resolution to be included in the v3 release. I don't have spent a lot of time here... but I'll release it soon because I recently started dogfooding again.

marcus13371337 commented 3 years ago

Just to be clear, I'm unable to generate the gatsby-types.d.ts for both commands

stefanpl commented 3 years ago

Facing the same issue … quite frustrating, since it cannot be reproduced reliably, and breaks CI. (parallel soucing is diabled) Looking forward to v3 😊

cometkim commented 2 years ago

This should be fixed in v3, and I will test it on my Gatsby Cloud today.

v3 doesn't use QUERY_EXTRACTION_BABEL_SUCCESS action anymore.