dotansimha/graphql-code-generator

Mention tsconfig-paths for codegen.ts?

Open

#8.838 aberto em 20 de jan. de 2023

Ver no GitHub
 (7 comments) (6 reactions) (0 assignees)TypeScript (1.295 forks)batch import
help wanted

Métricas do repositório

Stars
 (10.341 stars)
Métricas de merge de PR
 (Mesclagem média 22d 9h) (53 fundiu PRs em 30d)

Description

Which packages are impacted by your issue?

No response

Describe the bug

If you are using a paths section in your tsconfig.json, the codegen.ts config will fail to load if it exports any code from your project. This can happen, for instance, if you are using Pathos, which recommends providing the scheme as a string to the config.

❯ npm run gql-codegen

> gql-codegen
> graphql-codegen

TypeScriptLoader failed to compile TypeScript:
Cannot find module '@lib/model-settings'
Require stack:
- /Users/artyom/code/windorg/woc/lib/graphql/schema/user.ts
- /Users/artyom/code/windorg/woc/lib/graphql/schema.ts
- /Users/artyom/code/windorg/woc/codegen.ts
- /Users/artyom/code/windorg/woc/node_modules/cosmiconfig-typescript-loader/dist/cjs/index.js
- ...

The solution is to add this section to your tsconfig.json:

  "ts-node": {
    "require": [
      "tsconfig-paths/register"
    ]
  }

And install npm i -D tsconfig-paths.

I suppose this could be mentioned in the getting-started guide, but I don't know where in particular.

Your Example Website or App

Steps to Reproduce the Bug or Issue

Expected behavior

Screenshots or Videos

Platform

  • OS: macOS
  • NodeJS: 16.18.0
  • graphql version: 16.6.0
  • @graphql-codegen/cli@2.16.2
  • @graphql-codegen/client-preset@1.2.6

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli'
import { printSchema } from 'graphql'
import { schema } from '@lib/graphql/schema'

const config: CodegenConfig = {
  schema: printSchema(schema),
  documents: ['{components,lib,pages}/**/!(*.graphql).{ts,tsx}'],
  generates: {
    './generated/graphql/': {
      preset: 'client',
      plugins: [],
    },
  },
}

export default config

Additional context

No response

Guia do colaborador