gatsby-plugin-typegen icon indicating copy to clipboard operation
gatsby-plugin-typegen copied to clipboard

Types for gatsby-node.ts

Open jsbrain opened this issue 4 years ago • 8 comments

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

jsbrain avatar Sep 19 '20 15:09 jsbrain

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

I'm planning it for the next major version

cometkim avatar Oct 23 '20 01:10 cometkim

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

jsbrain avatar Oct 23 '20 05:10 jsbrain

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

cometkim avatar Nov 12 '20 17:11 cometkim

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

jsbrain avatar Nov 12 '20 18:11 jsbrain

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

christina-grannas avatar Jan 07 '21 13:01 christina-grannas

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 avatar Mar 07 '22 17:03 knpwrs

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.

knpwrs avatar Mar 07 '22 17:03 knpwrs

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!

LekoArts avatar Apr 25 '22 15:04 LekoArts