danielwaltz / vite-plugin-graphql-codegen

Zero-config vite plugin that uses the vite file watcher to run graphql codegen programmatically without needing to start a separate watcher
https://www.npmjs.com/package/vite-plugin-graphql-codegen
MIT License
83 stars 8 forks source link

Support `documents` under `generates` field in graphql config #24

Closed KholdStare closed 5 months ago

KholdStare commented 1 year ago

Using a config such as the one below fails to find the listed documents since it is not at the top level. I think the code should also recursively gather all documents fiels from all generates sections.

schema:
  - ../blockchain/subgraph/remote-schema.graphql
generates:
  "src/generated/subgraph.ts":
    documents:
      - operations.graphql
    plugins:
      # see https://the-guild.dev/graphql/codegen/plugins/typescript/typescript
      - typescript
      # see https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations
      - typescript-operations
      # see https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-urql
      - typescript-urql
    config:
      useTypeImports: true # use `import type {}`
      strictScalars: true # make sure all scalars have typescript types
      pureMagicComment: true # helps with treeshaking for bundlers like webpack to reduce bundle size
      scalars: # define typescript types for custom scalars
        Bytes: string
        BigDecimal: string
        BigInt: string
        Int8: number
    hooks:
      afterOneFileWrite:
        - prettier --write