npm - Conflicto de Apollo y GraphQL con TypeScript TS2416 en NestJS
Estoy con este proyecto heredado en Node 12 y por alguna razón los graphql están teniendo un conflicto con apollo-server-express sobre los tipos de TypeScript. El comando que está devolviendo el error es el que está en el script de compilación npm run build.
Estoy usando el framework NestJS y he seguido el tutorial de instalación de la documentación oficial.
Estoy suponiendo que el problema es un conflicto de versiones, pero no puedo manejar solucionarlo. Dado que es un proyecto heredado en el que acabo de empezar a trabajar, aún no tengo los detalles sobre la implementación.
Aquí está el error:
node_modules/@apollo/gateway/dist/index.d.ts:61:5 - error TS2416: Property 'load' in type 'ApolloGateway' is not assignable to the same property in base type 'GraphQLService'.
Type '(options?: { apollo?: ApolloConfigFromAS2Or3; engine?: GraphQLServiceEngineConfig; }) => Promise<{ schema: GraphQLSchema; executor: <TContext>(requestContext: GraphQLRequestContextExecutionDidStart<...>) => Promise<...>; }>' is not assignable to type '(options: { apollo?: ApolloConfig; engine?: GraphQLServiceEngineConfig; }) => Promise<GraphQLServiceConfig>'.
Type 'Promise<{ schema: GraphQLSchema; executor: <TContext>(requestContext: GraphQLRequestContextExecutionDidStart<TContext>) => Promise<...>; }>' is not assignable to type 'Promise<GraphQLServiceConfig>'.
Type '{ schema: GraphQLSchema; executor: <TContext>(requestContext: GraphQLRequestContextExecutionDidStart<TContext>) => Promise<GraphQLExecutionResult>; }' is not assignable to type 'GraphQLServiceConfig'.
Types of property 'executor' are incompatible.
Type '<TContext>(requestContext: GraphQLRequestContextExecutionDidStart<TContext>) => Promise<GraphQLExecutionResult>' is not assignable to type 'GraphQLExecutor<Record<string, any>>'.
Types of parameters 'requestContext' and 'requestContext' are incompatible.
Type 'import("/home/trolliama/Documents/OSTEC/GitLab/BeSafe/api-register/node_modules/graphql-extensions/node_modules/apollo-server-types/dist/index").GraphQLRequestContextExecutionDidStart<Record<string, any>>' is not assignable to type 'import("/home/trolliama/Documents/OSTEC/GitLab/BeSafe/api-register/node_modules/apollo-server-types/dist/index").GraphQLRequestContextExecutionDidStart<Record<string, any>>'.
Type 'GraphQLRequestContextExecutionDidStart<Record<string, any>>' is not assignable to type 'GraphQLRequestContext<Record<string, any>>'.
The types of 'request.http.headers' are incompatible between these types.
Type 'import("/home/trolliama/Documents/OSTEC/GitLab/BeSafe/api-register/node_modules/apollo-server-core/node_modules/apollo-server-env/dist/fetch").Headers' is not assignable to type 'import("/home/trolliama/Documents/OSTEC/GitLab/BeSafe/api-register/node_modules/apollo-server-types/node_modules/apollo-server-env/dist/fetch").Headers'.
Este es mi package.json:
{
"name": "api-register",
"version": "0.9.4",
"main": "dist/server.js",
"repository": "https://gitlab.ostec.xyz/besafe/api-register.git",
"license": "MIT",
"private": true,
"scripts": {
"build": "tsc -p tsconfig.build.json && tscpaths -p tsconfig.build.json -s ./ -o dist/",
"format": "prettier --write \"src/**/*.ts\"",
"prettier": "prettier --check \"src/**/*.ts\"",
"migration:generate": "ts-node -r tsconfig-paths/register node_modules/typeorm/cli.js migration:generate -f ormconfig -d src/migrations -n",
"migration:revert": "ts-node -r tsconfig-paths/register node_modules/typeorm/cli.js migration:revert -f ormconfig -t",
"migration:create": "ts-node -r tsconfig-paths/register node_modules/typeorm/cli.js migration:create -f ormconfig -d src/migrations -n",
"webpack": "webpack --config webpack.config.js --progress",
"schema:drop": "ts-node -r tsconfig-paths/register node_modules/typeorm/cli.js schema:drop -f ormconfig",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint --fix . --ext .ts",
"dev": "nodemon --config nodemon.json",
"prod": "node dist/src/main.js"
},
"dependencies": {
"@nestjs/common": "^7.2.0",
"@nestjs/core": "^7.2.0",
"@nestjs/graphql": "^7.9.8",
"@nestjs/jwt": "^7.2.0",
"@nestjs/microservices": "^7.3.2",
"@nestjs/mongoose": "^7.2.2",
"@nestjs/passport": "^7.1.5",
"@nestjs/platform-express": "^7.2.0",
"@nestjs/typeorm": "^7.1.0",
"apollo-server-express": "^2.20.0",
"bcryptjs": "~2.4.3",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"compression": "~1.7.4",
"date-fns": "^2.17.0",
"dotenv": "~8.1.0",
"express": "~4.17.1",
"graphql": "^15.5.0",
"graphql-tools": "^7.0.2",
"graphql-type-json": "^0.3.2",
"helmet": "~3.22.0",
"jsonwebtoken": "~8.5.1",
"kafkajs": "^1.15.0",
"lodash": "^4.17.20",
"mongoose": "^5.11.13",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"pg": "^8.2.1",
"request-context": "~2.0.0",
"rxjs": "^6.5.5",
"typeorm": "^0.2.45",
"typeorm-transactional-cls-hooked": "^0.1.12",
"typescript": "^3.9.5",
"uuid": "^8.1.0",
"winston": "^3.3.3",
"winston-mail": "^2.0.0"
},
"devDependencies": {
"@types/bcrypt": "^3.0.0",
"@types/compression": "^1.7.0",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.6",
"@types/graphql-type-json": "^0.3.2",
"@types/helmet": "^0.0.47",
"@types/jsonwebtoken": "^8.5.0",
"@types/lodash": "^4.14.152",
"@types/node": "^14.14.22",
"@types/passport-jwt": "^3.0.5",
"@types/uuid": "^8.0.0",
"@types/winston": "^2.4.4",
"@types/winston-mail": "^1.5.1",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"clean-webpack-plugin": "^3.0.0",
"cross-env": "^7.0.2",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-import-helpers": "^1.0.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-simple-import-sort": "^7.0.0",
"nodemon": "^1.19.3",
"prettier": "^2.0.5",
"ts-loader": "^7.0.4",
"ts-node": "^8.10.2",
"tsconfig-paths": "^3.9.0",
"tscpaths": "^0.0.9",
"webpack": "^4.41.1",
"webpack-cli": "^3.3.9",
"webpack-node-externals": "^1.7.2"
}
}