错误 TS2416:类型 'ApolloError' 中的 属性 'originalError' 不可分配给基本类型 'GraphQLError' 中的相同 属性
error TS2416: Property 'originalError' in type 'ApolloError' is not assignable to the same property in base type 'GraphQLError'
版本
apollo 服务器错误:3.2.0
graphql: 15.6.1/ 15.7.0
nestjs-cli: 8.1.2
npm: 6.14.15
打字稿:4.4.4
错误:
node_modules/apollo-server-errors/dist/index.d.ts:10:5 - error TS2416: Property 'originalError' in type 'ApolloError' is not assignable to the same property in base type 'GraphQLError'.
Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
Type 'null' is not assignable to type 'Error | undefined'.
10 originalError: Error | null | undefined;
在我错误地清除 node_modules 并使用此 package.json 文件构建后,此问题开始出现:
{
"name": "priojet-backend",
"version": "0.13.6",
"description": "The PRIOjet backend providing APIs (GraphQL and REST) and managing the data stored in a Postgres database.",
"author": "Tobias Wolff, Shivam Pathak",
"private": true,
"license": "UNLICENSED",
"type": "commonjs",
"scripts": {
"prebuild": "rimraf dist",
"build": "NODE_ENV=production nest build -p tsconfig.build.json",
"build:docker": "NODE_ENV=docker nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "NODE_ENV=development nest start",
"start:dev": "NODE_ENV=development nest start --watch",
"start:dev:windows": "set NODE_ENV=development && nest start --watch",
"start:debug": "NODE_ENV=development npm-run-all create-api-info-files && NODE_ENV=development nest start --debug --watch",
"start:debug:docker": "NODE_ENV=docker nest start --debug --watch",
"start:prod": "NODE_ENV=production node dist/main",
"start:prod:pm2": "NODE_ENV=production pm2 start dist/main.js -i 0",
"start:devprod": "NODE_ENV=production DEVPROD=1 ts-node ./migrate.ts && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --maxWorkers=50%",
"test:vscode-jest": "NODE_ENV=test TS_JEST=1 jest \"--detectOpenHandles\" \"--maxWorkers=50%\"",
"test:watch": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --watch --no-cache --silent=false",
"test:cov": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --coverage",
"test:cov:docker": "NODE_ENV=docker TS_JEST=1 jest --detectOpenHandles --coverage",
"test:debug": "NODE_ENV=test TS_JEST=1 node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "NODE_ENV=test TS_JEST=1 jest --config ./test/jest-e2e.json",
"test:changes": "NODE_ENV=test TS_JEST=1 jest -o",
"todo": "grep -R --exclude-dir=node_modules 'todo' .",
"TODO": "grep -R --exclude-dir=node_modules 'TODO' .",
"loose-types": "echo -e 'anys:\n\n'; grep -r any src; echo -e '\n\nfunctions\n\n'; grep -r function src; echo -e '\n\n';",
"db": "npx mikro-orm",
"db:help": "cat ./src/migrations/cli.ts",
"db:update": "ts-node ./migrate.ts",
"db:init": "npx mikro-orm schema:create -r",
"db:migration:create": "npx mikro-orm migration:create",
"db:migration:up": "npx mikro-orm migration:up # Migrate up to the latest version",
"db:migration:down": "npx mikro-orm migration:down # Migrate one step down",
"db:migration:list": "npx mikro-orm migration:list # List all executed migrations",
"db:migration:pending": "npx mikro-orm migration:pending # List all pending migrations",
"prebuild:prod": "rimraf dist # && tsc",
"create-api-info-files": "./create_api_info_files.sh"
},
"dependencies": {
"@apollo/federation": "^0.33.0",
"@apollo/gateway": "^0.33.0",
"@azure/identity": "^1.5.0",
"@azure/storage-blob": "^12.6.0",
"@casl/ability": "^5.3.1",
"@fingerprintjs/fingerprintjs": "^3.2.0",
"@googlemaps/google-maps-services-js": "^3.2.5",
"@mikro-orm/cli": "^4.5.9",
"@mikro-orm/core": "^4.5.9",
"@mikro-orm/knex": "^4.5.9",
"@mikro-orm/migrations": "^4.5.9",
"@mikro-orm/nestjs": "^4.3.0",
"@mikro-orm/postgresql": "^4.5.9",
"@mikro-orm/reflection": "^4.5.9",
"@nestjs/axios": "^0.0.2",
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.0.2",
"@nestjs/core": "^8.0.0",
"@nestjs/event-emitter": "^1.0.0",
"@nestjs/graphql": "^9.0.6",
"@nestjs/passport": "^8.0.0",
"@nestjs/platform-express": "^8.0.11",
"@sentry/node": "^6.13.2",
"@sentry/tracing": "^6.13.2",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.175",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"apollo-server-core": "^3.4.0",
"apollo-server-errors": "^3.2.0",
"apollo-server-express": "^3.4.0",
"apollo-server-types": "^3.3.0",
"axios": "^0.21.4",
"axios-retry": "^3.2.0",
"azure-storage": "^2.10.4",
"body-parser": "^1.19.0",
"bx24-api": "^1.4.1",
"check-peer-dependencies": "^4.0.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cluster": "^0.7.7",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"expo-device": "^3.1.1",
"express": "^4.17.1",
"form-data": "^4.0.0",
"graphql": "^15.6.1",
"graphql-type-json": "^0.3.2",
"http": "^0.0.1-security",
"http-proxy-middleware": "^2.0.1",
"nest-raven": "^8.0.0",
"passport": "^0.4.1",
"passport-azure-ad": "^4.3.1",
"passport-jwt": "^4.0.0",
"randomstring": "^1.2.1",
"reflect-metadata": "^0.1.13",
"request-ip": "^2.1.3",
"sharp": "^0.29.1",
"ts-morph": "^12.0.0",
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.9.0",
"tsutils": "^3.21.0",
"typescript": "^4.4.2",
"util": "^0.12.4",
"uuid": "^8.3.2",
"webpack": "^5.58.1"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.15",
"@nestjs/cli": "^8.1.2",
"@nestjs/schematics": "^8.0.3",
"@nestjs/testing": "^8.0.11",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.2",
"@types/multer": "^1.4.7",
"@types/node": "^16.10.2",
"@types/node-fetch": "^3.0.3",
"@types/request-ip": "0.0.37",
"@types/supertest": "^2.0.10",
"autoclean": "^1.0.2",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"faker": "^5.4.0",
"jest": "^27.2.4",
"jest-junit": "^13.0.0",
"npm-run-all": "^4.1.5",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3",
"ts-jest": "27.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.3.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.4.4"
},
"jest": {
"testTimeout": 60000,
"moduleFileExtensions": [
"json",
"ts",
"js"
],
"globalSetup": "./jest-setup.ts",
"globalTeardown": "./jest-teardown.ts",
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"reporters": [
"default",
"jest-junit"
],
"coverageThreshold": {
"global": {
"branches": 40,
"functions": 45,
"lines": 75,
"statements": 75
}
},
"modulePathIgnorePatterns": [
"dist/package.json",
"<rootDir>/package.json"
]
},
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": "test_results",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
},
"mikro-orm": {
"useTsNode": true,
"tsConfigPath": "tsconfig.json",
"configPaths": [
"dist/config/database/postgres/mikro-orm.config.js",
"src/config/database/postgres/mikro-orm.config.ts"
],
"entities": [
"dist/entities/*.entity.js"
],
"entitiesTs": [
"src/entities/*.entity.ts"
]
}
}
我的配置可能出了什么问题?如果跟apollo-server最新更新有关,什么时候可以解决?它是一个阻止程序,因为我的应用程序不可运行。
显然,GraphQLError.originalError
的类型在某个时候从 originalError?: Maybe<Error>
更改为 Error | undefined
。降级到 graphql 15.3.0 为我解决了这个问题。
降级到 graphql 对我也有用。此外,我尝试使用补丁包作为解决方法,只是为了不被阻止。
https://www.npmjs.com/package/patch-package
请注意,此问题已在 graphql.js 15.7.1 中修复:
版本
apollo 服务器错误:3.2.0
graphql: 15.6.1/ 15.7.0
nestjs-cli: 8.1.2
npm: 6.14.15
打字稿:4.4.4
错误:
node_modules/apollo-server-errors/dist/index.d.ts:10:5 - error TS2416: Property 'originalError' in type 'ApolloError' is not assignable to the same property in base type 'GraphQLError'.
Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
Type 'null' is not assignable to type 'Error | undefined'.
10 originalError: Error | null | undefined;
在我错误地清除 node_modules 并使用此 package.json 文件构建后,此问题开始出现:
{
"name": "priojet-backend",
"version": "0.13.6",
"description": "The PRIOjet backend providing APIs (GraphQL and REST) and managing the data stored in a Postgres database.",
"author": "Tobias Wolff, Shivam Pathak",
"private": true,
"license": "UNLICENSED",
"type": "commonjs",
"scripts": {
"prebuild": "rimraf dist",
"build": "NODE_ENV=production nest build -p tsconfig.build.json",
"build:docker": "NODE_ENV=docker nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "NODE_ENV=development nest start",
"start:dev": "NODE_ENV=development nest start --watch",
"start:dev:windows": "set NODE_ENV=development && nest start --watch",
"start:debug": "NODE_ENV=development npm-run-all create-api-info-files && NODE_ENV=development nest start --debug --watch",
"start:debug:docker": "NODE_ENV=docker nest start --debug --watch",
"start:prod": "NODE_ENV=production node dist/main",
"start:prod:pm2": "NODE_ENV=production pm2 start dist/main.js -i 0",
"start:devprod": "NODE_ENV=production DEVPROD=1 ts-node ./migrate.ts && node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --maxWorkers=50%",
"test:vscode-jest": "NODE_ENV=test TS_JEST=1 jest \"--detectOpenHandles\" \"--maxWorkers=50%\"",
"test:watch": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --watch --no-cache --silent=false",
"test:cov": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --coverage",
"test:cov:docker": "NODE_ENV=docker TS_JEST=1 jest --detectOpenHandles --coverage",
"test:debug": "NODE_ENV=test TS_JEST=1 node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "NODE_ENV=test TS_JEST=1 jest --config ./test/jest-e2e.json",
"test:changes": "NODE_ENV=test TS_JEST=1 jest -o",
"todo": "grep -R --exclude-dir=node_modules 'todo' .",
"TODO": "grep -R --exclude-dir=node_modules 'TODO' .",
"loose-types": "echo -e 'anys:\n\n'; grep -r any src; echo -e '\n\nfunctions\n\n'; grep -r function src; echo -e '\n\n';",
"db": "npx mikro-orm",
"db:help": "cat ./src/migrations/cli.ts",
"db:update": "ts-node ./migrate.ts",
"db:init": "npx mikro-orm schema:create -r",
"db:migration:create": "npx mikro-orm migration:create",
"db:migration:up": "npx mikro-orm migration:up # Migrate up to the latest version",
"db:migration:down": "npx mikro-orm migration:down # Migrate one step down",
"db:migration:list": "npx mikro-orm migration:list # List all executed migrations",
"db:migration:pending": "npx mikro-orm migration:pending # List all pending migrations",
"prebuild:prod": "rimraf dist # && tsc",
"create-api-info-files": "./create_api_info_files.sh"
},
"dependencies": {
"@apollo/federation": "^0.33.0",
"@apollo/gateway": "^0.33.0",
"@azure/identity": "^1.5.0",
"@azure/storage-blob": "^12.6.0",
"@casl/ability": "^5.3.1",
"@fingerprintjs/fingerprintjs": "^3.2.0",
"@googlemaps/google-maps-services-js": "^3.2.5",
"@mikro-orm/cli": "^4.5.9",
"@mikro-orm/core": "^4.5.9",
"@mikro-orm/knex": "^4.5.9",
"@mikro-orm/migrations": "^4.5.9",
"@mikro-orm/nestjs": "^4.3.0",
"@mikro-orm/postgresql": "^4.5.9",
"@mikro-orm/reflection": "^4.5.9",
"@nestjs/axios": "^0.0.2",
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.0.2",
"@nestjs/core": "^8.0.0",
"@nestjs/event-emitter": "^1.0.0",
"@nestjs/graphql": "^9.0.6",
"@nestjs/passport": "^8.0.0",
"@nestjs/platform-express": "^8.0.11",
"@sentry/node": "^6.13.2",
"@sentry/tracing": "^6.13.2",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.175",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"apollo-server-core": "^3.4.0",
"apollo-server-errors": "^3.2.0",
"apollo-server-express": "^3.4.0",
"apollo-server-types": "^3.3.0",
"axios": "^0.21.4",
"axios-retry": "^3.2.0",
"azure-storage": "^2.10.4",
"body-parser": "^1.19.0",
"bx24-api": "^1.4.1",
"check-peer-dependencies": "^4.0.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cluster": "^0.7.7",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"expo-device": "^3.1.1",
"express": "^4.17.1",
"form-data": "^4.0.0",
"graphql": "^15.6.1",
"graphql-type-json": "^0.3.2",
"http": "^0.0.1-security",
"http-proxy-middleware": "^2.0.1",
"nest-raven": "^8.0.0",
"passport": "^0.4.1",
"passport-azure-ad": "^4.3.1",
"passport-jwt": "^4.0.0",
"randomstring": "^1.2.1",
"reflect-metadata": "^0.1.13",
"request-ip": "^2.1.3",
"sharp": "^0.29.1",
"ts-morph": "^12.0.0",
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.9.0",
"tsutils": "^3.21.0",
"typescript": "^4.4.2",
"util": "^0.12.4",
"uuid": "^8.3.2",
"webpack": "^5.58.1"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.15",
"@nestjs/cli": "^8.1.2",
"@nestjs/schematics": "^8.0.3",
"@nestjs/testing": "^8.0.11",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.2",
"@types/multer": "^1.4.7",
"@types/node": "^16.10.2",
"@types/node-fetch": "^3.0.3",
"@types/request-ip": "0.0.37",
"@types/supertest": "^2.0.10",
"autoclean": "^1.0.2",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"faker": "^5.4.0",
"jest": "^27.2.4",
"jest-junit": "^13.0.0",
"npm-run-all": "^4.1.5",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3",
"ts-jest": "27.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.3.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.4.4"
},
"jest": {
"testTimeout": 60000,
"moduleFileExtensions": [
"json",
"ts",
"js"
],
"globalSetup": "./jest-setup.ts",
"globalTeardown": "./jest-teardown.ts",
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"reporters": [
"default",
"jest-junit"
],
"coverageThreshold": {
"global": {
"branches": 40,
"functions": 45,
"lines": 75,
"statements": 75
}
},
"modulePathIgnorePatterns": [
"dist/package.json",
"<rootDir>/package.json"
]
},
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": "test_results",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
},
"mikro-orm": {
"useTsNode": true,
"tsConfigPath": "tsconfig.json",
"configPaths": [
"dist/config/database/postgres/mikro-orm.config.js",
"src/config/database/postgres/mikro-orm.config.ts"
],
"entities": [
"dist/entities/*.entity.js"
],
"entitiesTs": [
"src/entities/*.entity.ts"
]
}
}
我的配置可能出了什么问题?如果跟apollo-server最新更新有关,什么时候可以解决?它是一个阻止程序,因为我的应用程序不可运行。
显然,GraphQLError.originalError
的类型在某个时候从 originalError?: Maybe<Error>
更改为 Error | undefined
。降级到 graphql 15.3.0 为我解决了这个问题。
降级到 graphql 对我也有用。此外,我尝试使用补丁包作为解决方法,只是为了不被阻止。 https://www.npmjs.com/package/patch-package
请注意,此问题已在 graphql.js 15.7.1 中修复: