gatsby-typescript icon indicating copy to clipboard operation
gatsby-typescript copied to clipboard

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

Open LesleyLai opened this issue 5 years ago • 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.

LesleyLai avatar May 06 '20 15:05 LesleyLai

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?

d4rekanguok avatar May 07 '20 04:05 d4rekanguok

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

d4rekanguok avatar May 07 '20 04:05 d4rekanguok

@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.

cometkim avatar May 07 '20 05:05 cometkim

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

LesleyLai avatar May 07 '20 18:05 LesleyLai

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.

EricWVGG avatar May 26 '20 23:05 EricWVGG

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.

d4rekanguok avatar May 27 '20 03:05 d4rekanguok

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

EricWVGG avatar May 27 '20 03:05 EricWVGG

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,
        },
      },
    },
  ],
}

sebtiz13 avatar Sep 27 '20 15:09 sebtiz13