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 23 forks source link

Types for gatsby-node.ts #110

Open jsbrain opened 4 years ago

jsbrain commented 4 years ago

Hi, I'm trying to get types generated for my root query in gatsby-node.ts.

Somehow this seems to not work. I used a query name (e.g. query GatsbyNode ...) as with all my other queries. All other type generation works fine, just not the gatsby-node.ts ones.

What am I doing wrong here

cometkim commented 4 years ago

@jsbrain Not your fault. it's simply the plugin doesn't support gatsby-node yet.

I'm planning it for the next major version

jsbrain commented 4 years ago

Amazing, thx for your reply! Do you already have an idea about the rough date?

cometkim commented 3 years ago

I will stabilize the plugin implementation over the next week and release v3 that relies on the new lifecycle hook.

The investigation into schema customization will probably be v4. I'm using a lot of schema builders recently, so I know it's really nice to have, but honestly, I'm not sure which is the best way to do

jsbrain commented 3 years ago

Sounds good! Meanwhile, do you have any idea how I could achieve getting those types anyhow? Like can you think of any workaround I could apply or will I definitely have to time them myself? :D

christina-grannas commented 3 years ago

I just ran into the same issue, now I know its not my fault 👍 Types for queries in gatsby-node would be awesome!

knpwrs commented 2 years ago

Is there a recommended work around for this in the interim? Can the queries be placed somewhere where types are generated and then be referenced from gatsby-node.ts?

knpwrs commented 2 years ago

As a temporary workaround I added the following codegen.yml to my project:

schema: http://localhost:8000/__graphql
documents:
  - ./gatsby-node.ts
generates:
  ./src/__generated__/gatsby-node-types.ts:
    plugins:
      - typescript
      - typescript-operations

Then I run a generate script defined as such:

"scripts": {
  "generate": "graphql-codegen",
}

This makes the type generation for the gatsby-*.ts files out-of-band, but it works for me for root queries until this plugin supports gatsby-node.ts.

LekoArts commented 2 years ago

As part of this RFC/Initiative https://github.com/gatsbyjs/gatsby/discussions/35420 I have a WIP PR up for an initial implementation. I have support for gatsby-node.ts working. I'd be really happy if you could follow that discussion and once I have a version published to try out, you could try it out. Thanks!