Apollo and GraphQL typescript conflict TS2416 in NestJS

Viewed 61

I am with this legacy project in node 12 and for some reason the graphql are getting a conflict with apollo-server-express about the typescript types. The command that is returning the error is the one in build script npm run build.

I am using the NestJS framework and I've followed the tutorial for installation from the official documentation.

I am assuming that the problem is a version conflict but I can't handle to fix it. Since it's a legacy project that I have just started to work on I don't have the details about the implementation yet.

Here is the 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'.

This is my 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"
  }
}
0 Answers
Related