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

Output scheme to theme instead of starter #167

Open kalebheitzman opened 3 years ago

kalebheitzman commented 3 years ago

Consider the following example:

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

Shipping types with a theme by changing the output directory and this correctly puts the types in the theme that I'm developing. Is there an option to make the schema and plugin documents output inside of the theme instead of the main/starter project. I'm loading this plugin from the theme as well.

I'm using yarn workspaces to develop the theme as suggested in the Gatsby docs.

cometkim commented 3 years ago

Well, to be honest, I've been thinking about this recently while using the plugin for my work, and there's no clear answer yet.

The difficult part is that this plugin cannot run independently of the site as it depends on the fully Gatsby.js lifecycle.

cometkim commented 2 years ago

I've considered providing a separate binary including Gatsby's default schema, but considering that the Gatsby Theme composition can be very heavy and complex, it is not a realistic solution. It only makes sense when it's all configured.

My suggestion would be to emit the type from the actual configured site, but give it an extra option to put output closer to the theme. (e.g. multiple outputs, near-file-preset, etc)

Or assuming that themes are usually managed in monorepo, the Gatsby site emitting types can be operated as a library.