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

Static query type is not generated after reboot #124

Closed orblazer closed 2 years ago

orblazer commented 3 years ago

Hello, I play with this plugin and after an reboot (without run gatsby clean) the static query type is not generated because action REPLACE_STATIC_QUERY is not called (logic because the query haven't change).

I have try to find an way to fix it but the only action called on each time when build, when start develop, when update is SET_GRAPHQL_DEFINITIONS (definition : https://github.com/gatsbyjs/gatsby/blob/f43a6bd8ab3226afdfa79519d477c2a43f86e66d/packages/gatsby/src/redux/actions/internal.ts#L130).

That return an object like :

{
  components: Map(3) {
    '/data/.cache/dev-404-page.js' => {
      query: 'query PagesQuery {\n' +
        '  allSitePage(filter: {path: {ne: "/dev-404-page/"}}) {\n' +
        '    nodes {\n' +
        '      path\n' +
        '    }\n' +
        '  }\n' +
        '}\n',
      componentPath: '/data/.cache/dev-404-page.js',
      pages: [Set],
      isInBootstrap: true
    },
    '/data/src/pages/404.tsx' => {
      query: '',
      componentPath: '/data/src/pages/404.tsx',
      pages: [Set],
      isInBootstrap: true
    },
    '/data/src/pages/index.tsx' => {
      query: '',
      componentPath: '/data/src/pages/index.tsx',
      pages: [Set],
      isInBootstrap: true
    }
  },
  staticQueryComponents: Map(1) {
    'sq--src-hooks-use-site-metadata-ts' => {
      name: 'SiteMetadata',
      componentPath: '/data/src/hooks/use-site-metadata.ts',
      id: 'sq--src-hooks-use-site-metadata-ts',
      query: 'query SiteMetadata {\n' +
        '  site {\n' +
        '    siteMetadata {\n' +
        '      siteUrl\n' +
        '      title\n' +
        '      description\n' +
        '    }\n' +
        '  }\n' +
        '}\n',
      hash: 227279697
    }
  }
}

For now the only way to fix it its to run gatsby clean before run gatsby develop

Thanks.

cometkim commented 2 years ago

This is fixed in v3. (currently rc)

v3 relies on SET_SCHEMA and SET_GRAPHQL_DEFINITIONS, which is much more stable. Thanks @orblazer