d4rekanguok/gatsby-typescript

Very slow codegen due to the documentPaths option includes './node_modules/gatsby-*/**/*.js'

LesleyLai opened this issue · 8 comments

Maybe that is because my site uses a lot of plugins, but the default option causes the dev server to freeze a few seconds every time I do an edit. Removing './node_modules/gatsby-/**/.js' from thedocumentPaths option solves this problem.

Thank you for this report @LesleyLai, I think we can definitely improve this area.

Perhaps we can try identifying the location of all plugins fragments in onPreInit and only fed those identified paths to graphql-codegen. Is your project opensource by any chance?

@cometkim ooh is this what you guys are doing? Manually identify fragments in node_modules?

@d4rekanguok Nope. my plugin track only documents that actually processed by gatsby. so no need to specify glob pattern or manually add it at all.

@d4rekanguok Thank you for the quick response. Unfortunately, that project is not open-sourced.

This might be super obvious to a person more used to gatsby than myself, but I had a config file that looked something like this…

module.exports = {
  siteMetadata: {
    title: "SomeSite",
    siteUrl: "https://herpderp.com",
  },
  plugins: [
    "gatsby-plugin-graphql-codegen",
    // blah blah blah
    {
      resolve: `gatsby-plugin-graphql-codegen`,
      options: {
        codegen: false,
        documentPaths: ['./src/**/*.{ts,tsx}']
      }
    },
    // etc. etc
  ]
}

so the codegen: false bit was being ignored. This locked up the refresh on every edit, which for my codebase (a fairly large Contentful stack) was about 20-30 seconds long.

Just leaving this here in case future generations find this helpful.

Hi @EricWVGG, thanks for using this plugin! To clarify, do you actually have 2 instances of gatsby-plugin-graphql-codegen, or is it some sort of typo? If you do, it is valid to have multiple instances of the same gatsby plugin, so only one will have codegen turned off.

no, I was just a dunce and had it listed multiple times. Removing the first reference fixed my issue.

Hello
I notice the same problem. The codegen it's very slow by default.
But I have just start my project, so I havent plugins with definitions and have warning

warn [gatsby-plugin-graphql-codegen]
Unable to find any GraphQL type definitions for the following pointers:

  • /home/sebtiz13/Developpement/gatsby-website/node_modules/gatsby-/**/.js

my actual gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-extract-schema',
      options: {
        dest: `${__dirname}/graphql.schema.json`,
      },
    },
    {
      resolve: 'gatsby-plugin-graphql-codegen',
      options: {
        fileName: 'graphql.d.ts',
        // Prevent slow codegen
        documentPaths: ['./src/**/*.{ts,tsx}'],
        codegenConfig: {
          // No export to use globaly with include in tsconfig.json
          noExport: true,
        },
      },
    },
  ],
}