在由 Windows 更新触发的 PC 自动重启(显然)之后,GraphQL 代码生成器停止正常运行。它不再生成预期的代码,并且还删除了所有以前生成的文件。 codegen.ts 和 package.json 未更改。 使用
npm run generate
- graphql-codegen --config codegen.ts
生成
问题是什么?
我当前的文件:
codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: 'https://studyhelper-backend.azurewebsites.net/graphql/',
documents: ['lib/**/*.ts', 'app/**/*.tsx'],
ignoreNoDocuments: true,
generates: {
'./src/graphql/': {
preset: 'client',
config: {
documentMode: 'string',
},
},
'./schema.graphql': {
plugins: ['schema-ast'],
config: {
includeDirectives: true,
},
},
},
};
export default config;
package.json
{
"name": "studyhelper-frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "node scripts/pre-run.js && next dev",
"build": "next build",
"start": "node scripts/pre-run.js && next start",
"lint": "next lint",
"prepare": "husky install",
"format": "prettier --write .",
"format:check": "prettier --check .",
"generate": "graphql-codegen --config codegen.ts",
"watch": "graphql-codegen --config codegen.ts --watch"
},
"dependencies": {
"@preline/toggle-password": "^2.3.0",
"@tanstack/react-query": "^5.64.1",
"@tanstack/react-query-devtools": "^5.64.1",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"dotenv": "^16.4.5",
"graphql": "^16.10.0",
"graphql-request": "^7.1.2",
"graphql-tag": "^2.12.6",
"i18next": "^23.16.5",
"moment": "^2.30.1",
"next": "14.2.10",
"next-i18next": "^15.3.1",
"preline": "^2.3.0",
"react": "^18",
"react-clock": "^5.1.0",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.2",
"react-i18next": "^15.1.1",
"react-icons": "^5.2.1",
"react-slick": "^0.30.2",
"react-spinner-material": "^1.4.0",
"slick-carousel": "^1.8.1",
"tailwindcss-textshadow": "^2.1.3",
"urql": "^4.2.1"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.12.16",
"@eslint/js": "^9.17.0",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/client-preset": "^4.5.1",
"@graphql-codegen/schema-ast": "^4.1.0",
"@parcel/watcher": "^2.5.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-clock": "^4.1.0",
"@types/react-dom": "^18",
"@types/react-slick": "^0.23.13",
"eslint": "^9.17.0",
"eslint-config-next": "^15.1.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.3",
"globals": "^15.14.0",
"lint-staged": "^15.3.0",
"postcss": "^8",
"prettier": "^3.4.2",
"react-clock": "^5.1.0",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"typescript-eslint": "^8.19.0"
},
"optionalDependencies": {
"husky": "^8.0.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --fix",
"*.{json,css,md}": "prettier --write"
}
}
因此,在
codegen.ts
文档中,目标位置应与生成输出位于同一文件夹中。
documents: ['lib/**/*.ts'],
ignoreNoDocuments: true,
generates: {
'./graphql/': {
preset: 'client',
config: {
documentMode: 'string'
}
},