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

Separating queries and type defs with codegen

Open jregistr opened this issue 4 years ago • 1 comments

Hello! Using the gatsby-plugin-graphql-codegen plugin, is it possible to create separate files for types and queries? Let's say I'd like all the types to be in a graphql-types.ts and graphql-queries.ts. In previous non gatsby projects using the codegen app standalone, I've done this using generates config. Something like this:

schema:
  - https://api.github...
generates:
  gql-types.ts:
    plugins:
      - typescript
  gql-queries.ts:
    documents:
      - 'src/**/*.ts'
    preset: import-types
    presetConfig:
      typesPath: ./gql-types
    plugins:
      - typescript-operations

I've tried adding an additionalSchema gatsby plugin option only pointing it to the tsx files. This doesn't seem to work.

Is this possible w/ the plugin as is?

jregistr avatar May 20 '20 03:05 jregistr

Hi @jregistr! Thank you for your interest in this plugin.

It's not possible with the plugin as is, since we're not 1:1 map with codegen cli. For your use case, it might be simpler to write a script that utilize @graphql-codegen/cli directly, as shown here.

I'm thinking about using the cli as well, but haven't really make a decision yet.

d4rekanguok avatar May 23 '20 17:05 d4rekanguok